From 9f7e75901bb269b2d525ec48c531b17345f24345 Mon Sep 17 00:00:00 2001 From: sergio Date: Tue, 16 Jun 2026 22:50:10 -0400 Subject: [PATCH] =?UTF-8?q?hammer-build:=20-C=20link-self-contained=3Dno?= =?UTF-8?q?=20CONDICIONAL=20(Alpine=20rechaza=20la=20opci=C3=B3n)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix de 503e09a, que añadía el flag SIEMPRE: el rust de Alpine (host x86_64-alpine-linux- musl) NO sólo tiene self-contained apagado — PARCHEA la opción para que sea un error ("option `-C link-self-contained` is not supported on this target"), así que pasarla rompía el build baseline (verificado: baseline-check falló en el build-script de proc-macro2). Un rust vanilla (host x86_64-unknown-linux-musl, p. ej. hammer-rust) SÍ la soporta y la NECESITA (su musl trae self-contained/rcrt1.o que choca con el crt1.o de zig ⇒ duplicate _start). Ahora condicional por host-triple del rustc: se añade el flag SÓLO si el host NO es `-alpine-`. Para Alpine ⇒ comando idéntico al pre-503e09a (sin flag) ⇒ 9adefb82 intacto por construcción. Para hammer-rust ⇒ con flag ⇒ linkea con zig sin duplicar _start. (`--print`/`--version` no validan -C; sólo el link real lo hace — por eso se discrimina por host-triple, no por probe.) Co-Authored-By: Claude Opus 4.8 --- crates/hammer-build/src/lib.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) 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 {