|
10 | 10 | # - Ubuntu 20.04 (glibc 2.31 — broad compatibility baseline) |
11 | 11 | # - Clang/LLD for all compilation and linking via --target |
12 | 12 | # - GNU cross-sysroots via crossbuild-essential (Ubuntu multiarch) |
13 | | -# - musl sysroots from musl.cc (headers + libs only; clang/lld do the work) |
| 13 | +# - musl sysroots from GHCR-hosted rust-musl-cross images |
14 | 14 | # - Node.js 20 (glibc-linked, used as build tool for all targets) |
15 | 15 | # - Rust nightly toolchain (pinned to match rust-toolchain.toml) |
16 | 16 | # - @napi-rs/cli for building native Node.js addons |
17 | 17 |
|
| 18 | +FROM ghcr.io/rust-cross/rust-musl-cross:x86_64-musl AS musl_x86_64 |
| 19 | +FROM ghcr.io/rust-cross/rust-musl-cross:aarch64-musl AS musl_aarch64 |
| 20 | + |
18 | 21 | FROM ubuntu:20.04 AS builder |
19 | 22 |
|
20 | 23 | # Avoid interactive prompts during apt-get |
@@ -54,19 +57,20 @@ RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certifi |
54 | 57 | crossbuild-essential-amd64 crossbuild-essential-arm64 \ |
55 | 58 | && rm -rf /var/lib/apt/lists/* |
56 | 59 |
|
57 | | -# Download musl cross-toolchains from musl.cc for their sysroots |
58 | | -# (headers, crt files, libc, libgcc). Clang + rust-lld handle compilation |
59 | | -# and linking; we only need the target libraries. |
60 | | -# Also copy GCC's crt files and libgcc into the sysroot lib dir — clang 10 |
61 | | -# doesn't search the --gcc-toolchain path for these files. |
62 | | -# https://musl.cc/ |
63 | | -RUN cd /opt && \ |
64 | | - for TRIPLE in aarch64-linux-musl x86_64-linux-musl; do \ |
65 | | - wget -qO- "https://musl.cc/${TRIPLE}-cross.tgz" | tar xz && \ |
66 | | - cp /opt/${TRIPLE}-cross/lib/gcc/${TRIPLE}/*/crt*.o \ |
67 | | - /opt/${TRIPLE}-cross/lib/gcc/${TRIPLE}/*/libgcc.a \ |
68 | | - /opt/${TRIPLE}-cross/${TRIPLE}/lib/; \ |
69 | | - done |
| 60 | +# Import prebuilt musl sysroots from the rust-musl-cross images and stage them |
| 61 | +# under /opt/*-cross for docker-native-build.sh. The symlinks provide the |
| 62 | +# target names that our clang --sysroot flags use, and libgcc/crt objects are |
| 63 | +# copied into the sysroot lib dir so clang/rust-lld can find them while linking. |
| 64 | +COPY --from=musl_x86_64 /usr/local/musl /opt/x86_64-linux-musl-cross |
| 65 | +COPY --from=musl_aarch64 /usr/local/musl /opt/aarch64-linux-musl-cross |
| 66 | +RUN ln -s x86_64-unknown-linux-musl /opt/x86_64-linux-musl-cross/x86_64-linux-musl && \ |
| 67 | + ln -s aarch64-unknown-linux-musl /opt/aarch64-linux-musl-cross/aarch64-linux-musl && \ |
| 68 | + cp /opt/x86_64-linux-musl-cross/lib/gcc/x86_64-unknown-linux-musl/*/crt*.o \ |
| 69 | + /opt/x86_64-linux-musl-cross/lib/gcc/x86_64-unknown-linux-musl/*/libgcc.a \ |
| 70 | + /opt/x86_64-linux-musl-cross/x86_64-linux-musl/lib/ && \ |
| 71 | + cp /opt/aarch64-linux-musl-cross/lib/gcc/aarch64-unknown-linux-musl/*/crt*.o \ |
| 72 | + /opt/aarch64-linux-musl-cross/lib/gcc/aarch64-unknown-linux-musl/*/libgcc.a \ |
| 73 | + /opt/aarch64-linux-musl-cross/aarch64-linux-musl/lib/ |
70 | 74 |
|
71 | 75 | # Install Rust — pinned nightly from rust-toolchain.toml |
72 | 76 | # The COPY of rust-toolchain.toml ensures the image rebuilds when the toolchain changes. |
|
0 commit comments