Skip to content

Commit 84b81ed

Browse files
committed
restructure actions to reusable build flow with parameters
Signed-off-by: Avi Deitcher <[email protected]>
1 parent 3b011cf commit 84b81ed

File tree

3 files changed

+262
-383
lines changed

3 files changed

+262
-383
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
name: Build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
artifact-name:
7+
description: "Name to use for the final collated artifact"
8+
required: true
9+
type: string
10+
os:
11+
description: "OS list"
12+
type: string
13+
default: '["ubuntu-22.04","ubuntu-24.04"]'
14+
mode:
15+
description: "Mode list"
16+
type: string
17+
default: '["newlib","linux","musl","uclibc"]'
18+
target:
19+
description: "Target list"
20+
type: string
21+
default: '["rv32gc-ilp32d","rv64gc-lp64d"]'
22+
compiler:
23+
description: "Compiler list"
24+
type: string
25+
default: '["gcc","llvm"]'
26+
sim:
27+
description: "Simulator"
28+
type: string
29+
30+
env:
31+
submodule_paths: |
32+
binutils
33+
dejagnu
34+
gcc
35+
gdb
36+
glibc
37+
llvm
38+
musl
39+
newlib
40+
pk
41+
qemu
42+
spike
43+
uclibc-ng
44+
.git/modules
45+
46+
jobs:
47+
submodule_cache:
48+
name: Initialize submodule cache
49+
runs-on: ubuntu-latest
50+
outputs:
51+
key: ${{ steps.keygen.outputs.smcache_key }}
52+
steps:
53+
- uses: actions/checkout@v4
54+
55+
- name: Remove unneeded frameworks to recover disk space
56+
run: sudo ./.github/cleanup-rootfs.sh
57+
58+
- name: Generate submodule cache key
59+
id: keygen
60+
run: echo "smcache_key=smcache-$(printf $(git submodule | sha1sum))" >> $GITHUB_OUTPUT
61+
62+
- name: Setup submodule cache
63+
id: smcache
64+
uses: actions/cache@v4
65+
with:
66+
path: ${{ env.submodule_paths }}
67+
key: ${{ steps.keygen.outputs.smcache_key }}
68+
69+
- name: Checkout required submodules
70+
if: steps.smcache.outputs.cache-hit != 'true'
71+
run: git submodule update --init -j $(nproc) --depth 1 $(echo ${submodule_paths} | sed '$d' | tr '\n' ' ')
72+
73+
- name: Storage size optimization
74+
if: steps.smcache.outputs.cache-hit != 'true'
75+
run: |
76+
git submodule foreach 'git maintenance run'
77+
78+
build:
79+
runs-on: ${{ matrix.os }}
80+
needs: [submodule_cache]
81+
env:
82+
smcache_key: ${{ needs.submodule_cache.outputs.key }}
83+
strategy:
84+
matrix:
85+
os: ${{ fromJSON(inputs.os) }}
86+
mode: ${{ fromJSON(inputs.mode) }}
87+
target: ${{ fromJSON(inputs.target) }}
88+
compiler: ${{ fromJSON(inputs.compiler) }}
89+
sim: ${{ fromJSON(inputs.sim) }}
90+
exclude:
91+
- mode: musl
92+
compiler: llvm
93+
- mode: uclibc
94+
compiler: llvm
95+
outputs:
96+
toolchain-name: ${{ steps.toolchain-name-generator.outputs.TOOLCHAIN_NAME }}
97+
steps:
98+
- uses: actions/checkout@v4
99+
100+
- name: Remove unneeded frameworks to recover disk space
101+
run: sudo ./.github/cleanup-rootfs.sh
102+
103+
- name: install dependencies
104+
run: sudo ./.github/setup-apt.sh
105+
106+
- name: Load submodule cache
107+
uses: actions/cache/restore@v4
108+
with:
109+
path: ${{ env.submodule_paths }}
110+
key: ${{ env.smcache_key }}
111+
112+
- name: build toolchain
113+
run: |
114+
TARGET_TUPLE=($(echo ${{ matrix.target }} | tr "-" "\n"))
115+
BUILD_TOOLCHAIN="./configure --prefix=/mnt/riscv --with-arch=${TARGET_TUPLE[0]} --with-abi=${TARGET_TUPLE[1]}"
116+
ARGS=""
117+
if [ "${{ matrix.compiler }}" == "llvm" ]; then # build toolchain with llvm
118+
ARGS="$ARGS --enable-llvm"
119+
fi
120+
if [ "${{ matrix.sim }}" != "" ]; then
121+
ARGS="$ARGS --with-sim=${{ matrix.sim }}"
122+
fi
123+
$BUILD_TOOLCHAIN $ARGS
124+
sudo mkdir /mnt/riscv
125+
sudo chown runner:runner /mnt/riscv
126+
make -j $(nproc) ${{ matrix.mode }}
127+
128+
- name: tarball build
129+
run: |
130+
du -s -h /mnt/riscv
131+
./.github/dedup-dir.sh /mnt/riscv/
132+
XZ_OPT="-e -T0" tar cJvf riscv.tar.xz -C /mnt/ riscv/
133+
134+
- name: make report
135+
if: |
136+
matrix.os == 'ubuntu-24.04'
137+
&& (matrix.mode == 'linux' || matrix.mode == 'newlib')
138+
&& matrix.compiler == 'gcc'
139+
run: |
140+
make report-${{ matrix.mode }} -j $(nproc)
141+
142+
- name: generate prebuilt toolchain name
143+
id: toolchain-name-generator
144+
run: |
145+
if [[ "${{ matrix.target }}" == *"32"* ]]; then BITS=32; else BITS=64; fi
146+
case "${{ matrix.mode }}" in
147+
"linux")
148+
MODE="glibc";;
149+
"musl")
150+
MODE="musl";;
151+
"uclibc")
152+
MODE="uclibc-ng";;
153+
*)
154+
MODE="elf";;
155+
esac
156+
echo "TOOLCHAIN_NAME=riscv$BITS-$MODE-${{ matrix.os }}-${{ matrix.compiler }}-nightly" >> $GITHUB_OUTPUT
157+
158+
- uses: actions/upload-artifact@v4
159+
with:
160+
name: ${{ steps.toolchain-name-generator.outputs.TOOLCHAIN_NAME }}
161+
path: riscv.tar.xz
162+
163+
collate-artifacts:
164+
needs: build
165+
runs-on: ubuntu-latest
166+
if: inputs.artifact-name != ''
167+
steps:
168+
- name: Download all toolchain artifacts
169+
uses: actions/download-artifact@v4
170+
with:
171+
path: all-toolchains
172+
173+
- name: List downloaded artifacts
174+
run: |
175+
echo "Contents of all-toolchains/"
176+
ls -R all-toolchains
177+
178+
- name: Upload collated toolchains
179+
uses: actions/upload-artifact@v4
180+
with:
181+
name: ${{ inputs.artifact-name }}
182+
path: all-toolchains/

0 commit comments

Comments
 (0)