|
1 |
| -FROM archlinux as builder |
| 1 | +FROM rust:1.75-slim-bookworm as builder |
2 | 2 |
|
3 |
| -RUN pacman -Syu --noconfirm |
4 |
| -RUN pacman -S base-devel protobuf rustup --noconfirm |
| 3 | +ARG TARGETARCH |
| 4 | + |
| 5 | +RUN apt-get update |
| 6 | +RUN apt-get install --yes build-essential protobuf-compiler pkg-config llvm-16 |
5 | 7 |
|
6 | 8 | RUN rustup default stable
|
7 | 9 | RUN rustup install nightly
|
8 | 10 | RUN rustup component add rust-src --toolchain nightly
|
9 |
| -RUN rustup target add x86_64-unknown-linux-musl |
10 | 11 | RUN --mount=type=cache,target=/root/.cargo/registry \
|
11 | 12 | cargo install bpf-linker
|
12 | 13 |
|
13 | 14 | WORKDIR /workspace
|
| 15 | +# Docker uses the amd64/arm64 convention while Rust uses the x86_64/aarch64 convention. |
| 16 | +# Since Dockerfile doesn't support conditional variables (sigh), write the arch in Rust's |
| 17 | +# convention to a file for later usage. |
| 18 | +RUN if [ "$TARGETARCH" = "amd64" ]; \ |
| 19 | + then echo "x86_64" >> arch; \ |
| 20 | + else echo "aarch64" >> arch; \ |
| 21 | + fi |
| 22 | +RUN rustup target add $(eval cat arch)-unknown-linux-musl |
14 | 23 |
|
15 | 24 | COPY . .
|
| 25 | + |
| 26 | +# We need to tell bpf-linker where it can find LLVM's shared library file. |
| 27 | +# Ref: https://github.com/aya-rs/rustc-llvm-proxy/blob/cbcb3c6/src/lib.rs#L48 |
| 28 | +ENV LD_LIBRARY_PATH="/usr/lib/llvm-16/lib" |
| 29 | + |
16 | 30 | RUN --mount=type=cache,target=/workspace/target/ \
|
17 | 31 | --mount=type=cache,target=/root/.cargo/registry \
|
18 | 32 | cargo xtask build-ebpf --release
|
19 | 33 | RUN --mount=type=cache,target=/workspace/target/ \
|
20 | 34 | --mount=type=cache,target=/root/.cargo/registry \
|
21 |
| - RUSTFLAGS=-Ctarget-feature=+crt-static cargo build --release --target=x86_64-unknown-linux-musl |
| 35 | + RUSTFLAGS=-Ctarget-feature=+crt-static cargo build --release --target=$(eval cat arch)-unknown-linux-musl |
22 | 36 | RUN --mount=type=cache,target=/workspace/target/ \
|
23 |
| - cp /workspace/target/x86_64-unknown-linux-musl/release/loader /workspace/dataplane |
| 37 | + cp /workspace/target/$(eval cat arch)-unknown-linux-musl/release/loader /workspace/dataplane |
24 | 38 |
|
25 | 39 | FROM alpine
|
26 | 40 |
|
|
0 commit comments