Commit 8d8b9e57 authored by Matt Mastracci's avatar Matt Mastracci

Address review feedback: ICF in config.toml, nodesource for Node.js

- Add --icf=all to Windows config (already uses rust-lld)
- Replace multi-stage node:20-slim copy with nodesource apt repo install
- Simplify Dockerfile (single stage, no COPY --from)
parent 0fc85e0a
......@@ -51,9 +51,10 @@ rustflags = ["-Clink-arg=--icf=all"]
# Windows: statically link the CRT and opt into rust-lld for fast linking.
# rust-lld is not yet the default on Windows (tracking: rust-lang/rust#71520).
# ICF (Identical Code Folding) reduces binary size with negligible build time impact.
[target.'cfg(windows)']
linker = "rust-lld"
rustflags = ["-Ctarget-feature=+crt-static"]
rustflags = ["-Ctarget-feature=+crt-static", "-Clink-arg=-Wl,--icf=all"]
# Musl targets: disable static CRT linking. We produce dynamic .node shared
# libraries (N-API addons), not static binaries.
......
......@@ -18,10 +18,9 @@ set -xeo pipefail
BUILD_TASK="${BUILD_TASK:-build-native-release}"
# Node.js is used only as a build tool (runs npm/napi-cli). The glibc-linked
# node works for all targets — the output .node file's linking is determined
# Node.js (installed via nodesource) is used only as a build tool (runs
# npm/napi-cli). The output .node shared library's linking is determined
# by cargo's --target, not the node binary.
export PATH="/opt/node-gnu/bin:${PATH}"
# --- RUSTFLAGS via cargo-rustflags ---
# We use `linker=clang` + `linker-flavor=gnu-lld-cc` rather than
......
......@@ -15,18 +15,6 @@
# - Rust nightly toolchain (pinned to match rust-toolchain.toml)
# - @napi-rs/cli for building native Node.js addons
# ---------------------------------------------------------------------------
# Stage 1: Extract glibc-linked Node.js binary + headers
# ---------------------------------------------------------------------------
FROM node:20-slim AS node-gnu
RUN mkdir -p /out && \
cp -r /usr/local/bin /out/bin && \
cp -r /usr/local/include /out/include && \
cp -r /usr/local/lib /out/lib
# ---------------------------------------------------------------------------
# Stage 2: Builder image
# ---------------------------------------------------------------------------
FROM ubuntu:20.04 AS builder
# Avoid interactive prompts during apt-get
......@@ -54,11 +42,13 @@ RUN HOST_ARCH=$(dpkg --print-architecture) && \
"deb [arch=${FOREIGN_ARCH}] ${FOREIGN_MIRROR} focal-security main universe" \
> /etc/apt/sources.list
# Core build tools + GNU cross-compilation sysroots.
# Core build tools + GNU cross-compilation sysroots + Node.js 20 via nodesource.
# crossbuild-essential installs headers + libs in the multiarch layout
# that clang finds via --target. Both archs installed so the image
# works on either host architecture.
RUN apt-get update && apt-get install -y --no-install-recommends \
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get update && apt-get install -y --no-install-recommends \
nodejs \
clang lld llvm pkg-config curl wget git ca-certificates xz-utils \
crossbuild-essential-amd64 crossbuild-essential-arm64 \
&& rm -rf /var/lib/apt/lists/*
......@@ -77,13 +67,6 @@ RUN cd /opt && \
/opt/${TRIPLE}-cross/${TRIPLE}/lib/; \
done
# Copy Node.js from multi-stage build. We use the glibc-linked node for ALL
# targets — node is just a build tool (runs npm/napi-cli), and the output
# .node shared library's linking is determined by cargo's --target, not the
# node binary. N-API is ABI-stable across glibc and musl.
COPY --from=node-gnu /out /opt/node-gnu
ENV PATH="/opt/node-gnu/bin:${PATH}"
# Install Rust — pinned nightly from rust-toolchain.toml
# The COPY of rust-toolchain.toml ensures the image rebuilds when the toolchain changes.
COPY rust-toolchain.toml /tmp/rust-toolchain.toml
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment