sergio/takana
> Una distribución Linux construida con un laboratorio funcional y hermético en el > sótano, y una terminal mutable, clásica y anárquica en el piso de arriba — diseñada > desde el suelo para que una IA programadora entienda, modifique y co…
⎇ fb71aca4be05bd7fb4d62a68cebca8dbee209a81
scripts/rust-frontier/swap-rust-into-toolchain.sh
Historia
crudo
selfhost-verify: swap rust hammer-built 1.91.1 en /toolchain (SWAP_RUST, auto-consistencia)
1#!/usr/bin/env bash
2# swap-rust-into-toolchain.sh — overlay the hammer-built rust 1.91.1 onto a toolchain
3# dir (default .dev-fs/alpine), so `hammer build` / `bootstrap stage1` compile the
4# 4/4 rust inputs (arje-zero, hammerd) with hammer-rust instead of Alpine's rustc.
5#
6# This is the rust tool-swap of the selfhost-verify "variante b". Unlike make/bwrap/…
7# (tools that orchestrate/copy → identical bytes), **rustc emits the 4/4 binaries**, so
8# a hammer-built rustc produces a DIFFERENT of_tree than Alpine's 9adefb82. Success
9# criterion is therefore AUTO-CONSISTENCY: stage1' built with hammer-rust == stage1''
10# rebuilt with hammer-rust (a NEW EXPECT_REF), not byte-identity with the Alpine baseline.
11#
12# The overlay is mostly ADDITIVE and fully reversible:
13# - hammer's rustc/cargo use host triple x86_64-unknown-linux-musl and hash-suffixed
14# .so names that DON'T collide with Alpine's (x86_64-alpine-linux-musl / other
15# hashes), so the new rustlib triple + librustc_driver just sit alongside Alpine's.
16# - only /usr/bin/{rustc,cargo} are REPLACED; the originals are backed up to
17# usr/bin/<name>.alpine so `--restore` can put them back.
18# The 4/4 rust recipes build NATIVE (target x86_64-linux-musl == SANDBOX_NATIVE_TARGET
19# ⇒ no --target, see hammer-build/src/lib.rs:269), so hammer-rustc compiles them for
20# its OWN native triple x86_64-unknown-linux-musl.
21#
22# Usage:
23# swap-rust-into-toolchain.sh [--prefix DIR] [--toolchain DIR] # apply the swap
24# swap-rust-into-toolchain.sh --restore [--toolchain DIR] # undo it
25set -euo pipefail
26ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
27PREFIX="$ROOT/.scratch/rust-1.91.1-prefix"
28TOOLCHAIN="$ROOT/.dev-fs/alpine"
29RESTORE=0
30while [ $# -gt 0 ]; do
31 case "$1" in
32 --prefix) PREFIX="$2"; shift 2 ;;
33 --toolchain) TOOLCHAIN="$2"; shift 2 ;;
34 --restore) RESTORE=1; shift ;;
35 *) echo "uso: $0 [--prefix DIR] [--toolchain DIR] [--restore]" >&2; exit 2 ;;
36 esac
37done
38
39say() { printf '\033[1;36m==> %s\033[0m\n' "$*"; }
40die() { printf '\033[1;31mERROR: %s\033[0m\n' "$*" >&2; exit 1; }
41
42[ -d "$TOOLCHAIN/usr/bin" ] || die "no veo el toolchain en $TOOLCHAIN"
43
44if [ "$RESTORE" = 1 ]; then
45 say "restaurar el rust de Alpine en $TOOLCHAIN"
46 for b in rustc cargo; do
47 if [ -f "$TOOLCHAIN/usr/bin/$b.alpine" ]; then
48 mv -f "$TOOLCHAIN/usr/bin/$b.alpine" "$TOOLCHAIN/usr/bin/$b"
49 echo " restaurado usr/bin/$b"
50 else
51 echo " (sin backup de usr/bin/$b — ¿ya restaurado?)"
52 fi
53 done
54 echo " (los .so y el rustlib x86_64-unknown-linux-musl añadidos quedan; son inertes — el rustc de Alpine no los usa)"
55 exit 0
56fi
57
58[ -x "$PREFIX/bin/rustc" ] || die "no veo el prefix hammer-rust en $PREFIX (corré el climb primero)"
59
60say "swap: overlay hammer-rust 1.91.1 ($PREFIX) → $TOOLCHAIN"
61
62# 1) librustc_driver de hammer (hash único, no choca con el de Alpine).
63cp -a "$PREFIX"/lib/librustc_driver-*.so "$TOOLCHAIN/usr/lib/"
64echo " + usr/lib/$(basename "$PREFIX"/lib/librustc_driver-*.so)"
65
66# 2) sysroot de hammer para su triple nativo (dir nuevo, no choca con x86_64-alpine-linux-musl).
67rm -rf "$TOOLCHAIN/usr/lib/rustlib/x86_64-unknown-linux-musl"
68cp -a "$PREFIX/lib/rustlib/x86_64-unknown-linux-musl" "$TOOLCHAIN/usr/lib/rustlib/"
69echo " + usr/lib/rustlib/x86_64-unknown-linux-musl ($(du -sh "$PREFIX/lib/rustlib/x86_64-unknown-linux-musl" | cut -f1))"
70
71# 3) reemplazar rustc y cargo (backup de los de Alpine).
72for b in rustc cargo; do
73 [ -f "$TOOLCHAIN/usr/bin/$b.alpine" ] || cp -a "$TOOLCHAIN/usr/bin/$b" "$TOOLCHAIN/usr/bin/$b.alpine"
74 cp -a "$PREFIX/bin/$b" "$TOOLCHAIN/usr/bin/$b"
75 echo " ~ usr/bin/$b (Alpine guardado en usr/bin/$b.alpine)"
76done
77
78say "listo. verificá con: bwrap --bind $TOOLCHAIN / ... /usr/bin/rustc --version"
79echo " esperado: rustc 1.91.1 (ed61e7d7e …) host x86_64-unknown-linux-musl"
80echo " deshacer: $0 --restore --toolchain $TOOLCHAIN"