Skip to content

Commit

Permalink
Add build-bpf-gcc action
Browse files Browse the repository at this point in the history
  • Loading branch information
theihor committed Dec 28, 2024
1 parent beb848b commit 83066ab
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 11 deletions.
28 changes: 18 additions & 10 deletions .github/workflows/kernel-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ jobs:
timeout-minutes: 100
env:
ARTIFACTS_ARCHIVE: "vmlinux-${{ inputs.arch }}-${{ inputs.toolchain_full }}.tar.zst"

BUILD_BPF_GCC: ${{ inputs.arch == 'x86_64' && 'true' || '' }}
BPF_GCC_INSTALL_DIR: ${{ github.workspace }}/bpf-gcc

BPF_NEXT_BASE_BRANCH: 'master'
BPF_NEXT_FETCH_DEPTH: 64 # A bit of history is needed to facilitate incremental builds
BUILD_SCHED_EXT_SELFTESTS: ${{ inputs.arch == 'x86_64' || inputs.arch == 'aarch64' && 'true' || '' }}
# BUILD_SCHED_EXT_SELFTESTS: ${{ inputs.arch == 'x86_64' || inputs.arch == 'aarch64' && 'true' || '' }}
KBUILD_OUTPUT: ${{ github.workspace }}/kbuild-output
KERNEL: ${{ inputs.kernel }}
KERNEL_ROOT: ${{ github.workspace }}
Expand Down Expand Up @@ -87,23 +91,18 @@ jobs:
cd ..
rmdir .kernel
- uses: ./patch-kernel

with:
patches-root: '${{ github.workspace }}/ci/diffs'
repo-root: ${{ env.REPO_ROOT }}

- name: Setup build environment
uses: ./setup-build-env
with:
arch: ${{ inputs.arch }}
llvm-version: ${{ inputs.llvm-version }}
pahole: master
- name: Print toolchain version used
shell: bash
run: |
TOOLCHAIN=${{ inputs.toolchain }}
if [ $TOOLCHAIN = "llvm" ]; then
TOOLCHAIN="clang-${{ inputs.llvm-version }}"
fi
${TOOLCHAIN} --version

- name: Build kernel image
uses: ./build-linux
with:
Expand All @@ -112,11 +111,19 @@ jobs:
kbuild-output: ${{ env.KBUILD_OUTPUT }}
max-make-jobs: 32
llvm-version: ${{ inputs.llvm-version }}

- if: ${{ env.BUILD_BPF_GCC }}
name: Build GCC for BPF selftests
uses: theihor/libbpf-ci/build-bpf-gcc@bpf-gcc
with:
install-dir: ${{ env.BPF_GCC_INSTALL_DIR }}

- name: Build selftests/bpf
uses: ./build-selftests
env:
MAX_MAKE_JOBS: 32
RELEASE: ${{ inputs.release && '1' || '' }}
BPF_GCC: ${{ env.BUILD_BPF_GCC && env.BPF_GCC_INSTALL_DIR || '' }}
with:
arch: ${{ inputs.arch }}
kernel-root: ${{ env.KERNEL_ROOT }}
Expand All @@ -133,6 +140,7 @@ jobs:
toolchain: ${{ inputs.toolchain }}
llvm-version: ${{ inputs.llvm-version }}
max-make-jobs: 32

- if: ${{ github.event_name != 'push' }}
name: Build samples
uses: ./build-samples
Expand All @@ -147,7 +155,7 @@ jobs:
uses: ./tar-artifacts
env:
ARCHIVE_BPF_SELFTESTS: 'true'
ARCHIVE_MAKE_HELPERS: ${{ github.repository != 'kernel-patches/bpf' && 'true' || '' }}
ARCHIVE_MAKE_HELPERS: 'true'
ARCHIVE_SCHED_EXT_SELFTESTS: ${{ env.BUILD_SCHED_EXT_SELFTESTS }}
with:
arch: ${{ inputs.arch }}
Expand Down
32 changes: 32 additions & 0 deletions build-bpf-gcc/action.yml
Original file line number Diff line number Diff line change
@@ -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; }
42 changes: 42 additions & 0 deletions build-bpf-gcc/build-and-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
set -euo 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
25 changes: 25 additions & 0 deletions build-bpf-gcc/latest-snapshots.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
BINUTILS_TARBALL=$BINUTILS_TARBALL
GCC_TARBALL=$GCC_TARBALL
BINUTILS_URL=$BINUTILS_URL
GCC_URL=$GCC_URL
BINUTILS_BASENAME=$BINUTILS_BASENAME
GCC_BASENAME=$GCC_BASENAME
EOF

echo "BINUTILS_BASENAME=${BINUTILS_BASENAME}" >> "$GITHUB_OUTPUT"
echo "GCC_BASENAME=${GCC_BASENAME}" >> "$GITHUB_OUTPUT"

exit 0
6 changes: 6 additions & 0 deletions build-selftests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions build-selftests/build_selftests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ if [[ $TOOLCHAIN = "llvm" ]]; then
TOOLCHAIN="llvm-$LLVM_VERSION"
fi

if [ -n "${BPF_GCC:-}" ]; then
BPF_GCC="${BPF_GCC}/bin/bpf-unknown-none-gcc"
else
BPF_GCC=
fi

foldable start build_selftests "Building selftests with $TOOLCHAIN"

MAKE_OPTS=$(cat <<EOF
ARCH=${ARCH}
BPF_GCC=${BPF_GCC}
CROSS_COMPILE=${CROSS_COMPILE}
CLANG=clang-${LLVM_VERSION}
LLC=llc-${LLVM_VERSION}
Expand Down
2 changes: 1 addition & 1 deletion setup-build-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ runs:
run: |
echo "::group::Setup"
sudo apt-get update
sudo apt-get install -y cmake flex bison build-essential libssl-dev ncurses-dev xz-utils bc rsync libguestfs-tools qemu-kvm qemu-utils zstd libzstd-dev binutils-dev elfutils libcap-dev libelf-dev libdw-dev python3-docutils
sudo apt-get install -y cmake flex bison build-essential libssl-dev ncurses-dev xz-utils bc rsync libguestfs-tools qemu-kvm qemu-utils zstd libzstd-dev binutils-dev elfutils libcap-dev libelf-dev libdw-dev python3-docutils texinfo
echo "::endgroup::"
- name: Install clang
shell: bash
Expand Down

0 comments on commit 83066ab

Please sign in to comment.