Skip to content

Commit 7b9b7f8

Browse files
committed
Add LLVM toolchain support to CI and build system
1 parent fe8a24b commit 7b9b7f8

File tree

3 files changed

+95
-22
lines changed

3 files changed

+95
-22
lines changed

.ci/run-qemu-tests.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/bin/bash
22
set -e
3-
export CROSS_COMPILE=${CROSS_COMPILE:-riscv32-unknown-elf-}
43

54
# Check if at least one app is provided
65
if [ $# -eq 0 ]; then
@@ -11,19 +10,21 @@ fi
1110

1211
APPS="$@"
1312
TIMEOUT=10
13+
TOOLCHAIN_TYPE=${TOOLCHAIN_TYPE:-gnu}
1414

1515
echo "[+] Will run apps: $APPS"
16+
echo "[+] Using toolchain: $TOOLCHAIN_TYPE"
1617
echo ""
1718

1819
# Loop through each app
1920
for app in $APPS; do
20-
echo "=== Running $app ==="
21+
echo "=== Running $app ($TOOLCHAIN_TYPE) ==="
2122

2223
# Build the app
23-
echo "[+] Building $app..."
24+
echo "[+] Building $app with $TOOLCHAIN_TYPE toolchain..."
2425
make clean >/dev/null 2>&1
25-
if ! make "$app" >/dev/null 2>&1; then
26-
echo "[!] Failed to build $app"
26+
if ! make "$app" TOOLCHAIN_TYPE="$TOOLCHAIN_TYPE" >/dev/null 2>&1; then
27+
echo "[!] Failed to build $app with $TOOLCHAIN_TYPE"
2728
echo ""
2829
continue
2930
fi
@@ -46,4 +47,4 @@ for app in $APPS; do
4647
echo ""
4748
done
4849

49-
echo "[+] All apps tested"
50+
echo "[+] All apps tested with $TOOLCHAIN_TYPE toolchain"

.ci/setup-toolchain.sh

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,56 @@
11
#!/bin/bash
22
set -e
33

4-
URL="https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2025.06.13/riscv32-elf-ubuntu-22.04-gcc-nightly-2025.06.13-nightly.tar.xz"
4+
# Default to GNU if no toolchain specified
5+
TOOLCHAIN_TYPE=${1:-gnu}
56

6-
echo "[+] Downloading RISC-V GNU toolchain..."
7-
wget "$URL"
8-
tar -xf "$(basename "$URL")"
7+
setup_gnu_toolchain() {
8+
echo "[+] Setting up GNU RISC-V toolchain..."
99

10-
echo "[+] Exporting toolchain path..."
11-
echo "$PWD/riscv/bin" >> "$GITHUB_PATH"
10+
local URL="https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2025.07.03/riscv32-elf-ubuntu-24.04-gcc-nightly-2025.06.13-nightly.tar.xz"
11+
12+
echo "[+] Downloading RISC-V GNU toolchain..."
13+
wget -q "$URL"
14+
tar -xf "$(basename "$URL")"
15+
16+
echo "[+] Exporting GNU toolchain path..."
17+
echo "$PWD/riscv/bin" >> "$GITHUB_PATH"
18+
19+
# Set cross-compile prefix for GNU
20+
echo "CROSS_COMPILE=riscv32-unknown-elf-" >> "$GITHUB_ENV"
21+
echo "TOOLCHAIN_TYPE=gnu" >> "$GITHUB_ENV"
22+
}
23+
24+
setup_llvm_toolchain() {
25+
echo "[+] Setting up LLVM RISC-V toolchain..."
26+
27+
# upstream URL for LLVM toolchain
28+
local URL="https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2025.07.03/riscv32-elf-ubuntu-24.04-llvm-nightly-2025.06.13-nightly.tar.xz"
29+
30+
echo "[+] Downloading RISC-V LLVM toolchain..."
31+
wget -q "$URL"
32+
tar -xf "$(basename "$URL")"
33+
34+
echo "[+] Exporting LLVM toolchain path..."
35+
echo "$PWD/riscv/bin" >> "$GITHUB_PATH"
36+
37+
# Set cross-compile prefix for LLVM
38+
echo "CROSS_COMPILE=llvm-" >> "$GITHUB_ENV"
39+
echo "TOOLCHAIN_TYPE=llvm" >> "$GITHUB_ENV"
40+
}
41+
42+
case "$TOOLCHAIN_TYPE" in
43+
"gnu")
44+
setup_gnu_toolchain
45+
;;
46+
"llvm")
47+
setup_llvm_toolchain
48+
;;
49+
*)
50+
echo "Error: Unknown toolchain type '$TOOLCHAIN_TYPE'"
51+
echo "Usage: $0 [gnu|llvm]"
52+
exit 1
53+
;;
54+
esac
55+
56+
echo "[+] Toolchain setup complete: $TOOLCHAIN_TYPE"

.github/workflows/ci.yml

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,43 @@ on:
77
branches: [main, ci]
88

99
jobs:
10-
basic-tests:
10+
matrix-tests:
1111
runs-on: ubuntu-24.04
12-
name: Basic Tests
12+
name: Test on ${{ matrix.toolchain }} toolchain
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
toolchain: [gnu, llvm]
1318

1419
steps:
1520
- name: Checkout
1621
uses: actions/checkout@v4
1722

18-
- name: Install dependencies
23+
- name: Install base dependencies
1924
run: |
2025
sudo apt-get update
2126
sudo apt-get install -y build-essential qemu-system-riscv32 wget
2227
23-
- name: Setup RISC-V Toolchain
24-
run: .ci/setup-toolchain.sh
28+
- name: Setup ${{ matrix.toolchain }} toolchain
29+
run: .ci/setup-toolchain.sh ${{ matrix.toolchain }}
2530

2631
- name: Verify toolchain installation
2732
run: |
28-
riscv32-unknown-elf-gcc --version
33+
if [ "${{ matrix.toolchain }}" = "gnu" ]; then
34+
riscv32-unknown-elf-gcc --version
35+
else
36+
riscv32-unknown-elf-clang --version
37+
riscv32-unknown-elf-llvm-objdump --version
38+
fi
2939
qemu-system-riscv32 --version
30-
env:
31-
CROSS_COMPILE: riscv32-unknown-elf-
3240
3341
- name: Build Kernel
3442
run: |
3543
make clean
3644
make
3745
env:
38-
CROSS_COMPILE: riscv32-unknown-elf-
46+
TOOLCHAIN_TYPE: ${{ matrix.toolchain }}
3947

4048
- name: Run Basic Apps
4149
id: test
@@ -44,16 +52,35 @@ jobs:
4452
echo "TEST_OUTPUT<<EOF" >> $GITHUB_OUTPUT
4553
echo "$output" >> $GITHUB_OUTPUT
4654
echo "EOF" >> $GITHUB_OUTPUT
55+
env:
56+
TOOLCHAIN_TYPE: ${{ matrix.toolchain }}
4757

4858
- name: Comment PR with results
4959
if: github.event_name == 'pull_request'
5060
uses: actions/github-script@v7
5161
with:
5262
script: |
5363
const output = `${{ steps.test.outputs.TEST_OUTPUT }}`;
64+
const toolchain = `${{ matrix.toolchain }}`.toUpperCase();
5465
github.rest.issues.createComment({
5566
issue_number: context.issue.number,
5667
owner: context.repo.owner,
5768
repo: context.repo.repo,
58-
body: `## Linmo QEMU App Test Result\n\n\`\`\`\n${output}\n\`\`\`\n\n_This is an automated report from CI._`
69+
body: `## Linmo QEMU App Test Result (${toolchain} Toolchain)\n\n\`\`\`\n${output}\n\`\`\`\n\n_This is an automated report from CI._`
5970
});
71+
72+
# Optional: Create a summary job that depends on all matrix jobs
73+
test-summary:
74+
runs-on: ubuntu-24.04
75+
needs: matrix-tests
76+
if: always()
77+
78+
steps:
79+
- name: Check test results
80+
run: |
81+
if [ "${{ needs.matrix-tests.result }}" = "success" ]; then
82+
echo "✅ All toolchain tests passed!"
83+
else
84+
echo "❌ Some toolchain tests failed"
85+
exit 1
86+
fi

0 commit comments

Comments
 (0)