From 5ac342c5e3f83b5a26f3a42c5e3046048fd43153 Mon Sep 17 00:00:00 2001 From: Nick Kossifidis Date: Sat, 2 Nov 2024 12:55:57 +0200 Subject: [PATCH 01/13] Use ubuntu-latest It's better to use ubuntu-latest to track current LTS provided by github, instead of having to manually update it. It also makes more sense to stick to the current LTS than trying to support the older one. Signed-off-by: Nick Kossifidis --- .github/workflows/build.yaml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 532332b2990..ae0ba37f2fd 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -13,7 +13,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-22.04, ubuntu-24.04] + os: [ubuntu-latest] mode: [newlib, linux, musl, uclibc] target: [rv32gc-ilp32d, rv64gc-lp64d] compiler: [gcc, llvm] @@ -50,8 +50,7 @@ jobs: - name: make report if: | - matrix.os == 'ubuntu-24.04' - && (matrix.mode == 'linux' || matrix.mode == 'newlib') + (matrix.mode == 'linux' || matrix.mode == 'newlib') && matrix.compiler == 'gcc' run: | sudo make report-${{ matrix.mode }} -j $(nproc) @@ -90,7 +89,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-24.04] + os: [ubuntu-latest] mode: [newlib] target: [rv64gc-lp64d] sim: [spike] @@ -123,7 +122,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-24.04] + os: [ubuntu-latest] mode: [newlib, linux] target: [rv64gc-lp64d] steps: From 243cd184b40c62e697a6794fd138eba1e148bc83 Mon Sep 17 00:00:00 2001 From: Nick Kossifidis Date: Sat, 2 Nov 2024 12:58:25 +0200 Subject: [PATCH 02/13] Allow to manually trigger build workflow This is usefull for testing / debugging. Signed-off-by: Nick Kossifidis --- .github/workflows/build.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ae0ba37f2fd..7691066b98f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,6 +1,7 @@ name: Build on: + workflow_dispatch: push: branches: - master From efc7cc9c828050d99125b0b6054a4ab80901adc8 Mon Sep 17 00:00:00 2001 From: Nick Kossifidis Date: Sat, 9 Nov 2024 20:58:26 +0200 Subject: [PATCH 03/13] Perform shallow clones of submodules Greatly reduces the time it takes to checkout the various submodules, and also reduces required storage. Signed-off-by: Nick Kossifidis --- .gitmodules | 14 +++++++++++++- Makefile.in | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 09f37f36668..9dc3a60554d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,44 +2,56 @@ path = binutils url = https://sourceware.org/git/binutils-gdb.git branch = binutils-2_43-branch + shallow = true [submodule "gcc"] path = gcc url = https://gcc.gnu.org/git/gcc.git branch = releases/gcc-14 + shallow = true [submodule "glibc"] path = glibc url = https://sourceware.org/git/glibc.git + shallow = true [submodule "dejagnu"] path = dejagnu url = https://git.savannah.gnu.org/git/dejagnu.git branch = master + shallow = true [submodule "newlib"] path = newlib url = https://sourceware.org/git/newlib-cygwin.git branch = master + shallow = true [submodule "gdb"] path = gdb url = https://sourceware.org/git/binutils-gdb.git branch = gdb-15-branch + shallow = true [submodule "qemu"] path = qemu url = https://gitlab.com/qemu-project/qemu.git + shallow = true [submodule "musl"] path = musl url = https://git.musl-libc.org/git/musl branch = master + shallow = true [submodule "spike"] path = spike url = /~https://github.com/riscv-software-src/riscv-isa-sim.git branch = master + shallow = true [submodule "pk"] path = pk url = /~https://github.com/riscv-software-src/riscv-pk.git branch = master + shallow = true [submodule "llvm"] path = llvm url = /~https://github.com/llvm/llvm-project.git branch = release/18.x + shallow = true [submodule "uclibc-ng"] path = uclibc-ng - url = https://git.uclibc-ng.org/git/uclibc-ng.git + url = /~https://github.com/wbx-github/uclibc-ng.git + shallow = true diff --git a/Makefile.in b/Makefile.in index 4449aa00d58..b597a4057c2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -347,7 +347,7 @@ endif $(srcdir)/%/.git: cd $(srcdir) && \ flock `git rev-parse --git-dir`/config git submodule init $(dir $@) && \ - flock `git rev-parse --git-dir`/config git submodule update --progress $(dir $@) + flock `git rev-parse --git-dir`/config git submodule update --progress --depth 1 $(dir $@) stamps/install-host-gcc: $(GCC_SRCDIR) $(GCC_SRC_GIT) if test -f $ Date: Sat, 9 Nov 2024 21:07:43 +0200 Subject: [PATCH 04/13] Move cleanup of base image to a script and improve it There are lots of things we can remove from the base image but the list becomes long and it polutes the workflow file, so it makes more sense to do this on a script instead. This gives us up to 50GB of free space, and we don't have to wait for it to finish, we can let those rm commands run in the background and move forward with the rest of the build process. Signed-off-by: Nick Kossifidis --- .github/cleanup-rootfs.sh | 66 ++++++++++++++++++++++++++ .github/workflows/build.yaml | 36 ++++---------- .github/workflows/nightly-release.yaml | 12 ++--- 3 files changed, 78 insertions(+), 36 deletions(-) create mode 100755 .github/cleanup-rootfs.sh diff --git a/.github/cleanup-rootfs.sh b/.github/cleanup-rootfs.sh new file mode 100755 index 00000000000..7d1b255c41c --- /dev/null +++ b/.github/cleanup-rootfs.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# There is no need to wait for this to finish, at least the rm part can be done +# while the process moves forward (for apt we'll need to wait for it to finish +# before we install dependencies later on, but it'll only give us a 1-3GBs so +# we can skip it. +WAIT=0 +RMONLY=1 + +PACKAGES=( + "firefox" + "google-chrome-stable" + "microsoft-edge-stable" + "php-pear" + "ruby-full" + "^aspnetcore-.*" + "^dotnet-.*" + "powershell*" +) + +PATHS=( + "/opt/hostedtoolcache" + "/usr/local/.ghcup/" + "/usr/share/swift" + "/usr/local/lib/android" + "/usr/local/share/edge_driver" + "/usr/local/share/gecko_driver" + "/usr/local/share/chromedriver-linux64" + "/usr/local/share/chromium" + "/home/linuxbrew" + "/usr/local/share/vcpkg" + "/usr/share/kotlinc" + "/usr/local/bin/minikube" +) + + +function cleanup_packages() +{ + if [[ ${RMONLY} == 0 ]]; then + apt-get purge -y "${PACKAGES[@]}" + apt-get autoremove --purge -y + apt-get clean + fi +} + +function cleanup_paths() +{ + for i in "${PATHS[@]}"; do + rm -rf "${i}" & + done + if [[ ${WAIT} == 1 ]]; then + wait + fi +} + +if [[ ${WAIT} == 1 ]]; then + echo "---=== Before ===---" + df -hT + cleanup_packages + cleanup_paths + echo "---=== After ===---" + df -hT +else + cleanup_packages + cleanup_paths +fi diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7691066b98f..693039a0775 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -24,17 +24,11 @@ jobs: - 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 - - uses: actions/checkout@v4 + - name: Remove unneeded frameworks to recover disk space + run: sudo ./.github/cleanup-rootfs.sh + - name: install dependencies run: sudo ./.github/setup-apt.sh @@ -95,17 +89,11 @@ jobs: 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: Remove unneeded frameworks to recover disk space + run: sudo ./.github/cleanup-rootfs.sh + - name: install dependencies run: sudo ./.github/setup-apt.sh @@ -127,17 +115,11 @@ jobs: 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: Remove unneeded frameworks to recover disk space + run: sudo ./.github/cleanup-rootfs.sh + - name: install dependencies run: sudo ./.github/setup-apt.sh diff --git a/.github/workflows/nightly-release.yaml b/.github/workflows/nightly-release.yaml index 5f97d9b2860..42b1bea5801 100644 --- a/.github/workflows/nightly-release.yaml +++ b/.github/workflows/nightly-release.yaml @@ -59,17 +59,11 @@ jobs: - 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 - - uses: actions/checkout@v4 + - name: Remove unneeded frameworks to recover disk space + run: sudo ./.github/cleanup-rootfs.sh + - name: install apt dependencies run: sudo ./.github/setup-apt.sh From 659b8ba4ed4a6f2d5847f7b166fd727207cc8bbe Mon Sep 17 00:00:00 2001 From: Nick Kossifidis Date: Sat, 9 Nov 2024 21:25:52 +0200 Subject: [PATCH 05/13] Cache fetched submodules across jobs Saves time by cloning the submodules only once per workflow run. This is also safer since some repos may block us if we attempt to clone multiple times (also in parallel) during the workflow. Signed-off-by: Nick Kossifidis --- .github/workflows/build.yaml | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 693039a0775..d5954066b5c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -9,9 +9,48 @@ on: branches: - master +env: + submodule_paths: | + binutils + dejagnu + gcc + gdb + glibc + llvm + musl + newlib + pk + qemu + spike + uclibc-ng + .git/modules + jobs: + submodule_cache: + name: Initialize submodule cache + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Remove unneeded frameworks to recover disk space + run: sudo ./.github/cleanup-rootfs.sh + + - name: Checkout required submodules + run: git submodule update --init -j $(nproc) --depth 1 $(echo ${submodule_paths} | sed '$d' | tr '\n' ' ') + + - name: Storage size optimization + run: | + git submodule foreach 'git maintenance run' + + - name: Setup submodule cache + uses: actions/cache@v4 + with: + path: ${{ env.submodule_paths }} + key: submodule-cache-${{ github.run_id }}-${{ github.run_attempt }} + build: runs-on: ${{ matrix.os }} + needs: [submodule_cache] strategy: matrix: os: [ubuntu-latest] @@ -32,6 +71,12 @@ jobs: - name: install dependencies run: sudo ./.github/setup-apt.sh + - name: Load submodule cache + uses: actions/cache/restore@v4 + with: + path: ${{ env.submodule_paths }} + key: submodule-cache-${{ github.run_id }}-${{ github.run_attempt }} + - name: build toolchain run: | TARGET_TUPLE=($(echo ${{ matrix.target }} | tr "-" "\n")) @@ -82,6 +127,7 @@ jobs: test-sim: runs-on: ${{ matrix.os }} + needs: [submodule_cache] strategy: matrix: os: [ubuntu-latest] @@ -97,6 +143,12 @@ jobs: - name: install dependencies run: sudo ./.github/setup-apt.sh + - name: Load submodule cache + uses: actions/cache/restore@v4 + with: + path: ${{ env.submodule_paths }} + key: submodule-cache-${{ github.run_id }}-${{ github.run_attempt }} + - name: build toolchain run: | TARGET_TUPLE=($(echo ${{ matrix.target }} | tr "-" "\n")) @@ -109,6 +161,7 @@ jobs: build-multilib: if: ${{ false }} # Disable until multilib errors are triaged runs-on: ${{ matrix.os }} + needs: [submodule_cache] strategy: matrix: os: [ubuntu-latest] @@ -123,6 +176,12 @@ jobs: - name: install dependencies run: sudo ./.github/setup-apt.sh + - name: Load submodule cache + uses: actions/cache/restore@v4 + with: + path: ${{ env.submodule_paths }} + key: submodule-cache-${{ github.run_id }}-${{ github.run_attempt }} + - name: build toolchain run: | TARGET_TUPLE=($(echo ${{ matrix.target }} | tr "-" "\n")) From 7261468fe08870aaa494aedb5ce8758f13f43f19 Mon Sep 17 00:00:00 2001 From: Nick Kossifidis Date: Sat, 9 Nov 2024 21:50:29 +0200 Subject: [PATCH 06/13] Use /mnt/riscv instead of /opt/riscv We have 14GB on /mnt available (more in practice) that we don't use at all. Instead of installing the toolchain / downloading artifacts in /opt thats in root partition, use /mnt instead. This patch also assigns ownership of that folder to the runner user, so that we drop use of sudo for make later on. Signed-off-by: Nick Kossifidis --- .github/workflows/build.yaml | 16 +++++++++++----- .github/workflows/nightly-release.yaml | 11 +++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d5954066b5c..f8f63c35772 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -80,12 +80,14 @@ jobs: - 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]}" + BUILD_TOOLCHAIN="./configure --prefix=/mnt/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 mkdir /mnt/riscv + sudo chown runner:runner /mnt/riscv sudo make -j $(nproc) ${{ matrix.mode }} - name: make report @@ -102,7 +104,7 @@ jobs: sudo du -hs / 2> /dev/null || true - name: tarball build - run: tar czvf riscv.tar.gz -C /opt/ riscv/ + run: tar czvf riscv.tar.gz -C /mnt/ riscv/ - name: generate prebuilt toolchain name id: toolchain-name-generator @@ -152,7 +154,9 @@ jobs: - 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 }} + ./configure --prefix=/mnt/riscv --with-arch=${TARGET_TUPLE[0]} --with-abi=${TARGET_TUPLE[1]} --with-sim=${{ matrix.sim }} + sudo mkdir /mnt/riscv + sudo chown runner:runner /mnt/riscv make -j $(nproc) ${{ matrix.mode }} - name: make report @@ -185,7 +189,9 @@ jobs: - 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 + ./configure --prefix=/mnt/riscv --with-arch=${TARGET_TUPLE[0]} --with-abi=${TARGET_TUPLE[1]} --enable-multilib + sudo mkdir /mnt/riscv + sudo chown runner:runner /mnt/riscv sudo make -j $(nproc) ${{ matrix.mode }} - name: make report @@ -193,7 +199,7 @@ jobs: sudo make report-${{ matrix.mode }} -j $(nproc) - name: tarball build - run: tar czvf riscv.tar.gz -C /opt/ riscv/ + run: tar czvf riscv.tar.gz -C /mnt/ riscv/ - name: generate prebuilt toolchain name id: toolchain-name-generator diff --git a/.github/workflows/nightly-release.yaml b/.github/workflows/nightly-release.yaml index 42b1bea5801..89eb77c60af 100644 --- a/.github/workflows/nightly-release.yaml +++ b/.github/workflows/nightly-release.yaml @@ -70,12 +70,14 @@ jobs: - 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]}" + BUILD_TOOLCHAIN="./configure --prefix=/mnt/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 mkdir /mnt/riscv + sudo chown runner:runner /mnt/riscv sudo make -j $(nproc) ${{ matrix.mode }} - name: build qemu @@ -90,7 +92,7 @@ jobs: sudo du -hs / 2> /dev/null || true - name: tarball build - run: tar czvf riscv.tar.gz -C /opt/ riscv/ + run: tar czvf riscv.tar.gz -C /mnt/ riscv/ - name: generate prebuilt toolchain name id: toolchain-name-generator @@ -136,8 +138,9 @@ jobs: echo "Version: ${DATESTAMP}-nightly" # Setup Artifacts Directory - ARTIFACTS_DIR="/opt/artifacts/" - mkdir -p $ARTIFACTS_DIR + ARTIFACTS_DIR="/mnt/artifacts/" + sudo mkdir -p $ARTIFACTS_DIR + sudo chown runner:runner $ARTIFACTS_DIR # Setup environment variables echo "DATESTAMP=${DATESTAMP}" >> $GITHUB_ENV From 911fd50f7e36a31afbc485c047d8c0677464659a Mon Sep 17 00:00:00 2001 From: Nick Kossifidis Date: Sat, 9 Nov 2024 21:59:13 +0200 Subject: [PATCH 07/13] No need for sudo when building toolchain Since the runner user owns the prefix dir, there is no need to use sudo. Signed-off-by: Nick Kossifidis --- .github/workflows/build.yaml | 8 ++++---- .github/workflows/nightly-release.yaml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index f8f63c35772..d879dfd778b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -88,14 +88,14 @@ jobs: fi sudo mkdir /mnt/riscv sudo chown runner:runner /mnt/riscv - sudo make -j $(nproc) ${{ matrix.mode }} + make -j $(nproc) ${{ matrix.mode }} - name: make report if: | (matrix.mode == 'linux' || matrix.mode == 'newlib') && matrix.compiler == 'gcc' run: | - sudo make report-${{ matrix.mode }} -j $(nproc) + make report-${{ matrix.mode }} -j $(nproc) - name: recover space run: | @@ -192,11 +192,11 @@ jobs: ./configure --prefix=/mnt/riscv --with-arch=${TARGET_TUPLE[0]} --with-abi=${TARGET_TUPLE[1]} --enable-multilib sudo mkdir /mnt/riscv sudo chown runner:runner /mnt/riscv - sudo make -j $(nproc) ${{ matrix.mode }} + make -j $(nproc) ${{ matrix.mode }} - name: make report run: | - sudo make report-${{ matrix.mode }} -j $(nproc) + make report-${{ matrix.mode }} -j $(nproc) - name: tarball build run: tar czvf riscv.tar.gz -C /mnt/ riscv/ diff --git a/.github/workflows/nightly-release.yaml b/.github/workflows/nightly-release.yaml index 89eb77c60af..8140119cc0e 100644 --- a/.github/workflows/nightly-release.yaml +++ b/.github/workflows/nightly-release.yaml @@ -78,12 +78,12 @@ jobs: fi sudo mkdir /mnt/riscv sudo chown runner:runner /mnt/riscv - sudo make -j $(nproc) ${{ matrix.mode }} + make -j $(nproc) ${{ matrix.mode }} - name: build qemu if: ${{ matrix.mode }} == 'linux' run: | - sudo make -j$(nproc) build-sim SIM=qemu + make -j$(nproc) build-sim SIM=qemu - name: recover space run: | From 825591e0ae9e22c704bc4debf8e5bf7d04d52af6 Mon Sep 17 00:00:00 2001 From: Nick Kossifidis Date: Sat, 9 Nov 2024 22:08:38 +0200 Subject: [PATCH 08/13] Only include toolchain in the tarball Currently we create the tarball after make report which results having qemu (both for 32 and 64bit), dejagnu, qemu etc in there too. Qemu ends up in the nightly releases too, with its roms etc, so clean that up too. Signed-off-by: Nick Kossifidis --- .github/workflows/build.yaml | 12 ++++++------ .github/workflows/nightly-release.yaml | 11 ----------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d879dfd778b..07117b95196 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -90,6 +90,9 @@ jobs: sudo chown runner:runner /mnt/riscv make -j $(nproc) ${{ matrix.mode }} + - name: tarball build + run: tar czvf riscv.tar.gz -C /mnt/ riscv/ + - name: make report if: | (matrix.mode == 'linux' || matrix.mode == 'newlib') @@ -103,9 +106,6 @@ jobs: 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: tarball build - run: tar czvf riscv.tar.gz -C /mnt/ riscv/ - - name: generate prebuilt toolchain name id: toolchain-name-generator run: | @@ -194,13 +194,13 @@ jobs: sudo chown runner:runner /mnt/riscv make -j $(nproc) ${{ matrix.mode }} + - name: tarball build + run: tar czvf riscv.tar.gz -C /mnt/ riscv/ + - name: make report run: | make report-${{ matrix.mode }} -j $(nproc) - - name: tarball build - run: tar czvf riscv.tar.gz -C /mnt/ riscv/ - - name: generate prebuilt toolchain name id: toolchain-name-generator run: | diff --git a/.github/workflows/nightly-release.yaml b/.github/workflows/nightly-release.yaml index 8140119cc0e..fd4f57e6968 100644 --- a/.github/workflows/nightly-release.yaml +++ b/.github/workflows/nightly-release.yaml @@ -80,17 +80,6 @@ jobs: sudo chown runner:runner /mnt/riscv make -j $(nproc) ${{ matrix.mode }} - - name: build qemu - if: ${{ matrix.mode }} == 'linux' - run: | - make -j$(nproc) build-sim SIM=qemu - - - 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: tarball build run: tar czvf riscv.tar.gz -C /mnt/ riscv/ From d9b55dcd2ac6a0a2e8c427cfe008c421ae706c7d Mon Sep 17 00:00:00 2001 From: Nick Kossifidis Date: Sat, 9 Nov 2024 22:17:33 +0200 Subject: [PATCH 09/13] Reduce output size using file deduplication There are files in the output that are the same with e.g. different names on different paths etc (and are not symlinks). Switch them to hardlinks so that tar doesn't archive them multiple times. This could be usefull to users too, since they may chose to preserve hardlinks when unpacking the tarball. Signed-off-by: Nick Kossifidis --- .github/dedup-dir.sh | 27 ++++++++++++++++++++++++++ .github/workflows/build.yaml | 10 ++++++++-- .github/workflows/nightly-release.yaml | 5 ++++- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100755 .github/dedup-dir.sh diff --git a/.github/dedup-dir.sh b/.github/dedup-dir.sh new file mode 100755 index 00000000000..079fdbf7234 --- /dev/null +++ b/.github/dedup-dir.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +function deduplicate_files() { + local DUPLICATES=() + local DIR=${1} + local IFS=$'\n' + local LINK_CHECK="" + + readarray -t DUPLICATES < <(for i in `find ${DIR} -type f ! -empty`; do sha1sum ${i}; done | sort | uniq -w 40 --all-repeated=separate) + + for ((i=1; i < ${#DUPLICATES[@]}; i++ )); do + if [[ ${DUPLICATES[$i]} == "" ]]; then + continue + elif [[ ${DUPLICATES[$i-1]} = "" ]]; then + continue + else + LINK_CHECK=$(ls -li "${DUPLICATES[$i]:42}" "${DUPLICATES[$i-1]:42}" |awk '{print $1}' | uniq | wc -l) + if [[ ${LINK_CHECK} != "1" ]]; then + ln -f "${DUPLICATES[$i-1]:42}" "${DUPLICATES[$i]:42}" + fi + fi + done + + return 0 +} + +deduplicate_files ${1} diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 07117b95196..d57c01c2826 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -91,7 +91,10 @@ jobs: make -j $(nproc) ${{ matrix.mode }} - name: tarball build - run: tar czvf riscv.tar.gz -C /mnt/ riscv/ + run: | + du -s -h /mnt/riscv + ./.github/dedup-dir.sh /mnt/riscv/ + tar czvf riscv.tar.gz -C /mnt/ riscv/ - name: make report if: | @@ -195,7 +198,10 @@ jobs: make -j $(nproc) ${{ matrix.mode }} - name: tarball build - run: tar czvf riscv.tar.gz -C /mnt/ riscv/ + run: | + du -s -h /mnt/riscv + ./.github/dedup-dir.sh /mnt/riscv/ + tar czvf riscv.tar.gz -C /mnt/ riscv/ - name: make report run: | diff --git a/.github/workflows/nightly-release.yaml b/.github/workflows/nightly-release.yaml index fd4f57e6968..a9d68d7e06f 100644 --- a/.github/workflows/nightly-release.yaml +++ b/.github/workflows/nightly-release.yaml @@ -81,7 +81,10 @@ jobs: make -j $(nproc) ${{ matrix.mode }} - name: tarball build - run: tar czvf riscv.tar.gz -C /mnt/ riscv/ + run: | + du -s -h /mnt/riscv + ./.github/dedup-dir.sh /mnt/riscv/ + tar czvf riscv.tar.gz -C /mnt/ riscv/ - name: generate prebuilt toolchain name id: toolchain-name-generator From 37d2c54faadade45937783d9d4339686b01eec37 Mon Sep 17 00:00:00 2001 From: Nick Kossifidis Date: Sat, 9 Nov 2024 22:36:24 +0200 Subject: [PATCH 10/13] Switch to xz compression Switch to xz from gzip, since it has a much better compress ratio. Signed-off-by: Nick Kossifidis --- .github/workflows/build.yaml | 8 ++++---- .github/workflows/nightly-release.yaml | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d57c01c2826..c3070412344 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -94,7 +94,7 @@ jobs: run: | du -s -h /mnt/riscv ./.github/dedup-dir.sh /mnt/riscv/ - tar czvf riscv.tar.gz -C /mnt/ riscv/ + XZ_OPT="-e -T0" tar cJvf riscv.tar.xz -C /mnt/ riscv/ - name: make report if: | @@ -128,7 +128,7 @@ jobs: - uses: actions/upload-artifact@v4 with: name: ${{ steps.toolchain-name-generator.outputs.TOOLCHAIN_NAME }} - path: riscv.tar.gz + path: riscv.tar.xz test-sim: runs-on: ${{ matrix.os }} @@ -201,7 +201,7 @@ jobs: run: | du -s -h /mnt/riscv ./.github/dedup-dir.sh /mnt/riscv/ - tar czvf riscv.tar.gz -C /mnt/ riscv/ + XZ_OPT="-e -T0" tar cJvf riscv.tar.xz -C /mnt/ riscv/ - name: make report run: | @@ -226,4 +226,4 @@ jobs: - uses: actions/upload-artifact@v4 with: name: ${{ steps.toolchain-name-generator.outputs.TOOLCHAIN_NAME }} - path: riscv.tar.gz + path: riscv.tar.xz diff --git a/.github/workflows/nightly-release.yaml b/.github/workflows/nightly-release.yaml index a9d68d7e06f..a374d8b38f6 100644 --- a/.github/workflows/nightly-release.yaml +++ b/.github/workflows/nightly-release.yaml @@ -84,7 +84,7 @@ jobs: run: | du -s -h /mnt/riscv ./.github/dedup-dir.sh /mnt/riscv/ - tar czvf riscv.tar.gz -C /mnt/ riscv/ + XZ_OPT="-e -T0" tar cJvf riscv.tar.xz -C /mnt/ riscv/ - name: generate prebuilt toolchain name id: toolchain-name-generator @@ -105,7 +105,7 @@ jobs: - uses: actions/upload-artifact@v4 with: name: ${{ steps.toolchain-name-generator.outputs.TOOLCHAIN_NAME }} - path: riscv.tar.gz + path: riscv.tar.xz create-release: @@ -216,4 +216,4 @@ jobs: upload_url: ${{ needs.create-release.outputs.upload_url }} asset_path: ${{ matrix.file }} asset_name: ${{ matrix.artifact }}-${{ needs.create-release.outputs.datestamp }}-nightly${{ matrix.extension }} - asset_content_type: application/gzip + asset_content_type: application/x-xz From 00efc94139a616bb0246f084f2f24deeb994a6a3 Mon Sep 17 00:00:00 2001 From: Nick Kossifidis Date: Sat, 9 Nov 2024 22:40:28 +0200 Subject: [PATCH 11/13] Revert "Use ubuntu-latest" This reverts commit 5ac342c5e3f83b5a26f3a42c5e3046048fd43153. It seems they haven't switched to 24.04 yet: /~https://github.com/actions/runner-images/issues/10636 Leave it as-is for now and we can revisit this if needed. Signed-off-by: Nick Kossifidis --- .github/workflows/build.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c3070412344..9ec814d57e8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -53,7 +53,7 @@ jobs: needs: [submodule_cache] strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-22.04, ubuntu-24.04] mode: [newlib, linux, musl, uclibc] target: [rv32gc-ilp32d, rv64gc-lp64d] compiler: [gcc, llvm] @@ -98,7 +98,8 @@ jobs: - name: make report if: | - (matrix.mode == 'linux' || matrix.mode == 'newlib') + matrix.os == 'ubuntu-24.04' + && (matrix.mode == 'linux' || matrix.mode == 'newlib') && matrix.compiler == 'gcc' run: | make report-${{ matrix.mode }} -j $(nproc) @@ -135,7 +136,7 @@ jobs: needs: [submodule_cache] strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-24.04] mode: [newlib] target: [rv64gc-lp64d] sim: [spike] @@ -171,7 +172,7 @@ jobs: needs: [submodule_cache] strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-24.04] mode: [newlib, linux] target: [rv64gc-lp64d] steps: From 4e699b4d633b706e3a48e08dc113d8f1b6597118 Mon Sep 17 00:00:00 2001 From: Nick Kossifidis Date: Sun, 10 Nov 2024 19:22:41 +0200 Subject: [PATCH 12/13] Allow submodule cache to persist across runs Although it only takes a few minutes to do the shallow clones, and we don't trigger runs that frequently, let's keep the submodule cache around, and invalidate it based on the hash of the 'git submodules' command, instead on each run. This will save us space on the repo's cache storage (10GB) and speed up the process a bit. Signed-off-by: Nick Kossifidis --- .github/workflows/build.yaml | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9ec814d57e8..fe91bd93b89 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -29,28 +29,39 @@ jobs: submodule_cache: name: Initialize submodule cache runs-on: ubuntu-latest + outputs: + key: ${{ steps.keygen.outputs.smcache_key }} steps: - uses: actions/checkout@v4 - name: Remove unneeded frameworks to recover disk space run: sudo ./.github/cleanup-rootfs.sh + - name: Generate submodule cache key + id: keygen + run: echo "smcache_key=smcache-$(printf $(git submodule | sha1sum))" >> $GITHUB_OUTPUT + + - name: Setup submodule cache + id: smcache + uses: actions/cache@v4 + with: + path: ${{ env.submodule_paths }} + key: ${{ steps.keygen.outputs.smcache_key }} + - name: Checkout required submodules + if: steps.smcache.outputs.cache-hit != 'true' run: git submodule update --init -j $(nproc) --depth 1 $(echo ${submodule_paths} | sed '$d' | tr '\n' ' ') - name: Storage size optimization + if: steps.smcache.outputs.cache-hit != 'true' run: | git submodule foreach 'git maintenance run' - - name: Setup submodule cache - uses: actions/cache@v4 - with: - path: ${{ env.submodule_paths }} - key: submodule-cache-${{ github.run_id }}-${{ github.run_attempt }} - build: runs-on: ${{ matrix.os }} needs: [submodule_cache] + env: + smcache_key: ${{ needs.submodule_cache.outputs.key }} strategy: matrix: os: [ubuntu-22.04, ubuntu-24.04] @@ -75,7 +86,7 @@ jobs: uses: actions/cache/restore@v4 with: path: ${{ env.submodule_paths }} - key: submodule-cache-${{ github.run_id }}-${{ github.run_attempt }} + key: ${{ env.smcache_key }} - name: build toolchain run: | @@ -134,6 +145,8 @@ jobs: test-sim: runs-on: ${{ matrix.os }} needs: [submodule_cache] + env: + smcache_key: ${{ needs.submodule_cache.outputs.key }} strategy: matrix: os: [ubuntu-24.04] @@ -153,7 +166,7 @@ jobs: uses: actions/cache/restore@v4 with: path: ${{ env.submodule_paths }} - key: submodule-cache-${{ github.run_id }}-${{ github.run_attempt }} + key: ${{ env.smcache_key }} - name: build toolchain run: | @@ -170,6 +183,8 @@ jobs: if: ${{ false }} # Disable until multilib errors are triaged runs-on: ${{ matrix.os }} needs: [submodule_cache] + env: + smcache_key: ${{ needs.submodule_cache.outputs.key }} strategy: matrix: os: [ubuntu-24.04] @@ -188,7 +203,7 @@ jobs: uses: actions/cache/restore@v4 with: path: ${{ env.submodule_paths }} - key: submodule-cache-${{ github.run_id }}-${{ github.run_attempt }} + key: ${{ env.smcache_key }} - name: build toolchain run: | From 404de92db17829e879077dace4f8279b10a2d424 Mon Sep 17 00:00:00 2001 From: Nick Kossifidis Date: Sun, 10 Nov 2024 22:47:14 +0200 Subject: [PATCH 13/13] No need for the recover space step after toolchain build This doesn't make sense anymore, it's not that we'll use any more space at that point, it may take up to a minute to complete, clean it up. Signed-off-by: Nick Kossifidis --- .github/workflows/build.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fe91bd93b89..7c06fb7b23e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -115,12 +115,6 @@ jobs: run: | 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: generate prebuilt toolchain name id: toolchain-name-generator run: |