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