Skip to content

Commit e792176

Browse files
committed
Add LLVM toolchain support to CI and build system
Remove test-summary job from CI workflow Update toolchain URLs and add CI test summary job Remove test64 argument from QEMU test script in CI Refactor toolchain URLs and add LLVM fallback in CI workflow Set CROSS_COMPILE to riscv32-unknown-elf- in CI setup Add AR=llvm-ar to LLVM toolchain environment setup Refactor toolchain URL to use TOOLCHAIN_OS variable Refactor RISC-V toolchain selection and defaults Run CI on all branches and pull requests Add __maybe_unused macro for unused attribute Use GNU ar instead of llvm-ar for LLVM toolchain Update toolchain version to verified Detect Clang toolchain in RISC-V build script
1 parent 3fa8d76 commit e792176

File tree

5 files changed

+111
-25
lines changed

5 files changed

+111
-25
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: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,60 @@
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+
TOOLCHAIN_REPO=https://github.com/riscv-collab/riscv-gnu-toolchain
8+
TOOLCHAIN_VERSION=2025.05.30
9+
TOOLCHAIN_OS=ubuntu-24.04
910

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

.github/workflows/ci.yml

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,84 @@ name: Linmo CI
22

33
on:
44
push:
5-
branches: [main, ci]
65
pull_request:
7-
branches: [main, ci]
86

97
jobs:
10-
basic-tests:
8+
matrix-tests:
119
runs-on: ubuntu-24.04
12-
name: Basic Tests
10+
name: Test on ${{ matrix.toolchain }} toolchain
11+
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
toolchain: [gnu, llvm]
1316

1417
steps:
1518
- name: Checkout
1619
uses: actions/checkout@v4
1720

18-
- name: Install dependencies
21+
- name: Install base dependencies
1922
run: |
2023
sudo apt-get update
2124
sudo apt-get install -y build-essential qemu-system-riscv32 wget
2225
23-
- name: Setup RISC-V Toolchain
24-
run: .ci/setup-toolchain.sh
26+
- name: Setup ${{ matrix.toolchain }} toolchain
27+
run: .ci/setup-toolchain.sh ${{ matrix.toolchain }}
2528

2629
- name: Verify toolchain installation
2730
run: |
28-
riscv32-unknown-elf-gcc --version
31+
if [ "${{ matrix.toolchain }}" = "gnu" ]; then
32+
riscv32-unknown-elf-gcc --version
33+
else
34+
# LLVM toolchain fallback: try system llvm-objdump
35+
riscv32-unknown-elf-clang --version || clang --version
36+
riscv32-unknown-elf-llvm-objdump --version || llvm-objdump --version
37+
fi
2938
qemu-system-riscv32 --version
30-
env:
31-
CROSS_COMPILE: riscv32-unknown-elf-
3239
3340
- name: Build Kernel
3441
run: |
3542
make clean
3643
make
3744
env:
38-
CROSS_COMPILE: riscv32-unknown-elf-
45+
TOOLCHAIN_TYPE: ${{ matrix.toolchain }}
3946

4047
- name: Run Basic Apps
4148
id: test
4249
run: |
43-
output=$(.ci/run-qemu-tests.sh cpubench test64)
50+
output=$(.ci/run-qemu-tests.sh cpubench )
4451
echo "TEST_OUTPUT<<EOF" >> $GITHUB_OUTPUT
4552
echo "$output" >> $GITHUB_OUTPUT
4653
echo "EOF" >> $GITHUB_OUTPUT
54+
env:
55+
TOOLCHAIN_TYPE: ${{ matrix.toolchain }}
4756

4857
- name: Comment PR with results
4958
if: github.event_name == 'pull_request'
5059
uses: actions/github-script@v7
5160
with:
5261
script: |
5362
const output = `${{ steps.test.outputs.TEST_OUTPUT }}`;
63+
const toolchain = `${{ matrix.toolchain }}`.toUpperCase();
5464
github.rest.issues.createComment({
5565
issue_number: context.issue.number,
5666
owner: context.repo.owner,
5767
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._`
68+
body: `## Linmo QEMU App Test Result (${toolchain} Toolchain)\n\n\`\`\`\n${output}\n\`\`\`\n\n_This is an automated report from CI._`
5969
});
70+
71+
# Optional: Create a summary job that depends on all matrix jobs
72+
test-summary:
73+
runs-on: ubuntu-24.04
74+
needs: matrix-tests
75+
if: always()
76+
77+
steps:
78+
- name: Check test results
79+
run: |
80+
if [ "${{ needs.matrix-tests.result }}" = "success" ]; then
81+
echo "✅ All toolchain tests passed!"
82+
else
83+
echo "❌ Some toolchain tests failed"
84+
exit 1
85+
fi

arch/riscv/build.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ DEFINES := -DF_CPU=$(F_CLK) \
1717
-DF_TIMER=$(F_TICK) \
1818
-include config.h
1919

20+
CROSS_COMPILE ?= riscv32-unknown-elf-
21+
CC = $(CROSS_COMPILE)gcc
22+
CC_IS_CLANG := $(shell $(CC) --version 2>/dev/null | grep -qi clang && echo 1)
23+
2024
# Architecture flags
2125
ARCH_FLAGS = -march=rv32imzicsr -mabi=ilp32
2226

@@ -28,26 +32,30 @@ CFLAGS += -mstrict-align -ffreestanding -nostdlib -fomit-frame-pointer
2832
CFLAGS += $(INC_DIRS) $(DEFINES) -fdata-sections -ffunction-sections
2933

3034
ifeq ($(CC_IS_CLANG),1)
35+
ifeq ($(TOOLCHAIN_TYPE),llvm)
3136
CC = $(CROSS_COMPILE)clang
3237
AS = $(CROSS_COMPILE)clang
3338
LD = $(CROSS_COMPILE)ld.lld
3439
DUMP = $(CROSS_COMPILE)llvm-objdump -M no-aliases
3540
READ = $(CROSS_COMPILE)llvm-readelf
3641
OBJ = $(CROSS_COMPILE)llvm-objcopy
3742
SIZE = $(CROSS_COMPILE)llvm-size
43+
AR = $(CROSS_COMPILE)ar
3844

3945
CFLAGS += --target=riscv32-unknown-elf
4046
CFLAGS += -Wno-unused-command-line-argument
4147
ASFLAGS = --target=riscv32-unknown-elf $(ARCH_FLAGS)
4248
LDFLAGS = -m elf32lriscv --gc-sections
4349
else
4450
CC = $(CC_DEFAULT)
51+
CC = $(CROSS_COMPILE)gcc
4552
AS = $(CROSS_COMPILE)as
4653
LD = $(CROSS_COMPILE)ld
4754
DUMP = $(CROSS_COMPILE)objdump -Mno-aliases
4855
READ = $(CROSS_COMPILE)readelf
4956
OBJ = $(CROSS_COMPILE)objcopy
5057
SIZE = $(CROSS_COMPILE)size
58+
AR = $(CROSS_COMPILE)ar
5159

5260
ASFLAGS = $(ARCH_FLAGS)
5361
LDFLAGS = -melf32lriscv --gc-sections

kernel/pipe.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#define PIPE_MIN_SIZE 4
1010
#define PIPE_MAX_SIZE 32768
1111

12+
#define __maybe_unused __attribute__((__unused__))
13+
1214
/* Enhanced validation with comprehensive integrity checks */
1315
static inline bool pipe_is_valid(const pipe_t *p)
1416
{

0 commit comments

Comments
 (0)