From dc40c49df43c2540882647336414232a44834803 Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Fri, 15 Dec 2023 16:11:31 -0800 Subject: [PATCH] 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 --- images/default/Dockerfile | 4 ++++ tools/bazeldefs/defs.bzl | 18 +----------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/images/default/Dockerfile b/images/default/Dockerfile index 683028ce1..cd66962dc 100644 --- a/images/default/Dockerfile +++ b/images/default/Dockerfile @@ -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 \ diff --git a/tools/bazeldefs/defs.bzl b/tools/bazeldefs/defs.bzl index 0d7114c50..f986029b9 100644 --- a/tools/bazeldefs/defs.bzl +++ b/tools/bazeldefs/defs.bzl @@ -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", )