Skip to content

Commit 3330d24

Browse files
authored
Merge pull request #474 from vacantron/prebuilt
Automate prebuilt executable updates via GitHub Actions
2 parents 654a2ef + 262513e commit 3330d24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+288
-554
lines changed

.ci/gdbstub-test.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
set -e -u -o pipefail
44

5-
export PATH=`pwd`/toolchain/riscv/bin:$PATH
5+
export PATH=`pwd`/toolchain/bin:$PATH
66

77
GDB=
8-
prefixes=("${CROSS_COMPILE}" "riscv32-unknown-elf" "riscv-none-elf")
8+
prefixes=("${CROSS_COMPILE}" "riscv32-unknown-elf-" "riscv-none-elf-")
99
for prefix in "${prefixes[@]}"; do
10-
utility=${prefix}-gdb
10+
utility=${prefix}gdb
1111
set +e # temporarily disable exit on error
1212
command -v "${utility}" &> /dev/null
1313
if [[ $? == 0 ]]; then
@@ -21,7 +21,7 @@ if [ -z ${GDB} ]; then
2121
exit 1
2222
fi
2323

24-
build/rv32emu -g build/puzzle.elf &
24+
build/rv32emu -g build/riscv32/puzzle &
2525
PID=$!
2626

2727
# Before starting GDB, we should ensure rv32emu is still running.
@@ -31,9 +31,9 @@ fi
3131

3232
OPTS=
3333
tmpfile=/tmp/rv32emu-gdbstub.$PID
34-
breakpoints=(0x10700 0x10800 0x10900)
34+
breakpoints=(0x10500 0x10600 0x10700)
3535
bkpt_count=${#breakpoints[@]}
36-
OPTS+="-ex 'file build/puzzle.elf' "
36+
OPTS+="-ex 'file build/riscv32/puzzle' "
3737
OPTS+="-ex 'target remote :1234' "
3838
for t in ${breakpoints[@]}; do
3939
OPTS+="-ex 'break *$t' "

.ci/riscv-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pip3 install git+https://github.com/riscv/riscof.git@d38859f85fe407bcacddd2efcd3
77

88
set -x
99

10-
export PATH=`pwd`/toolchain/riscv/bin:$PATH
10+
export PATH=`pwd`/toolchain/bin:$PATH
1111

1212
make clean
1313
make arch-test RISCV_DEVICE=IMAFCZicsrZifencei || exit 1

.ci/riscv-toolchain-install.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ check_platform
88

99
mkdir -p toolchain
1010

11-
# GNU Toolchain for RISC-V
12-
GCC_VER=2024.04.12
13-
TOOLCHAIN_REPO=https://github.com/riscv-collab/riscv-gnu-toolchain/releases
11+
if [[ "$#" == "0" ]] || [[ "$1" != "riscv-collab" ]]; then
12+
GCC_VER=14.2.0-1
13+
TOOLCHAIN_REPO=https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack
14+
TOOLCHAIN_URL=${TOOLCHAIN_REPO}/releases/download/v${GCC_VER}/xpack-riscv-none-elf-gcc-${GCC_VER}-linux-x64.tar.gz
15+
else
16+
UBUNTU_VER=`lsb_release -r | cut -f2`
17+
GCC_VER=2024.04.12
18+
TOOLCHAIN_REPO=https://github.com/riscv-collab/riscv-gnu-toolchain
19+
TOOLCHAIN_URL=${TOOLCHAIN_REPO}/releases/download/${GCC_VER}/riscv32-elf-ubuntu-${UBUNTU_VER}-gcc-nightly-${GCC_VER}-nightly.tar.gz
20+
fi
1421

15-
wget -q \
16-
${TOOLCHAIN_REPO}/download/${GCC_VER}/riscv32-elf-ubuntu-22.04-gcc-nightly-${GCC_VER}-nightly.tar.gz -O- \
17-
| tar -C toolchain -xz
22+
wget -q ${TOOLCHAIN_URL} -O- | tar -C toolchain --strip-components=1 -xz

.github/workflows/build-artifact.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Build artifact
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
jobs:
10+
detect-file-change:
11+
runs-on: ubuntu-22.04
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
with:
16+
submodules: 'true'
17+
- name: Test file change
18+
id: test-file-change
19+
uses: tj-actions/changed-files@v45
20+
with:
21+
fetch_additional_submodule_history: 'true'
22+
files: |
23+
tests/ansibench/*
24+
tests/rv8-bench/*
25+
tests/*.c
26+
- name: Set alias
27+
id: has_changed_files
28+
run: |
29+
if [[ ${{ steps.test-file-change.outputs.any_modified }} == true ]]; then
30+
echo "has_changed_files=true" >> $GITHUB_OUTPUT
31+
else
32+
echo "has_changed_files=false" >> $GITHUB_OUTPUT
33+
fi
34+
outputs:
35+
has_changed_files: ${{ steps.has_changed_files.outputs.has_changed_files }}
36+
37+
build-artifact:
38+
needs: [detect-file-change]
39+
if: ${{ needs.detect-file-change.outputs.has_changed_files == 'true' || github.event_name == 'workflow_dispatch' }}
40+
runs-on: ubuntu-22.04
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v4
44+
with:
45+
submodules: 'true'
46+
- name: Install dependencies
47+
run: |
48+
sudo apt-get update -q -y
49+
sudo apt-get upgrade -q -y
50+
sudo apt-get install -q -y gcc-multilib g++-multilib
51+
sudo apt-get install -q -y opam build-essential libgmp-dev z3 pkg-config zlib1g-dev
52+
.ci/riscv-toolchain-install.sh
53+
echo "$PWD/toolchain/bin" >> $GITHUB_PATH
54+
- name: Build binaries
55+
run: |
56+
make artifact ENABLE_PREBUILT=0
57+
mkdir -p /tmp/rv32emu-prebuilt
58+
mv build/linux-x86-softfp build/riscv32 /tmp/rv32emu-prebuilt
59+
- name: Build Sail model
60+
run: |
61+
cd /tmp
62+
opam init -y --disable-sandboxing
63+
opam switch create ocaml-base-compiler.4.06.1
64+
opam install sail -y
65+
eval $(opam config env)
66+
git clone https://github.com/riscv/sail-riscv.git
67+
cd sail-riscv
68+
git checkout 9547a30bf84572c458476591b569a95f5232c1c7
69+
ARCH=RV32 make -j
70+
mkdir -p /tmp/rv32emu-prebuilt/sail_cSim
71+
mv c_emulator/riscv_sim_RV32 /tmp/rv32emu-prebuilt/sail_cSim
72+
- name: Create tarball
73+
run: |
74+
cd /tmp
75+
tar -zcvf rv32emu-prebuilt.tar.gz rv32emu-prebuilt
76+
- name: Create GitHub Release
77+
env:
78+
GH_TOKEN: ${{ secrets.RV32EMU_PREBUILT_TOKEN }}
79+
run: |
80+
RELEASE_TAG=$(date +'%Y.%m.%d')
81+
cd /tmp
82+
gh release create $RELEASE_TAG \
83+
--repo sysprog21/rv32emu-prebuilt \
84+
--title "$RELEASE_TAG""-nightly"
85+
gh release upload $RELEASE_TAG \
86+
rv32emu-prebuilt.tar.gz \
87+
--repo sysprog21/rv32emu-prebuilt

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ build/softfloat
1616
build/cache/
1717
build/map/
1818
build/path/
19+
build/linux-x86-softfp/
20+
build/riscv32/
21+
build/sail_cSim/
22+
*.a
1923
*.o
2024
*.o.d
2125
tests/**/*.elf
2226
tests/arch-test-target/config.ini
27+
tests/arch-test-target/sail_cSim/riscv_sim_RV32
2328
__pycache__/
2429
src/rv32_jit.c

.gitmodules

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@
1111
url = https://github.com/sysprog21/berkeley-softfloat-3
1212
branch = rv32emu
1313
shallow = true
14+
[submodule "tests/ansibench"]
15+
path = tests/ansibench
16+
url = https://github.com/sysprog21/ansibench
17+
shallow = true
18+
[submodule "tests/rv8-bench"]
19+
path = tests/rv8-bench
20+
url = https://github.com/sysprog21/rv8-bench
21+
shallow = true
22+
[submodule "src/ieeelib"]
23+
path = src/ieeelib
24+
url = https://github.com/sysprog21/ieeelib
25+
shallow = true

Makefile

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ $(OUT)/emulate.o: CFLAGS += -foptimize-sibling-calls -fomit-frame-pointer -fno-s
182182
.DEFAULT_GOAL := all
183183

184184
include mk/external.mk
185-
185+
include mk/artifact.mk
186186
include mk/wasm.mk
187187

188188
all: config $(BIN)
@@ -229,13 +229,13 @@ tool: $(TOOLS_BIN)
229229
include mk/riscv-arch-test.mk
230230
include mk/tests.mk
231231

232-
CHECK_ELF_FILES := \
233-
hello \
234-
puzzle \
235-
fcalc
232+
# the prebuilt executables are built for "rv32im"
233+
CHECK_ELF_FILES :=
236234

237235
ifeq ($(call has, EXT_M), 1)
238236
CHECK_ELF_FILES += \
237+
puzzle \
238+
fcalc \
239239
pi
240240
endif
241241

@@ -244,10 +244,19 @@ EXPECTED_puzzle = success in 2005 trials
244244
EXPECTED_fcalc = Performed 12 tests, 0 failures, 100% success rate.
245245
EXPECTED_pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086
246246

247-
check: $(BIN)
247+
check-hello: $(BIN)
248+
$(Q)$(PRINTF) "Running hello.elf ..."; \
249+
if [ "$(shell $(BIN) $(OUT)/hello.elf | uniq)" = "$(strip $(EXPECTED_hello)) inferior exit code 0" ]; then \
250+
$(call notice, [OK]); \
251+
else \
252+
$(PRINTF) "Failed.\n"; \
253+
exit 1; \
254+
fi;
255+
256+
check: $(BIN) check-hello artifact
248257
$(Q)$(foreach e,$(CHECK_ELF_FILES),\
249-
$(PRINTF) "Running $(e).elf ... "; \
250-
if [ "$(shell $(BIN) $(OUT)/$(e).elf | uniq)" = "$(strip $(EXPECTED_$(e))) inferior exit code 0" ]; then \
258+
$(PRINTF) "Running $(e) ... "; \
259+
if [ "$(shell $(BIN) $(OUT)/riscv32/$(e) | uniq)" = "$(strip $(EXPECTED_$(e))) inferior exit code 0" ]; then \
251260
$(call notice, [OK]); \
252261
else \
253262
$(PRINTF) "Failed.\n"; \
@@ -256,9 +265,9 @@ check: $(BIN)
256265
)
257266

258267
EXPECTED_aes_sha1 = 1242a6757c8aef23e50b5264f5941a2f4b4a347e -
259-
misalign: $(BIN)
260-
$(Q)$(PRINTF) "Running aes.elf ... ";
261-
$(Q)if [ "$(shell $(BIN) -m $(OUT)/aes.elf | $(SHA1SUM))" = "$(EXPECTED_aes_sha1)" ]; then \
268+
misalign: $(BIN) artifact
269+
$(Q)$(PRINTF) "Running uaes ... ";
270+
$(Q)if [ "$(shell $(BIN) -m $(OUT)/riscv32/uaes | $(SHA1SUM))" = "$(EXPECTED_aes_sha1)" ]; then \
262271
$(call notice, [OK]); \
263272
else \
264273
$(PRINTF) "Failed.\n"; \

README.md

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -327,46 +327,8 @@ Use of this source code is governed by a MIT license that can be found in the [L
327327

328328
## External sources
329329

330-
In `rv32emu` repository, there are some prebuilt ELF files for testing purpose.
331-
* `aes.elf` : See [tests/aes.c](tests/aes.c)
332-
* `captcha.elf` : See [tests/captcha.c](tests/captcha.c)
333-
* `cc.elf` : See [tests/cc](tests/cc)
334-
* `chacha20.elf` : See [tests/chacha20](tests/chacha20)
335-
* `coremark.elf` : See [eembc/coremark](https://github.com/eembc/coremark) [RV32M]
336-
* `dhrystone.elf` : See [rv8-bench](https://github.com/michaeljclark/rv8-bench)
337-
* `donut.elf` : See [donut.c](tests/donut.c)
338-
* `doom.elf` : See [sysprog21/doom_riscv](https://github.com/sysprog21/doom_riscv) [RV32M]
339-
* `fcalc.elf` : See [fcalc.c](tests/fcalc.c)
340-
* `hamilton.elf` : See [hamilton.c](tests/hamilton.c)
341-
* `ieee754.elf` : See [tests/ieee754.c](tests/ieee754.c) [RV32F]
342-
* `jit-bf.elf` : See [ezaki-k/xkon_beta](https://github.com/ezaki-k/xkon_beta)
343-
* `lena.elf`: See [tests/lena.c](tests/lena.c)
344-
* `line.elf` : See [tests/line.c](tests/line.c) [RV32M]
345-
* `maj2random.elf` : See [tests/maj2random.c](tests/maj2random.c) [RV32F]
346-
* `mandelbrot.elf` : See [tests/mandelbrot.c](tests/mandelbrot.c)
347-
* `nqueens.elf` : See [tests/nqueens.c](tests/nqueens.c)
348-
* `nyancat.elf` : See [tests/nyancat.c](tests/nyancat.c)
349-
* `pi.elf` : See [tests/pi.c](tests/pi.c) [RV32M]
350-
* `qrcode.elf` : See [tests/qrcode.c](tests/qrcode.c)
351-
* `quake.elf` : See [sysprog21/quake-embedded](https://github.com/sysprog21/quake-embedded) [RV32F]
352-
* `readelf.elf` : See [tests/readelf](tests/readelf)
353-
* `richards.elf` : See [tests/richards.c](tests/richards.c)
354-
* `rvsim.elf` : See [tests/rvsim.c](tests/rvsim.c)
355-
* `scimark2.elf` : See [tests/scimark2](tests/scimark2) [RV32MF]
356-
* `smolnes.elf` : See [tests/smolnes](tests/smolnes.c) [RV32M]
357-
* `spirograph.elf` : See [tests/spirograph.c](tests/spirograph.c)
358-
* `stream.elf` : See [tests/stream](tests/stream.c) [RV32MF]
359-
* `qsort.elf` : See [rv8-bench](https://github.com/michaeljclark/rv8-bench)
360-
* `miniz.elf` : See [rv8-bench](https://github.com/michaeljclark/rv8-bench)
361-
* `primes.elf` : See [rv8-bench](https://github.com/michaeljclark/rv8-bench)
362-
* `sha512.elf` : See [rv8-bench](https://github.com/michaeljclark/rv8-bench)
363-
* `numeric_sort.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
364-
* `FP_emulation.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
365-
* `bitfield.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
366-
* `idea.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
367-
* `assignment.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
368-
* `string_sort.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
369-
* `huffman.elf` : See [nbench](https://github.com/nfinit/ansibench/tree/master/nbench)
330+
See [docs/prebuilt.md](docs/prebuilt.md).
331+
370332
## Reference
371333

372334
* [Writing a simple RISC-V emulator in plain C](https://fmash16.github.io/content/posts/riscv-emulator-in-c.html)

build/FP_emulation.elf

-494 KB
Binary file not shown.

build/aes.elf

-147 KB
Binary file not shown.

0 commit comments

Comments
 (0)