tawasuyu

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…

TOML 1506Shell 193Rust 108Markdown 983676 Definitions

⎇ 040d174bbe1f4c91e918280d182d2397783b6725 scripts/rust-frontier/swap-rust-into-toolchain.sh Shell · 91 lines · 4.6 KB History raw

selfhost-verify: RUST_EXPECT_REF=7fa6cb4e + swap --restore deja el toolchain prístino 5549330c9 · sergio ·

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    # Quitar también lo AÑADIDO por el swap: el librustc_driver de hammer (hash propio, distinto del
55    # de Alpine) y el sysroot del triple x86_64-unknown-linux-musl (un devfs Alpine prístino NO los
56    # tiene). Inertes para el rustc de Alpine, pero dejarlos es ~350 MB de cruft y deja el toolchain
57    # no-prístino; lo limpiamos para que --restore sea reversibilidad total.
58    rm -rf "$TOOLCHAIN/usr/lib/rustlib/x86_64-unknown-linux-musl"
59    # Sólo los librustc_driver que NO son de Alpine (Alpine deja exactamente uno; el swap añadió otro).
60    if [ -d "$PREFIX/lib" ]; then
61        for so in "$PREFIX"/lib/librustc_driver-*.so; do
62            [ -e "$so" ] && rm -f "$TOOLCHAIN/usr/lib/$(basename "$so")"
63        done
64    fi
65    echo "    limpiado usr/lib/rustlib/x86_64-unknown-linux-musl + librustc_driver de hammer"
66    exit 0
67fi
68
69[ -x "$PREFIX/bin/rustc" ] || die "no veo el prefix hammer-rust en $PREFIX (corré el climb primero)"
70
71say "swap: overlay hammer-rust 1.91.1 ($PREFIX) → $TOOLCHAIN"
72
73# 1) librustc_driver de hammer (hash único, no choca con el de Alpine).
74cp -a "$PREFIX"/lib/librustc_driver-*.so "$TOOLCHAIN/usr/lib/"
75echo "    + usr/lib/$(basename "$PREFIX"/lib/librustc_driver-*.so)"
76
77# 2) sysroot de hammer para su triple nativo (dir nuevo, no choca con x86_64-alpine-linux-musl).
78rm -rf "$TOOLCHAIN/usr/lib/rustlib/x86_64-unknown-linux-musl"
79cp -a "$PREFIX/lib/rustlib/x86_64-unknown-linux-musl" "$TOOLCHAIN/usr/lib/rustlib/"
80echo "    + usr/lib/rustlib/x86_64-unknown-linux-musl ($(du -sh "$PREFIX/lib/rustlib/x86_64-unknown-linux-musl" | cut -f1))"
81
82# 3) reemplazar rustc y cargo (backup de los de Alpine).
83for b in rustc cargo; do
84    [ -f "$TOOLCHAIN/usr/bin/$b.alpine" ] || cp -a "$TOOLCHAIN/usr/bin/$b" "$TOOLCHAIN/usr/bin/$b.alpine"
85    cp -a "$PREFIX/bin/$b" "$TOOLCHAIN/usr/bin/$b"
86    echo "    ~ usr/bin/$b  (Alpine guardado en usr/bin/$b.alpine)"
87done
88
89say "listo. verificá con:  bwrap --bind $TOOLCHAIN / ... /usr/bin/rustc --version"
90echo "    esperado: rustc 1.91.1 (ed61e7d7e …) host x86_64-unknown-linux-musl"
91echo "    deshacer: $0 --restore --toolchain $TOOLCHAIN"