Skip to content

Commit d4f4f53

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

File tree

3 files changed

+261
-383
lines changed

3 files changed

+261
-383
lines changed
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
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+
exclude:
90+
- mode: musl
91+
compiler: llvm
92+
- mode: uclibc
93+
compiler: llvm
94+
outputs:
95+
toolchain-name: ${{ steps.toolchain-name-generator.outputs.TOOLCHAIN_NAME }}
96+
steps:
97+
- uses: actions/checkout@v4
98+
99+
- name: Remove unneeded frameworks to recover disk space
100+
run: sudo ./.github/cleanup-rootfs.sh
101+
102+
- name: install dependencies
103+
run: sudo ./.github/setup-apt.sh
104+
105+
- name: Load submodule cache
106+
uses: actions/cache/restore@v4
107+
with:
108+
path: ${{ env.submodule_paths }}
109+
key: ${{ env.smcache_key }}
110+
111+
- name: build toolchain
112+
run: |
113+
TARGET_TUPLE=($(echo ${{ matrix.target }} | tr "-" "\n"))
114+
BUILD_TOOLCHAIN="./configure --prefix=/mnt/riscv --with-arch=${TARGET_TUPLE[0]} --with-abi=${TARGET_TUPLE[1]}"
115+
ARGS=""
116+
if [ "${{ matrix.compiler }}" == "llvm" ]; then # build toolchain with llvm
117+
ARGS="$ARGS --enable-llvm"
118+
fi
119+
if [ "${{ inputs.sim }}" != "" ]; then
120+
ARGS="$ARGS --with-sim=${{ inputs.sim }}"
121+
fi
122+
$BUILD_TOOLCHAIN $ARGS
123+
sudo mkdir /mnt/riscv
124+
sudo chown runner:runner /mnt/riscv
125+
make -j $(nproc) ${{ matrix.mode }}
126+
127+
- name: tarball build
128+
run: |
129+
du -s -h /mnt/riscv
130+
./.github/dedup-dir.sh /mnt/riscv/
131+
XZ_OPT="-e -T0" tar cJvf riscv.tar.xz -C /mnt/ riscv/
132+
133+
- name: make report
134+
if: |
135+
matrix.os == 'ubuntu-24.04'
136+
&& (matrix.mode == 'linux' || matrix.mode == 'newlib')
137+
&& matrix.compiler == 'gcc'
138+
run: |
139+
make report-${{ matrix.mode }} -j $(nproc)
140+
141+
- name: generate prebuilt toolchain name
142+
id: toolchain-name-generator
143+
run: |
144+
if [[ "${{ matrix.target }}" == *"32"* ]]; then BITS=32; else BITS=64; fi
145+
case "${{ matrix.mode }}" in
146+
"linux")
147+
MODE="glibc";;
148+
"musl")
149+
MODE="musl";;
150+
"uclibc")
151+
MODE="uclibc-ng";;
152+
*)
153+
MODE="elf";;
154+
esac
155+
echo "TOOLCHAIN_NAME=riscv$BITS-$MODE-${{ matrix.os }}-${{ matrix.compiler }}-nightly" >> $GITHUB_OUTPUT
156+
157+
- uses: actions/upload-artifact@v4
158+
with:
159+
name: ${{ steps.toolchain-name-generator.outputs.TOOLCHAIN_NAME }}
160+
path: riscv.tar.xz
161+
162+
collate-artifacts:
163+
needs: build
164+
runs-on: ubuntu-latest
165+
if: inputs.artifact-name != ''
166+
steps:
167+
- name: Download all toolchain artifacts
168+
uses: actions/download-artifact@v4
169+
with:
170+
path: all-toolchains
171+
172+
- name: List downloaded artifacts
173+
run: |
174+
echo "Contents of all-toolchains/"
175+
ls -R all-toolchains
176+
177+
- name: Upload collated toolchains
178+
uses: actions/upload-artifact@v4
179+
with:
180+
name: ${{ inputs.artifact-name }}
181+
path: all-toolchains/

0 commit comments

Comments
 (0)