Skip to content

Commit 49f8cf2

Browse files
committed
fix binary builds
1 parent 46f6cfd commit 49f8cf2

3 files changed

Lines changed: 32 additions & 21 deletions

File tree

.github/workflows/build_and_deploy.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,12 @@ jobs:
249249
node-version: ${{ env.NODE_LTS_VERSION }}
250250
check-latest: true
251251

252+
- name: Prepare corepack
253+
if: ${{ matrix.os != 'windows' }}
254+
run: npm i -g corepack@0.31
255+
252256
- name: Setup corepack
253-
run: |
254-
npm i -g corepack@0.31
255-
corepack enable
257+
run: corepack enable
256258

257259
# we always want to run this to set environment variables
258260
# (skip for docker builds - rust is already in the image)

crates/next-napi-bindings/build.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ use serde_json::Value;
44

55
fn main() -> anyhow::Result<()> {
66
println!("cargo:rerun-if-env-changed=CI");
7+
println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_OS");
8+
println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH");
79
let is_ci = env::var("CI").is_ok_and(|value| !value.is_empty());
10+
let is_macos_aarch64_target = env::var("CARGO_CFG_TARGET_OS")
11+
.is_ok_and(|value| value == "macos")
12+
&& env::var("CARGO_CFG_TARGET_ARCH").is_ok_and(|value| value == "aarch64");
813

914
let nextjs_version = {
1015
let package_json_path = Path::new(env!("CARGO_MANIFEST_DIR"))
@@ -68,12 +73,12 @@ fn main() -> anyhow::Result<()> {
6873
_ => println!("cargo:warning=`git rev-parse HEAD` failed"),
6974
}
7075

71-
#[cfg(not(all(target_os = "macos", target_arch = "aarch64")))]
72-
napi_build::setup();
76+
if !is_macos_aarch64_target {
77+
napi_build::setup();
78+
}
7379

7480
// This is a workaround for napi always including a GCC specific flag.
75-
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
76-
{
81+
if is_macos_aarch64_target {
7782
println!("cargo:rerun-if-env-changed=DEBUG_GENERATED_CODE");
7883
println!("cargo:rerun-if-env-changed=TYPE_DEF_TMP_PATH");
7984
println!("cargo:rerun-if-env-changed=CARGO_CFG_NAPI_RS_CLI_VERSION");

scripts/native-builder.Dockerfile

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
# - Ubuntu 20.04 (glibc 2.31 — broad compatibility baseline)
1111
# - Clang/LLD for all compilation and linking via --target
1212
# - 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
1414
# - Node.js 20 (glibc-linked, used as build tool for all targets)
1515
# - Rust nightly toolchain (pinned to match rust-toolchain.toml)
1616
# - @napi-rs/cli for building native Node.js addons
1717

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+
1821
FROM ubuntu:20.04 AS builder
1922

2023
# Avoid interactive prompts during apt-get
@@ -54,19 +57,20 @@ RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certifi
5457
crossbuild-essential-amd64 crossbuild-essential-arm64 \
5558
&& rm -rf /var/lib/apt/lists/*
5659

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/
7074

7175
# Install Rust — pinned nightly from rust-toolchain.toml
7276
# The COPY of rust-toolchain.toml ensures the image rebuilds when the toolchain changes.

0 commit comments

Comments
 (0)