Skip to content

Commit

Permalink
Post-build stripping.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzarc committed Jun 3, 2024
1 parent 6675697 commit f71daaf
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 8 deletions.
60 changes: 57 additions & 3 deletions .github/workflows/create_toolchains.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand All @@ -242,7 +296,7 @@ jobs:
if: always() && !cancelled()
uses: actions/download-artifact@v4
with:
pattern: toolchain-*
pattern: stripped-toolchains-*
path: .
merge-multiple: true

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/invoke_crosstool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions common.bashinc
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
22 changes: 18 additions & 4 deletions strip-toolchain.sh
Original file line number Diff line number Diff line change
@@ -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} <path-to-toolchain-dir>"
Expand All @@ -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 '{}' \;

0 comments on commit f71daaf

Please sign in to comment.