diff --git a/crates/hammer-build/src/lib.rs b/crates/hammer-build/src/lib.rs index fb17632a..31346510 100644 --- a/crates/hammer-build/src/lib.rs +++ b/crates/hammer-build/src/lib.rs @@ -345,21 +345,26 @@ fn resolve_phases(recipe: &Recipe, src: &Path) -> hammer_core::Result { // Dinámico: apaga crt-static para poder dlopen (necesita el loader/musl en el rootfs). LinkMode::Dynamic => "-C target-feature=-crt-static", }; - // `-C link-self-contained=no`: el link (de TODO — deps, build-scripts, - // proc-macros y la crate top) lo hace `zig cc`, que ya aporta sus startfiles - // (crt1.o). El target musl `x86_64-unknown-linux-musl` por defecto trae CRT - // AUTOCONTENIDO (self-contained/rcrt1.o) y lo pasaría también ⇒ `ld.lld: - // duplicate symbol: _start`. El rust de Alpine (host `x86_64-alpine-linux-musl`) - // ya tiene el self-contained APAGADO (de ahí que el baseline 9adefb82 linkee - // sin chocar), así que este flag es no-op para él e imprescindible para un rust - // vanilla (p. ej. el hammer-rust del frente self-host). RUSTFLAGS alcanza a - // todas las unidades; los `bin_flags` (cargo rustc --) sólo a la top. + // `-C link-self-contained=no` CONDICIONAL: el link (de TODO — deps, + // build-scripts, proc-macros y la crate top) lo hace `zig cc`, que ya aporta + // sus startfiles (crt1.o). Un rust VANILLA con target musl + // `x86_64-unknown-linux-musl` trae CRT AUTOCONTENIDO (self-contained/rcrt1.o) y + // lo pasaría también ⇒ `ld.lld: duplicate symbol: _start`; hay que apagarlo. PERO + // el rust de Alpine (host `x86_64-alpine-linux-musl`) PARCHEA la opción para que + // sea un ERROR ("option `-C link-self-contained` is not supported on this + // target") y NO usa self-contained — el baseline 9adefb82 linkea con zig sin + // chocar. Así que: añadir el flag SÓLO si el host del rustc NO es `-alpine-` + // (i.e. un rust vanilla como el hammer-rust del frente self-host); para Alpine, + // omitirlo. RUSTFLAGS alcanza a todas las unidades; los `bin_flags` (cargo rustc + // --) sólo a la top. Some(format!( "printf '%s\\n' '#!/bin/sh' 'for a do' \ 'case \"$a\" in --target=*) a=--target=x86_64-linux-musl ;; esac' \ 'set -- \"$@\" \"$a\"' 'shift' 'done' 'exec zig cc -mcpu=baseline \"$@\"' \ > \"$PWD/.hammer-zig-cc\" && chmod +x \"$PWD/.hammer-zig-cc\" && \ - CC=\"$PWD/.hammer-zig-cc\" RUSTFLAGS=\"-C linker=$PWD/.hammer-zig-cc -C link-self-contained=no\" \ + RF=\"-C linker=$PWD/.hammer-zig-cc\"; \ + rustc -vV | grep -q 'host: .*-alpine-' || RF=\"$RF -C link-self-contained=no\"; \ + CC=\"$PWD/.hammer-zig-cc\" RUSTFLAGS=\"$RF\" \ cargo rustc --release --locked --offline{flags_suffix} -- {bin_flags}" )) } else {