images: use mulitarch default image instead of hacky workaround

Instead of lying to clang about the targeted system, we can install the
necessary package only on x86_64 machines. Our tooling supports multiarch
packages (see tools/images.mk).

PiperOrigin-RevId: 591385576
This commit is contained in:
Kevin Krakauer
2023-12-15 16:14:40 -08:00
committed by gVisor bot
parent c1aef9f901
commit dc40c49df4
2 changed files with 5 additions and 17 deletions
+4
View File
@@ -10,6 +10,10 @@ RUN apt-get update && apt-get install -y curl gnupg2 git \
pkg-config libffi-dev patch diffutils libssl-dev iptables kmod \
clang crossbuild-essential-amd64 erofs-utils busybox-static libbpf-dev
# This package is needed to build eBPF on amd64, but not on arm64 where it
# doesn't exist.
RUN test "$(uname -m)" != x86_64 && exit 0 || apt-get install -y libc6-dev-i386
# Install Docker client for the website build.
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN add-apt-repository \
+1 -17
View File
@@ -104,21 +104,5 @@ def bpf_program(name, src, bpf_object, visibility, hdrs):
srcs = [src],
visibility = visibility,
outs = [bpf_object],
# Note: "-D __x86_64__" is a hack to deal with building across
# architectures. As we're targeting eBPF, setting this doesn't lead to
# any x86_64-specific code. But it does help with an annoying edge
# case:
#
# We have a single container -- images/default -- that runs on both
# arm64 and x86_64 machines. To build eBPF on x86_64, package
# gcc-multilib or libc6-dev-i386 is needed to install headers. But
# these don't exist on arm64, so adding it to the image breaks arm64
# builds.
#
# Defining __x86_64__ lets us avoid the need for these packages
# altogether. It turns out that the missing headers are irrelevant
# (unused) when building eBPF, and pretending we're targeting x86_64
# causes #includes to resolve without installing architecture-specific
# packages.
cmd = "clang -O2 -Wall -Werror -target bpf -c $< -o $@ -I/usr/include/$$(uname -m)-linux-gnu -D __x86_64__",
cmd = "clang -O2 -Wall -Werror -target bpf -c $< -o $@ -I/usr/include/$$(uname -m)-linux-gnu",
)