Skip to content

Commit 3bcbbf8

Browse files
committed
setup-build-env: fix cross-compilation dependencies
BPF CI got broken due to apt errors when installing cross compilers: * https://github.com/kernel-patches/bpf/actions/runs/14519065074/job/40735249827 dpkg --add-architecture now breaks apt config. Looks like there were changes in Ubuntu that require migrating to deb822 [1][2] format of apt package lists. In our case not only target arch repos need to be added, but also default /etc/apt/sources.list.d/ubuntu.sources needs to be modified. The host architecture has to be whitelisted, otherwise apt attempts fetching target arch packages from archive and security, and they are not there. Another issue was with libelf-dev:s390x dependencies. Current linux-libc-dev breaks linux-libc-dev:s390x, and unfortunately we need both for a proper cross-compilation build. Using aptituide I found that downgrading linux-libc-dev:amd64 resolves this conflict. [1] actions/runner-images#10901 [2] https://discourse.ubuntu.com/t/ubuntu-24-04-lts-noble-numbat-release-notes/39890#p-99950-deb822-sources-management Signed-off-by: Ihor Solodrai <[email protected]>
1 parent 4c78f40 commit 3bcbbf8

File tree

1 file changed

+49
-15
lines changed

1 file changed

+49
-15
lines changed

setup-build-env/install_cross_compilation_toolchain.sh

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,62 @@ set -euo pipefail
44

55
THISDIR="$(cd "$(dirname "$0")" && pwd)"
66

7-
# shellcheck source=./helpers.sh
87
source "${THISDIR}"/../helpers.sh
98

109
TARGET_ARCH="$1"
1110

1211
foldable start install_crosscompile "Installing Cross-Compilation toolchain"
1312

14-
if [[ "${TARGET_ARCH}" != "$(uname -m)" ]]
15-
then
16-
DEB_ARCH="$(platform_to_deb_arch "${TARGET_ARCH}")"
17-
# shellcheck source=/dev/null
18-
. /etc/os-release
19-
cat <<EOF > /etc/apt/sources.list.d/xcompile.list
20-
deb [arch=${DEB_ARCH}] http://ports.ubuntu.com/ubuntu-ports ${VERSION_CODENAME} main restricted
21-
deb [arch=${DEB_ARCH}] http://ports.ubuntu.com/ubuntu-ports ${VERSION_CODENAME}-updates main restricted
22-
EOF
23-
apt update
24-
# Add the architecture
25-
dpkg --add-architecture "${DEB_ARCH}"
26-
apt install -y g{cc,++}-"${TARGET_ARCH}-linux-gnu" {libelf-dev,libssl-dev}:"${DEB_ARCH}"
27-
else
13+
if [[ "${TARGET_ARCH}" == "$(uname -m)" ]]; then
2814
echo "Nothing to do. Target arch is the same as host arch: ${TARGET_ARCH}"
15+
exit 0
2916
fi
3017

18+
source /etc/os-release
19+
20+
DEB_ARCH="$(platform_to_deb_arch "${TARGET_ARCH}")"
21+
DEB_HOST_ARCH="$(dpkg --print-architecture)"
22+
UBUNTU_CODENAME=${VERSION_CODENAME:-noble}
23+
24+
cat <<EOF | sudo tee /etc/apt/sources.list.d/ubuntu.sources
25+
Types: deb
26+
URIs: http://archive.ubuntu.com/ubuntu/
27+
Suites: ${UBUNTU_CODENAME} ${UBUNTU_CODENAME}-updates ${UBUNTU_CODENAME}-backports
28+
Components: main restricted universe multiverse
29+
Architectures: ${DEB_HOST_ARCH}
30+
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
31+
32+
Types: deb
33+
URIs: http://security.ubuntu.com/ubuntu/
34+
Suites: ${UBUNTU_CODENAME}-security
35+
Components: main restricted universe multiverse
36+
Architectures: ${DEB_HOST_ARCH}
37+
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
38+
EOF
39+
40+
sudo dpkg --add-architecture "$DEB_ARCH"
41+
cat <<EOF | sudo tee /etc/apt/sources.list.d/xcompile.sources
42+
Types: deb
43+
URIs: http://ports.ubuntu.com/ubuntu-ports
44+
Suites: ${UBUNTU_CODENAME} ${UBUNTU_CODENAME}-updates ${UBUNTU_CODENAME}-security
45+
Components: main restricted universe multiverse
46+
Architectures: ${DEB_ARCH}
47+
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
48+
EOF
49+
50+
sudo apt-get update -y
51+
52+
# downgrade due to conflict with linux-libc-dev:s390x
53+
sudo apt-get install --allow-downgrades -y linux-libc-dev=6.8.0-57.59
54+
55+
sudo apt-get install -y \
56+
"crossbuild-essential-${DEB_ARCH}" \
57+
"binutils-${TARGET_ARCH}-linux-gnu" \
58+
"gcc-${TARGET_ARCH}-linux-gnu" \
59+
"g++-${TARGET_ARCH}-linux-gnu" \
60+
"linux-libc-dev:${DEB_ARCH}" \
61+
"libelf-dev:${DEB_ARCH}" \
62+
"libssl-dev:${DEB_ARCH}" \
63+
"zlib1g-dev:${DEB_ARCH}"
64+
3165
foldable end install_crosscompile

0 commit comments

Comments
 (0)