Skip to content

Commit 45e313e

Browse files
committed
setup-build-env: enable GCC 15 installation
GCC 15 is not available in Ubuntu 24.04 repositories, which is the distro used by both github and self-hosted BPF CI runners. To enable GCC 15 installation, make setup-build-env scripts set up Ubuntu 25.04 (plucky) repositories and then install the packages. Update cross-compilation setup with a apt config restrictions instead of manipulating the source lists. Refactor the action.yml into a single action.sh script for simpler local testing. Signed-off-by: Ihor Solodrai <[email protected]>
1 parent 3d86310 commit 45e313e

File tree

5 files changed

+66
-35
lines changed

5 files changed

+66
-35
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
build_runs_on: ["ubuntu-24.04"]
1919
arch: ["x86_64"]
2020
kernel_compiler: ["gcc", "llvm"]
21-
gcc_version: [14]
21+
gcc_version: [14, 15]
2222
llvm_version: [20]
2323
kernel: ["LATEST"]
2424
build_release: [false]

setup-build-env/action.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -x -euo pipefail
4+
5+
export GITHUB_ACTION_PATH=${GITHUB_ACTION_PATH:-$(pwd)}
6+
7+
export PAHOLE_BRANCH=${PAHOLE_BRANCH:-master}
8+
export PAHOLE_ORIGIN=${PAHOLE_ORIGIN:-https://git.kernel.org/pub/scm/devel/pahole/pahole.git}
9+
export GCC_VERSION=${GCC_VERSION:-15}
10+
export LLVM_VERSION=${LLVM_VERSION:-20}
11+
export TARGET_ARCH=${TARGET_ARCH:-$(uname -m)}
12+
13+
# gcc >= 15 is not available in Ubuntu 24
14+
# use this variable to set up alternative apt repositories
15+
export UBUNTU_CODENAME_OVERRIDE=plucky # Ubuntu 25.04 with GCC 15.0.1
16+
17+
${GITHUB_ACTION_PATH}/install_packages.sh
18+
${GITHUB_ACTION_PATH}/install_clang.sh
19+
${GITHUB_ACTION_PATH}/build_pahole.sh
20+
21+
${GITHUB_ACTION_PATH}/install_cross_compilation_toolchain.sh $TARGET_ARCH

setup-build-env/action.yml

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,10 @@ runs:
2626
shell: bash
2727
env:
2828
GCC_VERSION: ${{ inputs.gcc-version }}
29-
run: |
30-
${GITHUB_ACTION_PATH}/install_packages.sh
31-
- name: Install clang
32-
shell: bash
33-
env:
3429
LLVM_VERSION: ${{ inputs.llvm-version }}
35-
run: |
36-
${GITHUB_ACTION_PATH}/install_clang.sh
37-
- name: Install pahole
38-
shell: bash
39-
env:
4030
PAHOLE_BRANCH: ${{ inputs.pahole }}
4131
PAHOLE_ORIGIN: ${{ inputs.pahole-origin }}
32+
TARGET_ARCH: ${{ inputs.arch }}
4233
run: |
43-
${GITHUB_ACTION_PATH}/build_pahole.sh
34+
${GITHUB_ACTION_PATH}/action.sh
4435
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:/usr/local/lib" >> $GITHUB_ENV
45-
- name: Install cross compilation toolchain
46-
shell: bash
47-
env:
48-
GCC_VERSION: ${{ inputs.gcc-version }}
49-
run: |
50-
${GITHUB_ACTION_PATH}/install_cross_compilation_toolchain.sh ${{ inputs.arch }}

setup-build-env/install_cross_compilation_toolchain.sh

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,19 @@ source /etc/os-release
1919

2020
DEB_ARCH="$(platform_to_deb_arch "${TARGET_ARCH}")"
2121
DEB_HOST_ARCH="$(dpkg --print-architecture)"
22-
UBUNTU_CODENAME=${VERSION_CODENAME:-noble}
2322
GCC_VERSION=${GCC_VERSION:-14}
23+
UBUNTU_CODENAME=${UBUNTU_CODENAME:-noble}
2424

25-
cat <<EOF | sudo tee /etc/apt/sources.list.d/ubuntu.sources
26-
Types: deb
27-
URIs: http://archive.ubuntu.com/ubuntu/
28-
Suites: ${UBUNTU_CODENAME} ${UBUNTU_CODENAME}-updates ${UBUNTU_CODENAME}-backports
29-
Components: main restricted universe multiverse
30-
Architectures: ${DEB_HOST_ARCH}
31-
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
25+
if [ "${GCC_VERSION}" -ge 15 ]; then
26+
UBUNTU_CODENAME=${UBUNTU_CODENAME_OVERRIDE}
27+
fi
3228

33-
Types: deb
34-
URIs: http://security.ubuntu.com/ubuntu/
35-
Suites: ${UBUNTU_CODENAME}-security
36-
Components: main restricted universe multiverse
37-
Architectures: ${DEB_HOST_ARCH}
38-
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
39-
EOF
29+
# Disable other apt sources for foreign architectures to avoid 404 errors
30+
# Only allow fetching packages for the added architecture from ports.ubuntu.com
31+
sudo tee /etc/apt/apt.conf.d/99-no-foreign-arch <<APT_CONF
32+
APT::Architectures "${DEB_HOST_ARCH}";
33+
APT::Architectures:: "${DEB_ARCH}";
34+
APT_CONF
4035

4136
sudo dpkg --add-architecture "$DEB_ARCH"
4237
cat <<EOF | sudo tee /etc/apt/sources.list.d/xcompile.sources
@@ -61,10 +56,17 @@ sudo update-alternatives --install \
6156
/usr/bin/${TARGET_ARCH}-linux-gnu-gcc \
6257
${TARGET_ARCH}-linux-gnu-gcc \
6358
/usr/bin/${TARGET_ARCH}-linux-gnu-gcc-${GCC_VERSION} 10
59+
sudo update-alternatives --set \
60+
${TARGET_ARCH}-linux-gnu-gcc \
61+
/usr/bin/${TARGET_ARCH}-linux-gnu-gcc-${GCC_VERSION}
62+
6463

6564
sudo update-alternatives --install \
6665
/usr/bin/${TARGET_ARCH}-linux-gnu-g++ \
6766
${TARGET_ARCH}-linux-gnu-g++ \
6867
/usr/bin/${TARGET_ARCH}-linux-gnu-g++-${GCC_VERSION} 10
68+
sudo update-alternatives --set \
69+
${TARGET_ARCH}-linux-gnu-g++ \
70+
/usr/bin/${TARGET_ARCH}-linux-gnu-g++-${GCC_VERSION}
6971

7072
foldable end install_crosscompile

setup-build-env/install_packages.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,35 @@ export GCC_VERSION=${GCC_VERSION:-14}
1010

1111
foldable start install_packages
1212

13+
source /etc/os-release
14+
15+
if [[ "$GCC_VERSION" -ge 15 && "${UBUNTU_CODENAME}" != "${UBUNTU_CODENAME_OVERRIDE}" ]]; then
16+
UBUNTU_CODENAME=${UBUNTU_CODENAME_OVERRIDE}
17+
cat <<EOF | sudo tee /etc/apt/sources.list.d/${UBUNTU_CODENAME}.list
18+
deb http://archive.ubuntu.com/ubuntu ${UBUNTU_CODENAME} main universe
19+
deb http://archive.ubuntu.com/ubuntu ${UBUNTU_CODENAME}-updates main universe
20+
deb http://archive.ubuntu.com/ubuntu ${UBUNTU_CODENAME}-security main universe
21+
EOF
22+
cat <<EOF | sudo tee /etc/apt/preferences.d/${UBUNTU_CODENAME}
23+
Package: *
24+
Pin: release n=${UBUNTU_CODENAME}
25+
Pin-Priority: 999
26+
EOF
27+
fi
28+
29+
sudo apt-get update -y
30+
31+
# add git-core/ppa to install latest git version
32+
sudo -E apt-get install -y software-properties-common
33+
sudo add-apt-repository -y ppa:git-core/ppa
1334
sudo apt-get update -y
1435

1536
sudo -E apt-get install --no-install-recommends -y \
1637
bc bison build-essential cmake cpu-checker curl dumb-init \
1738
elfutils ethtool ethtool flex gawk git iproute2 iptables \
1839
iputils-ping jq keyutils libguestfs-tools pkg-config \
19-
python3-docutils python3-minimal rsync software-properties-common \
20-
sudo texinfo tree tzdata wget xxd xz-utils zstd
40+
python3-docutils python3-minimal rsync sudo texinfo tree \
41+
tzdata wget xxd xz-utils zstd
2142

2243
sudo -E apt-get install --no-install-recommends -y \
2344
binutils-dev libcap-dev libdw-dev libelf-dev libpcap-dev \
@@ -30,5 +51,7 @@ sudo -E apt-get install --no-install-recommends -y \
3051
sudo apt-get install -y gcc-${GCC_VERSION} g++-${GCC_VERSION}
3152
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_VERSION} 10
3253
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${GCC_VERSION} 10
54+
sudo update-alternatives --set gcc /usr/bin/gcc-${GCC_VERSION}
55+
sudo update-alternatives --set g++ /usr/bin/g++-${GCC_VERSION}
3356

3457
foldable end install_packages

0 commit comments

Comments
 (0)