diff --git a/.github/workflows/kernel-build.yml b/.github/workflows/kernel-build.yml index 67a3fc5..fdca622 100644 --- a/.github/workflows/kernel-build.yml +++ b/.github/workflows/kernel-build.yml @@ -117,6 +117,8 @@ jobs: env: MAX_MAKE_JOBS: 32 RELEASE: ${{ inputs.release && '1' || '' }} + # GCC for building BPF selftests will be installed into BPF_GCC directory + BPF_GCC: ${{ github.workspace }}/bpf-gcc with: arch: ${{ inputs.arch }} kernel-root: ${{ env.KERNEL_ROOT }} diff --git a/build-bpf-gcc/action.yml b/build-bpf-gcc/action.yml new file mode 100644 index 0000000..9702b6a --- /dev/null +++ b/build-bpf-gcc/action.yml @@ -0,0 +1,32 @@ +name: 'Build BPF GCC' +description: 'Fetch latest GCC and binutils snapshots, bulid GCC and install into the target directory' +inputs: + install-dir: + description: "Path to the GCC installation directory" + required: true + +runs: + using: "composite" + steps: + + - name: Determine latest snapshots + id: latest-snapshots + shell: bash + run: ${GITHUB_ACTION_PATH}/latest-snapshots.sh + + - uses: actions/cache@v4 + id: cache + with: + path: ${{ inputs.install-dir }} + key: BPF-GCC-${{ steps.latest-snapshots.outputs.GCC_BASENAME }}-${{ steps.latest-snapshots.outputs.BINUTILS_BASENAME }} + + - if: steps.cache.outputs.cache-hit != 'true' + name: Build BPF GCC + env: + LOGFILE: /tmp/build-bpf-gcc.log + shell: bash + run: | + ${GITHUB_ACTION_PATH}/build-and-install.sh ${{ inputs.install-dir }} \ + || { cat $LOGFILE; exit 1; } + + diff --git a/build-bpf-gcc/build-and-install.sh b/build-bpf-gcc/build-and-install.sh new file mode 100755 index 0000000..ef1b154 --- /dev/null +++ b/build-bpf-gcc/build-and-install.sh @@ -0,0 +1,42 @@ +#!/bin/bash +set -euxo pipefail + +INSTALLDIR=$(realpath $1) +LOGFILE=${LOGFILE:-build-bpf-gcc.log} + +source ${GITHUB_ACTION_PATH}/.env + +test -f $BINUTILS_TARBALL || { + echo -n "Fetching $BINUTILS_URL... "; + wget -o /dev/null $BINUTILS_URL || { echo -e "\nerror: could not fetch $BINUTILS_URL"; exit 1; }; + echo done; +} + +test -f $GCC_TARBALL || { + echo -n "Fetching $GCC_URL... "; + wget -o /dev/null $GCC_URL || { echo -e "\nerror: could not fetch $GCC_URL"; exit 1; }; + echo done; +} + +if [ ! -f "${INSTALLDIR}/${BINUTILS_BASENAME}.built" ]; then + echo -n "Building and installing $BINUTILS_BASENAME... "; + (tar xJf $BINUTILS_TARBALL; + cd ${BINUTILS_BASENAME}; + mkdir build-bpf; + cd build-bpf && ../configure --target=bpf-unknown-none --prefix=$INSTALLDIR && make -j $(nproc) && make install && touch ${INSTALLDIR}/${BINUTILS_BASENAME}.built; + ) >> $LOGFILE 2>&1 || { echo -e "\nerror: building $BINUTILS_TARBALL"; exit 1; } + echo done +fi + +if [ ! -f "${INSTALLDIR}/${GCC_BASENAME}.built" ]; then + echo -n "Building and installing $GCC_BASENAME... "; + (tar xJf $GCC_TARBALL; + cd ${GCC_BASENAME}; + ./contrib/download_prerequisites + mkdir build-bpf; + cd build-bpf && ../configure --target=bpf-unknown-none --prefix=$INSTALLDIR && make -j $(nproc) && make install && touch ${INSTALLDIR}/${GCC_BASENAME}.built; + ) >> $LOGFILE 2>&1 || { echo -e "\nerror: building $GCC_TARBALL"; exit 1; } + echo done +fi + +exit 0 diff --git a/build-bpf-gcc/latest-snapshots.sh b/build-bpf-gcc/latest-snapshots.sh new file mode 100755 index 0000000..ae3c936 --- /dev/null +++ b/build-bpf-gcc/latest-snapshots.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -euo pipefail + +BINUTILS_TARBALL=`wget https://snapshots.sourceware.org/binutils/trunk/latest/src/sha512.sum -O - -o /dev/null | grep -E 'binutils-[0-9a-f.-]+.tar.xz' | sed -e 's/.*\(binutils-[^<]*\).*/\1/'` +GCC_TARBALL=`wget https://gcc.gnu.org/pub/gcc/snapshots/LATEST-15 -O - -o /dev/null | grep -E 'gcc-15-[0-9]+.tar.xz' | sed -e 's/.*\(gcc-15-[^<]*\).*/\1/'` + +BINUTILS_URL="https://snapshots.sourceware.org/binutils/trunk/latest/src/$BINUTILS_TARBALL" +GCC_URL="https://gcc.gnu.org/pub/gcc/snapshots/LATEST-15/$GCC_TARBALL" + +BINUTILS_BASENAME=$(basename $BINUTILS_TARBALL .tar.xz) +GCC_BASENAME=$(basename $GCC_TARBALL .tar.xz) + +cat > ${GITHUB_ACTION_PATH}/.env <> "$GITHUB_OUTPUT" +echo "GCC_BASENAME=${GCC_BASENAME}" >> "$GITHUB_OUTPUT" + +exit 0 diff --git a/build-selftests/action.yml b/build-selftests/action.yml index a040f3b..a1b2283 100644 --- a/build-selftests/action.yml +++ b/build-selftests/action.yml @@ -18,6 +18,12 @@ inputs: runs: using: "composite" steps: + + - if: ${{ env.BPF_GCC }} + uses: ./build-bpf-gcc + with: + install-dir: ${{ env.BPF_GCC }} + - name: build selftests shell: bash env: diff --git a/build-selftests/build_selftests.sh b/build-selftests/build_selftests.sh index 29fd67c..e8bf3c7 100755 --- a/build-selftests/build_selftests.sh +++ b/build-selftests/build_selftests.sh @@ -29,6 +29,7 @@ foldable start build_selftests "Building selftests with $TOOLCHAIN" MAKE_OPTS=$(cat <