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