From f71daaf79a1230d289d2620a6fa89f2dd14336d3 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Mon, 3 Jun 2024 15:57:25 +1000 Subject: [PATCH] Post-build stripping. --- .github/workflows/create_toolchains.yaml | 60 ++++++++++++++++++++++-- .github/workflows/invoke_crosstool.yaml | 1 - common.bashinc | 2 + strip-toolchain.sh | 22 +++++++-- 4 files changed, 77 insertions(+), 8 deletions(-) diff --git a/.github/workflows/create_toolchains.yaml b/.github/workflows/create_toolchains.yaml index f8bb6d0..0f17f3e 100644 --- a/.github/workflows/create_toolchains.yaml +++ b/.github/workflows/create_toolchains.yaml @@ -96,7 +96,7 @@ jobs: - name: "Gather source tarballs" run: | # Clear out the tools prefix so we can run everything, even without a bootstrap compiler present - for f in $(ls *.sh); do ./$f --tools-prefix= source; done + for f in $(ls aarch64*.sh arm*.sh avr*.sh riscv32*.sh win64*.sh x64linux*.sh); do ./$f --tools-prefix= source; done tar cvf tarballs.tar tarballs - name: "Upload source tarballs" @@ -231,9 +231,63 @@ jobs: target_host: linuxARM64 build_script: aarch64linux-aarch64linux-canadian.sh + strip-and-repack-toolchains: + name: Strip and repack toolchains + needs: [bootstrap-linuxX64-toolchain, native-toolchains, canadian-toolchains, native-linuxX64-toolchain, canadian-windowsX64-toolchain, canadian-linuxARM64-toolchain] + if: always() && !cancelled() + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + target_host: [baremetalARM, baremetalAVR, baremetalRV32] + + steps: + - name: "Clone toolchains repo" + uses: actions/checkout@v4 + + - name: Download toolchains + if: always() && !cancelled() + uses: actions/download-artifact@v4 + with: + pattern: toolchain-*-target_${{ matrix.target_host }} + path: . + merge-multiple: true + + - name: Unpack toolchains + run: | + mkdir toolchains + for file in $(ls qmk_toolchain*.tar.xz); do + echo "Extracting $file" + tar xf $file -C toolchains + done + + - name: Strip toolchains + run: | + for dir in $(ls -d toolchains/*${{ matrix.target_host }}); do + echo "Stripping toolchain in $dir" + ./strip-toolchain.sh $dir + done + + - name: Repack toolchains + run: | + for dir in $(ls -d toolchains/*${{ matrix.target_host }}); do + output_filename=$(ls qmk_toolchain*.tar.xz | grep $(basename $dir)) + echo "Repacking toolchain in $dir => $output_filename" + [[ ! -f $output_filename ]] || rm -f $output_filename + tar cf $(basename ${output_filename} .xz) -C toolchains $(basename $dir) + xz -T 0 -z -9 -e $(basename ${output_filename} .xz) + done + + - name: Upload toolchain + uses: actions/upload-artifact@v4 + with: + name: stripped-toolchains-target_${{ matrix.target_host }} + path: | + qmk_toolchain-gcc*.tar.xz + publish: name: Publish toolchains - needs: [bootstrap-linuxX64-toolchain, native-toolchains, canadian-toolchains, native-linuxX64-toolchain, canadian-windowsX64-toolchain, canadian-linuxARM64-toolchain] + needs: [strip-and-repack-toolchains] if: always() && !cancelled() runs-on: ubuntu-latest @@ -242,7 +296,7 @@ jobs: if: always() && !cancelled() uses: actions/download-artifact@v4 with: - pattern: toolchain-* + pattern: stripped-toolchains-* path: . merge-multiple: true diff --git a/.github/workflows/invoke_crosstool.yaml b/.github/workflows/invoke_crosstool.yaml index ec8f0d3..b2467c3 100644 --- a/.github/workflows/invoke_crosstool.yaml +++ b/.github/workflows/invoke_crosstool.yaml @@ -220,7 +220,6 @@ jobs: fi latest_state=$(dirname $(find $(find build -mindepth 4 -maxdepth 5 -type d -name state) -mindepth 2 -maxdepth 2 -type f -name env.sh -print0 | xargs -0r $STAT -c '%w|%n' | sort | cut -d'|' -f2 | tail -n1)) source "$latest_state/env.sh" - ./strip-toolchain.sh toolchains/host_${{ inputs.build_host }}-target_${{ inputs.target_host }}${{ inputs.toolchain_suffix }} tar cf qmk_toolchain-gcc${CT_GCC_VERSION}-host_${{ inputs.build_host }}-target_${{ inputs.target_host }}${{ inputs.toolchain_suffix }}.tar -C toolchains host_${{ inputs.build_host }}-target_${{ inputs.target_host }}${{ inputs.toolchain_suffix }} ${DEREF_SYMLINKS_ARGS:-} xz -T 0 -z -9 -e qmk_toolchain-gcc${CT_GCC_VERSION}-host_${{ inputs.build_host }}-target_${{ inputs.target_host }}${{ inputs.toolchain_suffix }}.tar diff --git a/common.bashinc b/common.bashinc index ee9d179..cf7f581 100644 --- a/common.bashinc +++ b/common.bashinc @@ -196,6 +196,8 @@ function build_one() { ct-ng $sample_name echo "CT_EXPERIMENTAL=y" >>.config echo "CT_FORCE_EXTRACT=y" >>.config + echo "CT_STRIP_HOST_TOOLCHAIN_EXECUTABLES=y" >>.config + echo "CT_STRIP_TARGET_TOOLCHAIN_EXECUTABLES=y" >>.config if [[ ! -z "${build_host_compile:-}" ]]; then ${SED} -i \ diff --git a/strip-toolchain.sh b/strip-toolchain.sh index df76515..fa109dc 100755 --- a/strip-toolchain.sh +++ b/strip-toolchain.sh @@ -1,7 +1,10 @@ #!/usr/bin/env bash +set -eEuo pipefail + this_script="$PWD/$(basename ${BASH_SOURCE[0]})" script_dir=$(dirname "${this_script}") +source "${script_dir}/common.bashinc" if [[ -z "${1}" ]]; then echo "Usage: ${this_script} " @@ -15,16 +18,27 @@ if [[ ! -d "${toolchain_dir}" ]]; then exit 1 fi -# Work out the exec prefix -toolchain_prefix=$(find "${toolchain_dir}/bin" -type f -name '*-gcc' -exec basename '{}' \; | head -n1 | sed -e 's@gcc$@@g') +# Add the other compilers to the PATH for use +while read bindir; do + export PATH="$bindir:$PATH" + echo "Adding $bindir to \$PATH" +done < <(find "$script_dir/toolchains/host_$(fn_os_arch)"* -mindepth 1 -maxdepth 1 -type d -name bin) + +echo + +# Work out the toolchain prefix +toolchain_prefix=$(find "${toolchain_dir}/bin" -type f -name '*-gcc*' -exec basename '{}' \; 2>/dev/null | head -n1 | sed -e 's@gcc.*$@@g') + +echo "Toolchain prefix: ${toolchain_prefix}" +echo # Strip binaries find "${toolchain_dir}" -type f \ -name '*.o' -or -name '*.a' \ - -print \ + -printf '%P\n' \ -exec ${toolchain_prefix}strip --strip-debug '{}' \; find "${toolchain_dir}" -type f \ -name '*.a' \ - -print \ + -printf '%P\n' \ -exec ${toolchain_prefix}ranlib '{}' \; \ No newline at end of file