Skip to content

Commit 0fd7b4e

Browse files
committed
Update CI and toolchain installation
1 parent 2786803 commit 0fd7b4e

File tree

9 files changed

+103
-93
lines changed

9 files changed

+103
-93
lines changed

.ci/gdbstub-test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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=
88
prefixes=("${CROSS_COMPILE}" "riscv32-unknown-elf" "riscv-none-elf")
@@ -21,7 +21,7 @@ if [ -z ${GDB} ]; then
2121
exit 1
2222
fi
2323

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

2727
# Before starting GDB, we should ensure rv32emu is still running.
@@ -33,7 +33,7 @@ OPTS=
3333
tmpfile=/tmp/rv32emu-gdbstub.$PID
3434
breakpoints=(0x10500 0x10600 0x10700)
3535
bkpt_count=${#breakpoints[@]}
36-
OPTS+="-ex 'file build/bin/riscv32/puzzle' "
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: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Build artifact
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
jobs:
10+
detect-files-changed:
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 files changed
18+
id: files-changed
19+
uses: tj-actions/changed-files@v44
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_files_changed
28+
run: |
29+
if [[ ${{ steps.files-changed.outputs.any_changed }} == true ]]; then
30+
echo "has_files_changed=true" >> $GITHUB_OUTPUT
31+
else
32+
echo "has_files_changed=false" >> $GITHUB_OUTPUT
33+
fi
34+
outputs:
35+
has_files_changed: ${{ steps.has_files_changed.outputs.has_files_changed }}
36+
37+
build-artifact:
38+
needs: [detect-files-changed]
39+
if: ${{ needs.detect-files-changed.outputs.has_files_changed == '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+
.ci/riscv-toolchain-install.sh
52+
echo "$PWD/toolchain/bin" >> $GITHUB_PATH
53+
- name: Build binaries
54+
run: |
55+
make build-artifact USE_PREBUILT=0
56+
- name: Create tarball
57+
run: |
58+
tar -C build -zcf rv32emu-prebuilt.tar.gz linux-x64 riscv32
59+
- name: Create GitHub Release
60+
env:
61+
GH_TOKEN: ${{ secrets.RV32EMU_PREBUILT_TOKEN }}
62+
run: |
63+
RELEASE_TAG=$(date +'%Y.%m.%d')
64+
gh release create $RELEASE_TAG \
65+
--repo sysprog21/rv32emu-prebuilt \
66+
--title "$RELEASE_TAG""-nightly"
67+
gh release upload $RELEASE_TAG \
68+
rv32emu-prebuilt.tar.gz \
69+
--repo sysprog21/rv32emu-prebuilt

.github/workflows/build-testbenches.yml

Lines changed: 0 additions & 61 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ build/softfloat
1616
build/cache/
1717
build/map/
1818
build/path/
19-
build/bin/
19+
build/linux-x64/
20+
build/riscv32/
2021
*.o
2122
*.o.d
2223
tests/**/*.elf

Makefile

Lines changed: 5 additions & 5 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-
include mk/benchmark.mk
185+
include mk/artifact.mk
186186
include mk/wasm.mk
187187

188188
all: config $(BIN)
@@ -243,10 +243,10 @@ EXPECTED_puzzle = success in 2005 trials
243243
EXPECTED_fcalc = Performed 12 tests, 0 failures, 100% success rate.
244244
EXPECTED_pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086
245245

246-
check: $(BIN) build-testbenches
246+
check: $(BIN) build-artifact
247247
$(Q)$(foreach e,$(CHECK_ELF_FILES),\
248248
$(PRINTF) "Running $(e) ... "; \
249-
if [ "$(shell $(BIN) $(OUT)/bin/riscv32/$(e) | uniq)" = "$(strip $(EXPECTED_$(e))) inferior exit code 0" ]; then \
249+
if [ "$(shell $(BIN) $(OUT)/riscv32/$(e) | uniq)" = "$(strip $(EXPECTED_$(e))) inferior exit code 0" ]; then \
250250
$(call notice, [OK]); \
251251
else \
252252
$(PRINTF) "Failed.\n"; \
@@ -255,9 +255,9 @@ check: $(BIN) build-testbenches
255255
)
256256

257257
EXPECTED_aes_sha1 = f9924635666d3d58d5b60c0bde8b986a2a99effb -
258-
misalign: $(BIN) build-testbenches
258+
misalign: $(BIN) build-artifact
259259
$(Q)$(PRINTF) "Running aes ... ";
260-
$(Q)if [ "$(shell $(BIN) -m $(OUT)/bin/riscv32/aes | $(SHA1SUM))" = "$(EXPECTED_aes_sha1)" ]; then \
260+
$(Q)if [ "$(shell $(BIN) -m $(OUT)/riscv32/aes | $(SHA1SUM))" = "$(EXPECTED_aes_sha1)" ]; then \
261261
$(call notice, [OK]); \
262262
else \
263263
$(PRINTF) "Failed.\n"; \

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,18 +333,18 @@ The prebuilt executables are built from GNU/GCC v9 and [xPack GCC v14.2.0-1](htt
333333
To fetch the prebuilt executables, run the following command:
334334

335335
```shell
336-
$ make build-testbenches
336+
$ make build-artifact
337337
```
338338

339339
Or, to compile the executables from the source, run:
340340

341341
```shell
342-
$ make build-testbenches USE_PREBUILT=0 CROSS_CC=<riscv-cross-compiler>
342+
$ make build-artifact USE_PREBUILT=0
343343
```
344344

345345
Notice that the RISC-V cross-compiler is required to build the binary.
346346

347-
In default, `rv32emu` will download the tarball from GitHub and extract the executables into `build/bin/`.
347+
In default, `rv32emu` will download the tarball from GitHub and extract the executables into `build/`.
348348

349349
There are still some prebuilt ELF files for testing purpose under `build/`.
350350
* `cc.elf` : See [tests/cc](tests/cc)

mk/benchmark.mk renamed to mk/artifact.mk

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
USE_PREBUILT ?= 1
22

33
CC ?= gcc
4-
CROSS_CC ?= riscv-none-elf-gcc
4+
CROSS_COMPILE ?= riscv-none-elf-
55

6-
BINDIR := $(abspath $(OUT))/bin
6+
BINDIR := $(abspath $(OUT))
77

88
TEST_SUITES += \
99
ansibench \
@@ -34,27 +34,23 @@ TESTBENCHES += \
3434
$(ticks)
3535

3636
ifeq ($(USE_PREBUILT),1)
37-
LATEST_RELEASE := $(shell wget -qO - https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases/latest | grep -Po '(?<="tag_name": ").+(?=",)')
37+
LATEST_RELEASE := $(shell wget -q https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases/latest -O- | grep -Po '(?<="tag_name": ").+(?=",)')
3838
endif
3939

40-
.PHONY: build-testbenches benchmark
40+
.PHONY: build-artifact
4141

42-
# TODO: generate results automatically
43-
benchmark: build-testbenches
44-
45-
build-testbenches:
42+
build-artifact:
4643
ifeq ($(USE_PREBUILT),1)
4744
@echo "Fetching prebuilt executables in \"rv32emu-prebuilt\"..."
48-
@wget -O - https://github.com/sysprog21/rv32emu-prebuilt/releases/download/$(LATEST_RELEASE)/rv32emu-prebuilt.tar.gz | tar zx -C build
45+
@wget -q https://github.com/sysprog21/rv32emu-prebuilt/releases/download/$(LATEST_RELEASE)/rv32emu-prebuilt.tar.gz -O- | tar -C build -xz
4946
else
5047
@$(foreach tb,$(TEST_SUITES), \
5148
git submodule update --init ./tests/$(tb) &&) true
5249
@$(foreach tb,$(TEST_SUITES), \
53-
CC=$(CC) CROSS_CC=$(CROSS_CC) BINDIR=$(BINDIR) \
54-
$(MAKE) -C ./tests/$(tb) all &&) true
50+
$(MAKE) -C ./tests/$(tb) all BINDIR=$(BINDIR) &&) true
5551
@$(foreach tb,$(TESTBENCHES), \
56-
$(CC) -m32 -O2 -Wno-unused-result -o $(BINDIR)/x86_64/$(tb) tests/$(tb).c -lm &&) true
52+
$(CC) -m32 -O2 -Wno-unused-result -o $(BINDIR)/linux-x64/$(tb) tests/$(tb).c -lm &&) true
5753
@$(foreach tb,$(TESTBENCHES), \
58-
$(CROSS_CC) -march=rv32im -mabi=ilp32 -O2 -Wno-unused-result -Wno-implicit-function-declaration \
54+
$(CROSS_COMPILE)gcc -march=rv32im -mabi=ilp32 -O2 -Wno-unused-result -Wno-implicit-function-declaration \
5955
-o $(BINDIR)/riscv32/$(tb) tests/$(tb).c -lm -lsemihost &&) true
6056
endif

0 commit comments

Comments
 (0)