diff --git a/architecture/build.md b/architecture/build.md index 012a72d3f..74952ad36 100644 --- a/architecture/build.md +++ b/architecture/build.md @@ -61,7 +61,9 @@ Binary staging is driven by `tasks/scripts/stage-prebuilt-binaries.sh`. Gateway binaries use `cargo zigbuild` with GNU targets pinned to glibc 2.31, including native-architecture builds, so the gateway image, standalone tarballs, and Linux packages share the same host portability floor. Supervisor binaries remain -static musl. Local Docker image tasks infer the target architecture from +static musl and use `cargo zigbuild` when available, including native CPU +architectures, so C dependencies are compiled for the musl target instead of the +host GNU libc target. Local Docker image tasks infer the target architecture from `DOCKER_PLATFORM` when set, otherwise from the container engine host metadata with the kernel architecture as the fallback. CI invokes the same staging step via the `rust-native-build.yml` workflow (per-architecture, per-component) and diff --git a/tasks/scripts/stage-prebuilt-binaries.sh b/tasks/scripts/stage-prebuilt-binaries.sh index 130c47d27..a5436f896 100755 --- a/tasks/scripts/stage-prebuilt-binaries.sh +++ b/tasks/scripts/stage-prebuilt-binaries.sh @@ -52,6 +52,10 @@ host_os() { uname -s } +has_cargo_zigbuild() { + command -v cargo-zigbuild >/dev/null 2>&1 || mise which cargo-zigbuild >/dev/null 2>&1 +} + detect_arches() { if [[ -n "${PREBUILT_ARCH:-}" ]]; then normalize_arch "${PREBUILT_ARCH}" @@ -159,15 +163,17 @@ build_component_for_arch() { build_target="$target" if [[ "$component" == "gateway" ]]; then - if command -v cargo-zigbuild >/dev/null 2>&1 || mise which cargo-zigbuild >/dev/null 2>&1; then + if has_cargo_zigbuild; then cargo_subcommand=(cargo zigbuild) build_target="${target}.2.31" else echo "Error: cargo-zigbuild + zig are required to build ${binary} with the glibc 2.31 floor." >&2 exit 1 fi + elif [[ "$target_libc" == "musl" ]] && has_cargo_zigbuild; then + cargo_subcommand=(cargo zigbuild) elif [[ "$current_host_os" != "Linux" || "$current_host_arch" != "$arch" ]]; then - if command -v cargo-zigbuild >/dev/null 2>&1 || mise which cargo-zigbuild >/dev/null 2>&1; then + if has_cargo_zigbuild; then cargo_subcommand=(cargo zigbuild) else echo "Error: cannot build ${binary} for linux/${arch} on ${current_host_os}/${current_host_arch}." >&2