Add Submodule Caching to Toolchain Generation #546
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
jobs: | |
cache: | |
name: Update Submodule Cache | |
runs-on: ubuntu-24.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Cache GCC | |
uses: actions/cache@v4 | |
with: | |
path: | | |
.git/modules/gcc | |
gcc | |
key: compiler-gcc | |
- name: Cache LLVM | |
uses: actions/cache@v4 | |
with: | |
path: | | |
.git/modules/llvm | |
llvm | |
key: compiler-llvm | |
- name: Cache Newlib | |
uses: actions/cache@v4 | |
with: | |
path: | | |
.git/modules/newlib | |
newlib | |
key: mode-newlib | |
- name: Cache Linux | |
uses: actions/cache@v4 | |
with: | |
path: | | |
.git/modules/glibc | |
glibc | |
key: mode-linux | |
- name: Cache musl | |
uses: actions/cache@v4 | |
with: | |
path: | | |
.git/modules/musl | |
musl | |
key: mode-musl | |
- name: Cache uClibc | |
uses: actions/cache@v4 | |
with: | |
path: | | |
.git/modules/uclibc-ng | |
uclibc-ng | |
key: mode-uclibc | |
- name: Cache Always Required Submodules | |
uses: actions/cache@v4 | |
with: | |
path: | | |
.git/modules/binutils | |
.git/modules/gdb | |
binutils | |
gdb | |
key: general-dependencies | |
- name: Clone needed submodules | |
run: | | |
git submodule update --init --progress --depth 1 --jobs $(nproc) binutils gdb gcc llvm newlib glibc musl | |
git submodule update --init --progress uclibc-ng | |
build: | |
name: Build Toolchain Variants | |
runs-on: ${{ matrix.os }} | |
needs: [cache] | |
strategy: | |
matrix: | |
os: [ubuntu-22.04, ubuntu-24.04] | |
mode: [newlib, linux, musl, uclibc] | |
target: [rv32gc-ilp32d, rv64gc-lp64d] | |
compiler: [gcc, llvm] | |
exclude: | |
- mode: musl | |
compiler: llvm | |
- mode: uclibc | |
compiler: llvm | |
steps: | |
- name: Remove unneeded frameworks to recover disk space | |
run: | | |
echo "-- Before --" | |
df -h | |
sudo rm -rf /usr/share/dotnet | |
sudo rm -rf /usr/local/lib/android | |
echo "-- After --" | |
df -h | |
- name: Generate Required Submodules | |
id: required-submodules | |
run: | | |
case "${{ matrix.mode }}" in | |
"linux") | |
MODE_SUBMODULE="glibc";; | |
"musl") | |
MODE_SUBMODULE="musl";; | |
"uclibc") | |
MODE_SUBMODULE="uclibc-ng";; | |
"newlib") | |
MODE_SUBMODULE="newlib";; | |
*) | |
echo "Invalid Mode"; exit 1;; | |
esac | |
echo "MODE_SUBMODULE=$MODE_SUBMODULE" >> $GITHUB_OUTPUT | |
case "${{ matrix.compiler }}" in | |
"gcc") | |
COMPILER_SUBMODULE="gcc";; | |
"llvm") | |
COMPILER_SUBMODULE="llvm";; | |
*) | |
echo "Invalid Compiler"; exit 1;; | |
esac | |
echo "COMPILER_SUBMODULE=$COMPILER_SUBMODULE" >> $GITHUB_OUTPUT | |
- uses: actions/checkout@v4 | |
- name: Load Compiler Submodule from Cache | |
uses: actions/cache/restore@v4 | |
env: | |
submodule: ${{ steps.required-submodules.outputs.COMPILER_SUBMODULE }} | |
with: | |
path: | | |
.git/modules/${{ env.submodule }} | |
${{ env.submodule }} | |
key: compiler-${{ matrix.compiler }} | |
- name: Load Mode Submodule from Cache | |
uses: actions/cache/restore@v4 | |
env: | |
submodule: ${{ steps.required-submodules.outputs.MODE_SUBMODULE }} | |
with: | |
path: | | |
.git/modules/${{ env.submodule }} | |
${{ env.submodule }} | |
key: mode-${{ matrix.mode }} | |
- name: Load Always Required Submodules from Cache | |
uses: actions/cache/restore@v4 | |
with: | |
path: | | |
.git/modules/binutils | |
.git/modules/gdb | |
binutils | |
gdb | |
key: general-dependencies | |
- name: Install Dependencies | |
run: sudo ./.github/setup-apt.sh | |
- name: Build Toolchain | |
run: | | |
TARGET_TUPLE=($(echo ${{ matrix.target }} | tr "-" "\n")) | |
BUILD_TOOLCHAIN="./configure --prefix=/opt/riscv --with-arch=${TARGET_TUPLE[0]} --with-abi=${TARGET_TUPLE[1]}" | |
if [ "${{ matrix.compiler }}" == "llvm" ]; then # build toolchain with llvm | |
$BUILD_TOOLCHAIN --enable-llvm | |
else | |
$BUILD_TOOLCHAIN | |
fi | |
sudo make -j $(nproc) ${{ matrix.mode }} | |
- name: Generate Report | |
if: | | |
matrix.os == 'ubuntu-24.04' | |
&& (matrix.mode == 'linux' || matrix.mode == 'newlib') | |
&& matrix.compiler == 'gcc' | |
run: | | |
sudo make report-${{ matrix.mode }} -j $(nproc) | |
- name: Recover Space | |
run: | | |
sudo du -hs / 2> /dev/null || true | |
sudo rm -rf binutils dejagnu gcc gdb glibc llvm musl newlib pk qemu spike uclibc-ng || true | |
sudo du -hs / 2> /dev/null || true | |
- name: Tar Toolchain | |
run: tar czvf riscv.tar.gz -C /opt/ riscv/ | |
- name: Generate Prebuilt Toolchain Name | |
id: toolchain-name-generator | |
run: | | |
if [[ "${{ matrix.target }}" == *"32"* ]]; then BITS=32; else BITS=64; fi | |
case "${{ matrix.mode }}" in | |
"linux") | |
MODE="glibc";; | |
"musl") | |
MODE="musl";; | |
"uclibc") | |
MODE="uclibc-ng";; | |
*) | |
MODE="elf";; | |
esac | |
echo "TOOLCHAIN_NAME=riscv$BITS-$MODE-${{ matrix.os }}-${{ matrix.compiler }}-nightly" >> $GITHUB_OUTPUT | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ steps.toolchain-name-generator.outputs.TOOLCHAIN_NAME }} | |
path: riscv.tar.gz | |
test-sim: | |
name: Test Simulation | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-24.04] | |
mode: [newlib] | |
target: [rv64gc-lp64d] | |
sim: [spike] | |
steps: | |
- name: Remove unneeded frameworks to recover disk space | |
run: | | |
echo "-- Before --" | |
df -h | |
sudo rm -rf /usr/share/dotnet | |
sudo rm -rf /usr/local/lib/android | |
echo "-- After --" | |
df -h | |
- uses: actions/checkout@v4 | |
- name: Install Dependencies | |
run: sudo ./.github/setup-apt.sh | |
- name: Build Toolchain | |
run: | | |
TARGET_TUPLE=($(echo ${{ matrix.target }} | tr "-" "\n")) | |
./configure --prefix=/opt/riscv --with-arch=${TARGET_TUPLE[0]} --with-abi=${TARGET_TUPLE[1]} --with-sim=${{ matrix.sim }} | |
make -j $(nproc) ${{ matrix.mode }} | |
- name: Generate Report | |
run: make report-${{ matrix.mode }} -j $(nproc) | |
build-multilib: | |
if: ${{ false }} # Disable until multilib errors are triaged | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-24.04] | |
mode: [newlib, linux] | |
target: [rv64gc-lp64d] | |
steps: | |
- name: Remove unneeded frameworks to recover disk space | |
run: | | |
echo "-- Before --" | |
df -h | |
sudo rm -rf /usr/share/dotnet | |
sudo rm -rf /usr/local/lib/android | |
echo "-- After --" | |
df -h | |
- uses: actions/checkout@v4 | |
- name: install dependencies | |
run: sudo ./.github/setup-apt.sh | |
- name: build toolchain | |
run: | | |
TARGET_TUPLE=($(echo ${{ matrix.target }} | tr "-" "\n")) | |
./configure --prefix=/opt/riscv --with-arch=${TARGET_TUPLE[0]} --with-abi=${TARGET_TUPLE[1]} --enable-multilib | |
sudo make -j $(nproc) ${{ matrix.mode }} | |
- name: make report | |
run: | | |
sudo make report-${{ matrix.mode }} -j $(nproc) | |
- name: tarball build | |
run: tar czvf riscv.tar.gz -C /opt/ riscv/ | |
- name: generate prebuilt toolchain name | |
id: toolchain-name-generator | |
run: | | |
if [[ "${{ matrix.target }}" == *"32"* ]]; then BITS=32; else BITS=64; fi | |
case "${{ matrix.mode }}" in | |
"linux") | |
MODE="glibc";; | |
"musl") | |
MODE="musl";; | |
"uclibc") | |
MODE="uclibc-ng";; | |
*) | |
MODE="elf";; | |
esac | |
echo "TOOLCHAIN_NAME=riscv$BITS-$MODE-${{ matrix.os }}-multilib-nightly" >> $GITHUB_OUTPUT | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ steps.toolchain-name-generator.outputs.TOOLCHAIN_NAME }} | |
path: riscv.tar.gz |