Skip to content

Commit

Permalink
add BPF GCC support for BPF CI
Browse files Browse the repository at this point in the history
Signed-off-by: Cupertino Miranda <[email protected]>
  • Loading branch information
cupermir authored and Cupertino Miranda committed Sep 19, 2024
1 parent f1bc702 commit e93262e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
5 changes: 4 additions & 1 deletion build-selftests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
toolchain:
description: 'what toolchain to use'
default: 'gcc'
bpf-toolchain:
description: 'what bpf toolchain to use'
default: 'clang'
kbuild-output:
description: 'relative or absolute path to use for storing build artifacts'
required: true
Expand All @@ -29,6 +32,6 @@ runs:
run: |
kbuild_output="$(realpath ${{ inputs.kbuild-output }})"
export LLVM_VERSION=${{ inputs.llvm-version }}
${GITHUB_ACTION_PATH}/build_selftests.sh "${{ inputs.arch }}" "${{ inputs.kernel }}" "${{ inputs.toolchain }}" "${kbuild_output}"
${GITHUB_ACTION_PATH}/build_selftests.sh "${{ inputs.arch }}" "${{ inputs.kernel }}" "${{ inputs.toolchain }}" "${kbuild_output}" "${{ inputs.bpf-toolchain }}"
env:
MAX_MAKE_JOBS: ${{ inputs.max-make-jobs }}
8 changes: 8 additions & 0 deletions build-selftests/build_selftests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ TARGET_ARCH="$1"
KERNEL="$2"
TOOLCHAIN="$3"
export KBUILD_OUTPUT="$4"
BPF_TOOLCHAIN="$5"

ARCH="$(platform_to_kernel_arch ${TARGET_ARCH})"
CROSS_COMPILE=""
BPF_GCC_BIN="${GITHUB_WORKSPACE}/install_bpf_gcc/bin/bpf-unknown-none-gcc"

if [[ "${TARGET_ARCH}" != "$(uname -m)" ]]
then
Expand Down Expand Up @@ -51,6 +53,12 @@ MAKE_OPTS=$(cat <<EOF
VMLINUX_H=${VMLINUX_H}
EOF
)

if [[ "${BPF_TOOLCHAIN}" == 'gcc' ]]
then
MAKE_OPTS="${MAKE_OPTS} BPF_GCC=${BPF_GCC_BIN}"
fi

SELF_OPTS=$(cat <<EOF
-C ${REPO_ROOT}/${REPO_PATH}/tools/testing/selftests/bpf
EOF
Expand Down
11 changes: 10 additions & 1 deletion setup-build-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ inputs:
arch:
description: 'arch'
required: true
bpf-toolchain:
description: 'bpf-toolchain to build'
required: true
runs:
using: "composite"
steps:
Expand All @@ -24,13 +27,19 @@ 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 linux-image-generic zstd 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 linux-image-generic zstd binutils-dev elfutils libcap-dev libelf-dev libdw-dev python3-docutils texinfo
echo "::endgroup::"
- name: Install clang
shell: bash
run: |
export LLVM_VERSION=${{ inputs.llvm-version }}
${GITHUB_ACTION_PATH}/install_clang.sh
- name: Install bpf-gcc
if: inputs.bpf-toolchain == 'gcc'
shell: bash
run: |
export BPF_TOOLCHAIN=${{ inputs.bpf-toolchain }}
${GITHUB_ACTION_PATH}/install_bpf_gcc.sh
- name: Install pahole
shell: bash
run: |
Expand Down
54 changes: 54 additions & 0 deletions setup-build-env/install_bpf_gcc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
set -eu

source $(cd $(dirname $0) && ${GITHUB_WORKSPACE})/../helpers.sh

LOGFILE=build-gnu-bpf.log
INSTALLDIR=${GITHUB_WORKSPACE}/install_bpf_gcc/

mkdir -p build_bpf_gcc
cd build_bpf_gcc

foldable start install_bpf_gcc "Installing BPF GCC"
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)

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_TARBALL... ";
(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_TARBALL... ";
(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
foldable end install_bpf_gcc

0 comments on commit e93262e

Please sign in to comment.