From 55cac99d081c16d61bab69339dc09970028f9150 Mon Sep 17 00:00:00 2001 From: bryan Date: Sun, 4 Oct 2026 15:52:28 -0700 Subject: [PATCH 1/2] rust: 1.98.1 -> 1.99.0, via a new rustc-1.98.1 bootstrap rung 1.99.0's src/stage0 pins 1.98.0; x.py's check_stage0_version accepts any 1.98.x (it compares major/minor only, verified in the 1.99.0 source), so the stage0 is a new rung rustc-1.98.1 -- a mechanical copy of the 1.97.1 rung (version, stage0, import, sha; bootstrap's VendorOutput is unchanged), built from the already-mirrored rustc-1.98.1-src by rustc-1.97.1. The earlier rungs are empty on arm64 and packages/rust took a hand-built rustc-1.97.1-aarch64 bedrock tarball. This rung instead BUILDS on arm64 from that same sha-pinned tarball, so rust 1.99 takes the 1.98.1 rung on both arches from the builder and no new hand-built prebuilt is needed. The 1.90..1.97.1 chain is unchanged and comes from the cache. rustc-1.99.0-src.tar.xz is mirrored (no-clobber), sha256 cc41916a... equal to static.rust-lang.org's published .sha256. Co-Authored-By: Claude Opus 5.5 --- packages/rust/build.ncl | 34 +- packages/rust/build.sh | 23 +- packages/rustc-1.98.1/README.md | 62 ++ packages/rustc-1.98.1/build.ncl | 100 ++++ packages/rustc-1.98.1/build.sh | 623 +++++++++++++++++++++ packages/rustc-1.98.1/gate_pm.rs | 13 + packages/rustc-1.98.1/gate_pm_use.rs | 23 + packages/rustc-1.98.1/gatelib.rs | 28 + packages/rustc-1.98.1/gatestd.rs | 153 +++++ packages/rustc-1.98.1/rustc-1.98.1.answers | 9 + 10 files changed, 1029 insertions(+), 39 deletions(-) create mode 100644 packages/rustc-1.98.1/README.md create mode 100644 packages/rustc-1.98.1/build.ncl create mode 100755 packages/rustc-1.98.1/build.sh create mode 100644 packages/rustc-1.98.1/gate_pm.rs create mode 100644 packages/rustc-1.98.1/gate_pm_use.rs create mode 100644 packages/rustc-1.98.1/gatelib.rs create mode 100644 packages/rustc-1.98.1/gatestd.rs create mode 100644 packages/rustc-1.98.1/rustc-1.98.1.answers diff --git a/packages/rust/build.ncl b/packages/rust/build.ncl index 8dd3f2cef..e2dfa6563 100644 --- a/packages/rust/build.ncl +++ b/packages/rust/build.ncl @@ -12,8 +12,8 @@ let libffi = import "../libffi/build.ncl" in let libssh2 = import "../libssh2/build.ncl" in let toolchain = import "../toolchain/build.ncl" in let gcc = import "../gcc/build.ncl" in -let rustc-1-97-1 = import "../rustc-1.97.1/build.ncl" in # the stage0 -let version = "1.98.1" in +let rustc-1-98-1 = import "../rustc-1.98.1/build.ncl" in # the stage0 +let version = "1.99.0" in { name = "rust", build_deps = @@ -22,7 +22,7 @@ let version = "1.98.1" in { file = "build.sh" } | Local, { url = "gs://minimal-staging-archives/rustc-%{version}-src.tar.xz", - sha256 = "be1816e7f6c40abb90245ad6e024bed2a7e88d7dda4561e4d5470207df616b9f", + sha256 = "cc41916a8c84f5d9ec4f55561b44e39f43b647b133f8a6f51be9ea13c83f7036", extract = true, strip_prefix = "rustc-%{version}-src", } | Source, @@ -35,28 +35,12 @@ let version = "1.98.1" in python, toolchain, ] - # stage0 = the rustc-1.97.1 rung (1.98.1's src/stage0 pins 1.97.1), built by the chain - # gcc-15.2.0 -> mrustc 0.12.0 -> rustc-1.90.0 -> 1.91.1 -> ... -> 1.97.1. amd64 takes the - # rung build_dep; arm64 takes a sha-pinned tarball of the same rung. build.sh injects it - # into bootstrap.toml [build] rustc/cargo; x.py never downloads a stage0. - @ ( - match { - { arch = 'Amd64, .. } => [rustc-1-97-1], - { arch = 'Arm64, .. } => - [ - # arm64 stage0: rustc-1.97.1 built by the same rung recipes on arm64 hardware. The - # tarball bundles the libLLVM.so.21.1 it links (built with all targets; the llvm - # package here omits experimental ones) and that library's non-glibc dependencies, - # each with an $ORIGIN RUNPATH. `extract = true` unpacks it to ./rustc-1.97.1-aarch64 - # inside the source root; build.sh points bootstrap.toml [build] rustc/cargo at it. - { - url = "gs://minimal-staging-archives/prebuilts/bedrock/sha256/de0724a4bf882c5f4641dc6edd6284ee0fa565a405d4ea264a4f305e3bfe5e6e/rustc-1.97.1-aarch64.tar.zst", - sha256 = "de0724a4bf882c5f4641dc6edd6284ee0fa565a405d4ea264a4f305e3bfe5e6e", - extract = true, - } | Source, - ], - } target - ), + # stage0 = the rustc-1.98.1 rung on BOTH arches (1.99.0's src/stage0 pins 1.98.0; x.py's + # check_stage0_version accepts any 1.98.x). amd64: built by the chain gcc-15.2.0 -> mrustc + # 0.12.0 -> rustc-1.90.0 -> ... -> 1.97.1 -> 1.98.1. arm64: the rung builds from the sha-pinned + # rustc-1.97.1 bedrock tarball, so no new hand-built prebuilt is needed. build.sh injects it into + # bootstrap.toml [build] rustc/cargo; x.py never downloads a stage0. + @ [rustc-1-98-1], # The build itself is offline (build.sh stubs curl/wget/git and fails on any attempt). The flags stay # because the builder grants a package network access when ANY of its dependencies declares it, and # the Rust programs that depend on this package still fetch their crates during their own builds. diff --git a/packages/rust/build.sh b/packages/rust/build.sh index a02c775ce..487a7c184 100755 --- a/packages/rust/build.sh +++ b/packages/rust/build.sh @@ -17,24 +17,19 @@ export CFLAGS="$MARCH -O2 -pipe -gno-record-gcc-switches -ffile-prefix-map=$(pwd export LDFLAGS="-Wl,--build-id=none" export CXXFLAGS="${CFLAGS}" -# stage0 = the rustc-1.97.1 rung (1.98.1's src/stage0 pins 1.97.1). amd64: the rung build_dep, -# hydrated read-only at /usr/lib/rustc-1.97.1. arm64: the sha-pinned tarball Source from -# build.ncl, extracted to ./rustc-1.97.1-aarch64 inside the source root. The stage0 is injected -# into bootstrap.toml [build] rustc/cargo below; x.py never downloads one, and a missing stage0 -# is fatal. -if [ "$(uname -m)" = aarch64 ]; then - STAGE0_PREFIX="$(pwd)/rustc-1.97.1-aarch64" -else - STAGE0_PREFIX=/usr/lib/rustc-1.97.1 -fi +# stage0 = the rustc-1.98.1 rung on both arches (1.99.0's src/stage0 pins 1.98.0; x.py accepts any +# 1.98.x), hydrated read-only at /usr/lib/rustc-1.98.1. The stage0 is injected into bootstrap.toml +# [build] rustc/cargo below; x.py never downloads one, and a missing stage0 fails the build. +STAGE0_PREFIX=/usr/lib/rustc-1.98.1 SEED_RUSTC="${STAGE0_PREFIX}/bin/rustc" SEED_CARGO="${STAGE0_PREFIX}/bin/cargo" -[ -x "$SEED_RUSTC" ] || { echo "rust: FATAL stage0 rustc missing at $SEED_RUSTC — the rustc-1.97.1 package is required" >&2; exit 1; } +[ -x "$SEED_RUSTC" ] || { echo "rust: FATAL stage0 rustc missing at $SEED_RUSTC — the rustc-1.98.1 package is required" >&2; exit 1; } [ -x "$SEED_CARGO" ] || { echo "rust: FATAL stage0 cargo missing at $SEED_CARGO" >&2; exit 1; } -# x.py checks the stage0 release against the src/stage0 pin; equal to the pin is accepted. +# x.py's check_stage0_version accepts the same or the previous MINOR (patch is not compared), so the +# 1.98.1 rung passes for 1.99.0's 1.98.0 pin. S0V="$("$SEED_RUSTC" --version 2>&1 || true)" -echo "$S0V" | grep -qF "1.97.1" || { echo "rust: FATAL stage0 rustc --version = '$S0V', expected 1.97.1" >&2; exit 1; } -echo "rust stage0: rustc-1.97.1 -> $S0V" +echo "$S0V" | grep -qF "1.98.1" || { echo "rust: FATAL stage0 rustc --version = '$S0V', expected 1.98.1" >&2; exit 1; } +echo "rust stage0: rustc-1.98.1 -> $S0V" # Drop the stage0's bundled rust-src: x.py compiles that stale copy of rustc_macros instead of the # in-tree source (E0433 on the renamed proc_macro::tracked_env API). The hydrated stage0 is diff --git a/packages/rustc-1.98.1/README.md b/packages/rustc-1.98.1/README.md new file mode 100644 index 000000000..273e8b7c2 --- /dev/null +++ b/packages/rustc-1.98.1/README.md @@ -0,0 +1,62 @@ +# packages/rustc-1.98.1 + +Builds rustc 1.98.1 (with cargo and std) from the upstream `rustc-1.98.1-src.tar.xz`, using the +`rustc-1.97.1` package as x.py's stage0, with no network access, and installs it to the private prefix +`/usr/lib/rustc-1.98.1` (`bin/`, `lib/` and `BUILDINFO` only). `packages/rust` consumes that prefix as its +stage0 the same way. + +## Stage0 wiring + +`build.sh` generates `bootstrap.toml` with `[build] rustc`/`cargo` pointing at +`/usr/lib/rustc-1.97.1/bin/{rustc,cargo}`, so x.py uses those binaries instead of downloading the +`src/stage0` snapshot. Before building it asserts the stage0 runs (`--version` contains 1.97.1, +`--print sysroot` equals the prefix) and that the extracted source is the right one +(`src/version` is 1.98.1 and `src/stage0` pins the stage0's version). + +## arm64 + +Unlike the earlier rungs (empty on arm64), this one BUILDS on arm64 too, so that `packages/rust` +1.99 can take a 1.98.1 stage0 on both arches from the builder instead of a new hand-built prebuilt. +Its arm64 stage0 is the same sha-pinned `rustc-1.97.1-aarch64` bedrock tarball `packages/rust` 1.98.1 +used, extracted to `${BUILDROOT}/rustc-1.97.1-aarch64`; amd64 is unchanged (the rustc-1.97.1 rung). + +## Offline mechanism + +- Crates: the source tarball ships `.cargo/config.toml` redirecting crates-io to its bundled `vendor/`. +- Stage0 download: disabled by the `[build] rustc`/`cargo` pins. +- LLVM: external `llvm-config = /usr/bin/llvm-config` (packages/llvm, LLVM 21) with `[llvm] link-shared`. +- `curl`/`wget`: stubs that exit non-zero and record a tripwire. `git`: a stub that allows local + read-only verbs and fails on network verbs. +- Vendored `curl-sys`/`libssh2-sys`: an empty `.git` marker in each bundled submodule dir keeps + their `build.rs` from running `git submodule update --init`. +- An ambient `.cargo/` above the build root fails the build, since cargo would merge it. + +## Gates (run on the installed binaries) + +1. `rustc --version` contains 1.98.1. +2. An rlib is emitted. +3. Ten std constructs compile and run; the exit code is their computed sum (42), each with its own failure code (111-120). +4. A proc-macro crate is built as a dylib, loaded and expanded by rustc, and the result runs (42). +5. cargo builds a proc-macro crate plus a `#[derive]` consumer offline, and the binary runs (42). +6. `bin/rustc` has a glibc interpreter and the network tripwire is still clean. + +## Files + +| file | role | +|---|---| +| `build.ncl` | spec: stage0 build_dep, source, system LLVM, one `OutputData` glob over `usr/lib/rustc-1.98.1/**`; empty on arm64 | +| `build.sh` | preconditions, offline stubs, submodule markers, `bootstrap.toml`, `x.py build`, install, gates, seal | +| `gatelib.rs`, `gatestd.rs`, `gate_pm.rs`, `gate_pm_use.rs` | readable copies of the gate sources heredoc'd in `build.sh` | +| `rustc-1.98.1.answers` | sha256 pins for `bin/rustc` and `bin/cargo`; none yet, so the seal check is skipped | + +Per-rung values: `VERSION`/`STAGE0_VERSION` in `build.sh`; `version`, `stage0_version`, the stage0 +import and the Source `sha256` in `build.ncl`; the `.answers` filename and its two pin paths. + +This rung's newer bootstrap needs four more things to stay offline, all in `build.sh`: +- it bootstraps from a copy of the stage0 with any bundled `rust-src` removed, since x.py would + otherwise compile pre-rename `proc_macro::tracked_env` code against it; +- `bootstrap.toml` sets `build.vendor = false`, `dist.vendor = false`, `dist.src-tarball = false`, + `rust.remap-debuginfo = false` and an explicit `tools` list without `src`; +- bootstrap's `vendor.rs` is patched to skip the generate-copyright vendoring when + `BOOTSTRAP_SKIP_VENDOR` is set (build tooling only, nothing shipped); +- `x.py install` names its components instead of installing everything. diff --git a/packages/rustc-1.98.1/build.ncl b/packages/rustc-1.98.1/build.ncl new file mode 100644 index 000000000..4942fe3f1 --- /dev/null +++ b/packages/rustc-1.98.1/build.ncl @@ -0,0 +1,100 @@ +let { subsetOf, Attrs, BuildSpec, Local, OutputData, Source, .. } = import "minimal.ncl" in +let { target, .. } = import "config.ncl" in +# rustc-1.98.1: builds rustc 1.98.1 from the upstream -src tarball with the rustc-1.97.1 package as +# x.py's stage0, strictly offline, installed to /usr/lib/rustc-1.98.1 (bin/ + lib/ only). +# packages/rust consumes this rung as its stage0. +# Same recipe as every rustc-1.9x rung: only version, stage0_version, the stage0 import and the +# Source sha256 differ in this file; VERSION and STAGE0_VERSION differ in build.sh. See README.md. +let rustc-1-97-1 = import "../rustc-1.97.1/build.ncl" in # the stage0 (amd64) +let base = import "../base/build.ncl" in +let cmake = import "../cmake/build.ncl" in +let curl = import "../curl/build.ncl" in +let llvm = import "../llvm/build.ncl" in +let openssl = import "../openssl/build.ncl" in +let pkgconf = import "../pkgconf/build.ncl" in +let python = import "../python/build.ncl" in +let sqlite = import "../sqlite/build.ncl" in +let libffi = import "../libffi/build.ncl" in +let libssh2 = import "../libssh2/build.ncl" in +let toolchain = import "../toolchain/build.ncl" in +let gcc = import "../gcc/build.ncl" in + +# pkgmgr: bootstrap_rung = "rust" +let version = "1.98.1" in +let stage0_version = "1.97.1" in +# stage0 by arch. amd64: the rustc-1.97.1 rung. arm64: the rung chain is amd64-only, so take the +# same sha-pinned rustc-1.97.1 bedrock tarball packages/rust 1.98.1 used; build.sh points at its +# extracted ./rustc-1.97.1-aarch64. This rung builds on BOTH arches so packages/rust 1.99 gets a +# 1.98.1 stage0 from the builder on arm64 too, with no new hand-built prebuilt. +let stage0 = + match { + { arch = 'Amd64, .. } => rustc-1-97-1, + { arch = 'Arm64, .. } => + { + url = "gs://minimal-staging-archives/prebuilts/bedrock/sha256/de0724a4bf882c5f4641dc6edd6284ee0fa565a405d4ea264a4f305e3bfe5e6e/rustc-1.97.1-aarch64.tar.zst", + sha256 = "de0724a4bf882c5f4641dc6edd6284ee0fa565a405d4ea264a4f305e3bfe5e6e", + extract = true, + } | Source, + } target +in +let spec = + { + name = "rustc-%{version}", + build_deps = [ + { file = "build.sh" } | Local, + { file = "rustc-1.98.1.answers" } | Local, # sha256 pins for the seal check in build.sh; unpinned today + # The -src tarball ships .cargo/config.toml (crates-io -> vendored-sources) and vendor/, so no + # cargo-vendor input is needed. build.sh asserts src/version and the src/stage0 pairing. + { + url = "gs://minimal-staging-archives/rustc-%{version}-src.tar.xz", + sha256 = "be1816e7f6c40abb90245ad6e024bed2a7e88d7dda4561e4d5470207df616b9f", + extract = true, + strip_prefix = "rustc-%{version}-src", + } | Source, + # stage0: the previous rung's installed prefix, /usr/lib/rustc-/bin/{rustc,cargo} + # + lib/rustlib//lib. build.sh pins bootstrap.toml [build] rustc/cargo at it. + stage0, + base, # userland; xz extracts the source + cmake, # some vendored -sys build scripts; also pulls in a real curl, shadowed by build.sh's stub + curl, # libcurl for curl-sys (pkg-config path or the marked vendored submodule) + libssh2, # LIBSSH2_SYS_USE_PKG_CONFIG=1 makes libssh2-sys use the system lib + pkgconf, # pkg-config for the -sys probes + python, # x.py + toolchain, # gcc/binutils/glibc/linux_headers: clang's sysroot + ], + runtime_deps = [ + libffi, + llvm, # clang, clang++, llvm-config and libLLVM-21.so; also present at build time + openssl, + sqlite, + subsetOf gcc ["libgcc", "libstdcpp"], + ], + # no `needs` block: the rung must be strictly offline. + + cmd = "./build.sh", + outputs = { + # One recursive OutputData glob over the private prefix: the toolchain is consumed as data by + # the next rung via absolute path and must not land on /usr/bin. build.sh prunes the prefix + # to bin/ + lib/ + BUILDINFO so nothing is left uncaptured. + toolchain = { glob = "usr/lib/rustc-%{version}/**", allow_executable = true } | OutputData, + }, + + attrs = + { + upstream_version = version, + license_spdx = "MIT OR Apache-2.0", + source_provenance = { + category = 'GithubRepo, + owner = "rust-lang", + repo = "rust", + }, + env_state_wiring = { + env_var = "CARGO_HOME", + prefix = "cargo", + }, + # system LLVM + clang, comparable to packages/rust + build_cost_multiple = 4, + } | Attrs, + } | BuildSpec +in +spec diff --git a/packages/rustc-1.98.1/build.sh b/packages/rustc-1.98.1/build.sh new file mode 100755 index 000000000..ad04be5b8 --- /dev/null +++ b/packages/rustc-1.98.1/build.sh @@ -0,0 +1,623 @@ +#!/bin/sh +# build.sh — builds rustc ${VERSION} from the rustc--src tarball with the previous rung's rustc +# as x.py's stage0 (a build_dep at /usr/lib/rustc-), fully offline, installed to the +# private prefix /usr/lib/rustc-. See build.ncl. +# phases: P0 preconditions, P0b offline stubs, P0c submodule markers, P1 bootstrap.toml, +# P2 x.py build, P3 install, P4 path sweep, P5 gates, P6 seal. +# VERSION and STAGE0_VERSION are the only per-rung values; STAGE0_PREFIX derives from them. +set -ex + +# Start from an empty OUTPUT_DIR: a failed earlier round's partial install would otherwise be +# swallowed by the capture globs. +if [ -n "$OUTPUT_DIR" ] && [ -d "$OUTPUT_DIR" ]; then + for _e in "$OUTPUT_DIR"/* "$OUTPUT_DIR"/.[!.]* "$OUTPUT_DIR"/..?*; do [ -e "$_e" ] || [ -L "$_e" ] && rm -r "$_e"; done +fi +mkdir -p "$OUTPUT_DIR" + +VERSION=1.98.1 +STAGE0_VERSION=1.97.1 +# The stage0 build_dep supplies the rustc for the host arch; MARCH dispatches on it below too. +case "$(uname -m)" in + x86_64) TRIPLE=x86_64-unknown-linux-gnu ;; + aarch64) TRIPLE=aarch64-unknown-linux-gnu ;; + *) echo "rustc: unsupported arch $(uname -m)" >&2; exit 1 ;; +esac + +BUILDROOT="$(pwd)" +PREFIX="/usr/lib/rustc-${VERSION}" # private versioned prefix, not /usr/bin +DST="${OUTPUT_DIR}${PREFIX}" # staged install location = ${DESTDIR}${prefix} + +# stage0 = the previous rung's installed prefix, consumed as a build_dep. The 1.90.0 rung is an +# mrustc build installed at /usr/lib/mrustc-rust-1.90.0; every later rung installs at /usr/lib/rustc-. +case "${STAGE0_VERSION}" in + 1.90.0) STAGE0_PREFIX="/usr/lib/mrustc-rust-${STAGE0_VERSION}" ;; # the mrustc rung + *) STAGE0_PREFIX="/usr/lib/rustc-${STAGE0_VERSION}" ;; # all later rungs +esac +# arm64: the rung chain is amd64-only, so the stage0 is the sha-pinned bedrock tarball of the +# previous rung (build.ncl), extracted into the build root -- the same one packages/rust 1.98.1 used. +if [ "$(uname -m)" = aarch64 ]; then + STAGE0_PREFIX="${BUILDROOT}/rustc-${STAGE0_VERSION}-aarch64" +fi +STAGE0_RUSTC="${STAGE0_PREFIX}/bin/rustc" # a POSIX-sh wrapper for 1.90.0, a real ELF later; both resolve --print sysroot in place +STAGE0_CARGO="${STAGE0_PREFIX}/bin/cargo" + +# A stage0 that ships a bundled rust-src (lib/rustlib/rustc-src) makes x.py resolve rustc_macros +# through it and compile pre-rename proc_macro::tracked_env code that the stage0's libproc_macro +# no longer exports (E0433). Bootstrap from a copy with that source stripped. +CLEAN0="${BUILDROOT}/stage0-clean" +rm -rf "${CLEAN0}" 2>/dev/null || true +cp -a "${STAGE0_PREFIX}" "${CLEAN0}" +rm -rf "${CLEAN0}/lib/rustlib/rustc-src" "${CLEAN0}/lib/rustlib/src" 2>/dev/null || true +STAGE0_PREFIX="${CLEAN0}" +STAGE0_RUSTC="${STAGE0_PREFIX}/bin/rustc" +STAGE0_CARGO="${STAGE0_PREFIX}/bin/cargo" + +JOBS="$(nproc 2>/dev/null || echo 4)" + +case "$(uname -m)" in + x86_64) MARCH="-march=x86-64-v3" ;; + aarch64) MARCH="-march=armv8-a" ;; + *) MARCH="" ;; +esac +# Same CFLAGS as packages/rust; -ffile-prefix-map keeps the build root out of C debug info. +export CFLAGS="${MARCH} -O2 -pipe -gno-record-gcc-switches -ffile-prefix-map=${BUILDROOT}=/builddir" +export CXXFLAGS="${CFLAGS}" +export LDFLAGS="-Wl,--build-id=none" +export LIBSQLITE3_SYS_USE_PKG_CONFIG=1 +export LIBSSH2_SYS_USE_PKG_CONFIG=1 + +# --- P0 preconditions: tools, LLVM major, the stage0 itself, the extracted source --- +for t in clang clang++ llvm-config ar ranlib python3 pkg-config cmake \ + find sed grep tar xz sha256sum readelf; do + command -v "${t}" >/dev/null 2>&1 || { echo "rustc: '${t}' not on PATH" >&2; exit 1; } +done + +LLVMVER="$(llvm-config --version 2>/dev/null || echo unknown)" +case "${LLVMVER}" in + 21.*) : ;; + *) echo "rustc: llvm-config --version = '${LLVMVER}', expected 21.x (rustc ${VERSION} targets LLVM 21)." >&2 + echo " A too-new/too-old external LLVM hard-errors at x.py configure. Refusing." >&2 + exit 1 ;; +esac + +# stage0 binaries from the previous rung +[ -x "${STAGE0_RUSTC}" ] || { echo "rustc: FATAL stage0 rustc missing at ${STAGE0_RUSTC} — the stage0 package is required" >&2; exit 1; } +[ -x "${STAGE0_CARGO}" ] || { echo "rustc: FATAL stage0 cargo missing at ${STAGE0_CARGO}" >&2; exit 1; } + +# The 1.90.0 stage0 reports `1.90.0-stable-mrustc`; later stage0s report a bare version, so this +# is a substring match. x.py's own stage0-version check runs early and fails fast anyway. +S0V="$("${STAGE0_RUSTC}" --version 2>&1 || true)" +echo "${S0V}" | grep -qF "${STAGE0_VERSION}" || { + echo "rustc: FATAL stage0 rustc --version = '${S0V}', expected to contain ${STAGE0_VERSION}" >&2; exit 1; } +# --print sysroot must resolve to the stage0 prefix: proves the stage0 runs in place and that its +# std is where x.py will look for it. +S0SR="$("${STAGE0_RUSTC}" --print sysroot 2>&1 || true)" +[ "${S0SR}" = "${STAGE0_PREFIX}" ] || { + echo "rustc: FATAL stage0 rustc --print sysroot = '${S0SR}', expected ${STAGE0_PREFIX}" >&2; exit 1; } +[ -d "${STAGE0_PREFIX}/lib/rustlib/${TRIPLE}/lib" ] || { + echo "rustc: FATAL stage0 std sysroot missing at ${STAGE0_PREFIX}/lib/rustlib/${TRIPLE}/lib" >&2; exit 1; } +"${STAGE0_CARGO}" --version >/dev/null 2>&1 || { echo "rustc: FATAL stage0 cargo did not execute" >&2; exit 1; } +echo "rustc STAGE0: stage0 OK — ${S0V} (sysroot ${S0SR})" >&2 + +# --- the extracted source must be the right one --- +# extract=true: the harness already unpacked and sha-verified the tarball, so assert the tree +# identity (version and bootstrap pairing) instead of re-hashing. +[ -f "${BUILDROOT}/x.py" ] || { echo "rustc: FATAL x.py absent — source not extracted to build root" >&2; exit 1; } +[ -d "${BUILDROOT}/vendor" ] || { echo "rustc: FATAL vendor/ absent — source is not the self-contained offline tarball" >&2; exit 1; } +[ -f "${BUILDROOT}/.cargo/config.toml" ] || { echo "rustc: FATAL .cargo/config.toml absent — the in-tree vendor redirect IS the offline mechanism" >&2; exit 1; } +grep -q 'vendored-sources' "${BUILDROOT}/.cargo/config.toml" || { + echo "rustc: FATAL .cargo/config.toml does not redirect crates-io to vendored-sources" >&2; exit 1; } +SVER="$(cat "${BUILDROOT}/src/version" 2>/dev/null || echo MISSING)" +[ "${SVER}" = "${VERSION}" ] || { echo "rustc: FATAL src/version = '${SVER}', expected ${VERSION} — wrong source extracted" >&2; exit 1; } +# x.py accepts a stage0 in the same minor or one minor behind, ignoring the patch level, and +# upstream pins the .0 of the prior minor; assert the minor line, not the exact patch. +STAGE0_MINOR="${STAGE0_VERSION%.*}" # e.g. 1.91.1 -> 1.91 +grep -qE "compiler_version=${STAGE0_MINOR}\.[0-9]+" "${BUILDROOT}/src/stage0" || { + echo "rustc: FATAL src/stage0 compiler_version not in the ${STAGE0_MINOR}.x line (our stage0 is ${STAGE0_VERSION}) — wrong bootstrap pairing" >&2 + grep -i 'compiler_' "${BUILDROOT}/src/stage0" >&2 || true + exit 1; } +S0PIN="$(grep -oE 'compiler_version=[0-9.]+' "${BUILDROOT}/src/stage0" | head -1)" +echo "rustc SOURCE: OK — src/version=${SVER}, src/stage0 ${S0PIN} matches our stage0 ${STAGE0_VERSION} minor line (x.py minor-rule)" >&2 + +# --- P0b offline harness --- +# curl/wget stubs exit non-zero: the build must fail if x.py or a build.rs tries the network. +# A real curl is in the rootfs (pulled in by cmake), so the stub's PATH precedence is asserted. +# git stub: local read-only verbs exit 1 (x.py's version stamp and a few vendored build.rs probe +# them and handle failure); network-capable and unknown verbs are tripwires. +STUBS="${BUILDROOT}/stubs"; mkdir -p "${STUBS}" +for t in curl wget; do + cat > "${STUBS}/${t}" <> "${BUILDROOT}/NETWORK-TRIPWIRE" +echo "rustc: FATAL — the build invoked '${t}', which must never happen offline" >&2 +exit 1 +EOF + chmod 0755 "${STUBS}/${t}" +done + +cat > "${STUBS}/git" <> "${BUILDROOT}/GIT-LOCAL.log"; echo "git version 0.0.0-bedrock-stub"; exit 0 +fi +case "\$1" in + rev-parse|log|describe|symbolic-ref|show-ref|rev-list|cat-file|status|diff|show|name-rev|for-each-ref|update-index|config) + echo "git \$*" >> "${BUILDROOT}/GIT-LOCAL.log"; exit 1 ;; # local read-only; no network + clone|fetch|pull|push|remote|ls-remote|submodule|archive|request-pull|send-pack|fetch-pack|upload-pack) + echo "git \$*" >> "${BUILDROOT}/NETWORK-TRIPWIRE" + echo "rustc: FATAL — git NETWORK verb attempted: \$*" >&2; exit 1 ;; + *) + # unknown verb: default deny, so a new network path cannot slip through + echo "git \$*" >> "${BUILDROOT}/NETWORK-TRIPWIRE" + echo "rustc: FATAL — git invoked with an un-allowlisted verb (default-deny): \$*" >&2; exit 1 ;; +esac +EOF +chmod 0755 "${STUBS}/git" + +PATH="${STUBS}:${PATH}"; export PATH +[ "$(command -v curl)" = "${STUBS}/curl" ] || { + echo "rustc: FATAL the curl stub is NOT shadowing the real curl (packages/cmake pulls one in)." >&2 + echo " command -v curl = $(command -v curl)" >&2; exit 1; } +[ "$(command -v git)" = "${STUBS}/git" ] || { echo "rustc: FATAL the git stub is NOT first on PATH" >&2; exit 1; } + +export CARGO_NET_OFFLINE=true +export GIT_CEILING_DIRECTORIES="${BUILDROOT}" +export GIT_CONFIG_NOSYSTEM=1 +export GIT_TERMINAL_PROMPT=0 + +# cargo merges every .cargo/config[.toml] from the build root up to /; one planted above the +# build root could override [source.crates-io] and re-enable the network. Fail shut. +d="${BUILDROOT}" +while [ "${d}" != "/" ] && [ -n "${d}" ]; do + # the source's own .cargo at ${BUILDROOT} is the vendor redirect; anything above it is the hazard + if [ "${d}" != "${BUILDROOT}" ] && [ -e "${d}/.cargo" ]; then + echo "rustc: FATAL ambient .cargo/ found at ${d} — cargo would merge it and could re-enable the network" >&2; exit 1 + fi + d="$(dirname "${d}")" +done +[ -e "/.cargo" ] && { echo "rustc: FATAL ambient /.cargo/ present" >&2; exit 1; } +unset d + +# The stage0 rustc's default linker is the literal `cc`. x.py passes -C linker=clang from +# bootstrap.toml, but alias cc/c++ to clang for any tool that shells `cc` directly. +ln -sf "$(command -v clang)" "${STUBS}/cc" +ln -sf "$(command -v clang++)" "${STUBS}/c++" +command -v cc >/dev/null 2>&1 || { echo "rustc: FATAL cc alias not on PATH" >&2; exit 1; } + +# --- P0c vendored submodule markers --- +# curl-sys and libssh2-sys build.rs check for a `.git` marker in their bundled submodule dir and, +# absent one (release tarballs ship none), run `git submodule update --init`, which the git stub +# fail-shuts. An empty `.git` marker makes build.rs compile the sources shipped in the tarball. +# Checksum-safe: cargo's DirectorySource::verify checks only the files listed in +# .cargo-checksum.json, so an extra unlisted file is not detected. Never edit a vendored file. +# The dirs are globbed (the -sys crate versions change per rung) and only populated ones are +# marked; marking an empty checkout would make the crate try to compile nothing. +# libgit2-sys is not marked: its guard keys on libgit2/src, which the tarball ships. +marked=0 +for pat in "curl-sys-*/curl" "libssh2-sys-*/libssh2"; do + # shellcheck disable=SC2231 # intentional glob on ${pat} + for d in "${BUILDROOT}"/vendor/${pat}; do + [ -d "${d}" ] || continue + # a populated submodule dir has entries; an empty checkout has none + n="$(find "${d}" -mindepth 1 -maxdepth 1 ! -name .git 2>/dev/null | head -1 | wc -l | tr -d ' ')" + if [ "${n}" -lt 1 ]; then + echo "rustc SUBMOD: NOTE ${d#"${BUILDROOT}"/} ships no sources; NOT marking (expecting the pkg-config path)" >&2 + continue + fi + if [ ! -e "${d}/.git" ]; then + : > "${d}/.git" + marked=$((marked + 1)) + echo "rustc SUBMOD: marked ${d#"${BUILDROOT}"/}/.git" >&2 + fi + done +done +echo "rustc SUBMOD: ${marked} vendored submodule marker(s) placed" >&2 +# Diagnostic (non-fatal): whether pkg-config sees the system libs, so the log shows which path +# curl-sys/libssh2-sys will take if a marker was skipped. +for lib in libcurl libssh2; do + if pkg-config --exists "${lib}" 2>/dev/null; then + echo "rustc SUBMOD: pkg-config sees ${lib} $(pkg-config --modversion "${lib}" 2>/dev/null)" >&2 + else + echo "rustc SUBMOD: NOTE pkg-config does NOT see ${lib} — the crate MUST use its vendored submodule (marker required above)" >&2 + fi +done + +# --- P1 bootstrap.toml --- +# The tarball ships only bootstrap.example.toml, so the config is generated in full. Same shape +# as packages/rust/bootstrap.toml, with [build] rustc/cargo pinned at the stage0 and [install] +# prefix set to the private versioned path. +cat > "${BUILDROOT}/bootstrap.toml" <&2; exit 1; } +echo "rustc CONFIG: bootstrap.toml generated (stage0 pinned, prefix ${PREFIX})" >&2 + +# --- P2 x.py build --- +# Offline is structural: the in-tree .cargo vendor redirect, the stage0 pin (no stage0 download), +# external llvm-config (no LLVM download) and P0c's markers. CARGO_NET_OFFLINE is belt-and-braces. +# cwd is BUILDROOT so ./x.py finds bootstrap.toml. Do not export RUSTC_BOOTSTRAP: x.py sets it +# per invocation and a global value interferes. +# Neutralize bootstrap's Vendor step: the install-time generate-copyright Vendor step is a default +# step no [dist]/[build] flag suppresses, and offline it fails ("no matching package named +# serde_core"). Gate it behind an env flag with an early return before the Command is built +# (bootstrap panics on a constructed-but-unexecuted Command). This patches build tooling only. +VENDOR_RS=src/bootstrap/src/core/build_steps/vendor.rs +grep -q 'BOOTSTRAP_SKIP_VENDOR' "$VENDOR_RS" || { + sed -i 's|let _guard = builder.group(&format!("Vendoring sources|if std::env::var_os("BOOTSTRAP_SKIP_VENDOR").is_some() { return VendorOutput { config: String::new(), config_library: String::new() }; }\n let _guard = builder.group(\&format!("Vendoring sources|' "$VENDOR_RS" + grep -q 'BOOTSTRAP_SKIP_VENDOR' "$VENDOR_RS" || { echo "rustc: FATAL vendor.rs early-return patch did not apply" >&2; exit 1; } +} +export BOOTSTRAP_SKIP_VENDOR=1 + +./x.py build -j "${JOBS}" + +# --- offline tripwire, checkpoint 1 (after the build, before install) --- +if [ -e "${BUILDROOT}/NETWORK-TRIPWIRE" ]; then + echo "rustc: FATAL the build attempted a network fetch:" >&2; cat "${BUILDROOT}/NETWORK-TRIPWIRE" >&2; exit 1 +fi +[ -e "${BUILDROOT}/GIT-LOCAL.log" ] && { + echo "rustc OFFLINE: NOTE — permitted local git probes occurred (harmless, no network verb):" >&2 + sort -u "${BUILDROOT}/GIT-LOCAL.log" >&2; } +echo "rustc OFFLINE: PASS (no curl/wget, no network-capable git verb, during the build)" >&2 + +# --- P3 install --- +# DESTDIR is prepended to every written path but baked into no file; `prefix` is the logical path +# baked into the toolchain, so files land at ${DST} while baked references say ${PREFIX}. +# Explicit components: a bare `x.py install` reaches the Src component's dist steps regardless of +# the [build] tools list. +DESTDIR="${OUTPUT_DIR}" ./x.py install library/std compiler/rustc cargo clippy rustfmt rust-analyzer + +[ -x "${DST}/bin/rustc" ] || { echo "rustc: FATAL install produced no ${DST}/bin/rustc" >&2; exit 1; } +[ -x "${DST}/bin/cargo" ] || { echo "rustc: FATAL install produced no ${DST}/bin/cargo (extended=true should install it)" >&2; exit 1; } +[ -d "${DST}/lib/rustlib/${TRIPLE}/lib" ] || { echo "rustc: FATAL installed std sysroot missing at ${DST}/lib/rustlib/${TRIPLE}/lib" >&2; exit 1; } +ls "${DST}"/lib/librustc_driver*.so >/dev/null 2>&1 || { echo "rustc: FATAL librustc_driver*.so missing from ${DST}/lib" >&2; exit 1; } + +# rust-gdbgui is a shell script with a re-rooted path; packages/rust drops it too. +rm -f "${DST}/bin/rust-gdbgui" +# The next rung needs only bin/{rustc,cargo} + lib/; pruning keeps the single output glob's +# coverage complete (no share/man/doc/libexec left uncaptured). +rm -rf "${DST}/share" "${DST}/libexec" "${DST}/etc" + +echo "rustc INSTALL: layout below (bin/ + lib/ only):" >&2 +ls -la "${DST}" >&2 || true + +cat > "${DST}/BUILDINFO" </dev/null || true)" +if [ -n "${hits_b}" ]; then + echo "rustc SWEEP: NOTE — build-root (source) paths present in installed TEXT files (review, not fatal):" >&2 + echo "${hits_b}" >&2 +else + echo "rustc SWEEP: clean of build-root paths" >&2 +fi +hits_o="$(find "${DST}" -type f -exec grep -I -l -F "${OUTPUT_DIR}" {} + 2>/dev/null || true)" +if [ -n "${hits_o}" ]; then + echo "rustc SWEEP: ⚠ WARNING — DESTDIR STAGING paths (${OUTPUT_DIR}) baked into installed TEXT files." >&2 + echo " This is a RELOCATION DEFECT — the next rung's stage0 would carry a dead path." >&2 + echo " Non-fatal; must be fixed before sealing:" >&2 + echo "${hits_o}" >&2 +else + echo "rustc SWEEP: clean of staging paths (relocatable)" >&2 +fi + +# --- P5 gates: run the installed binaries from ${OUTPUT_DIR}, after install --- +# GATE-3 runs ten std constructs whose exit code is their computed sum (42), never a literal. +# GATE-4/5 build and load a proc-macro (directly, then via cargo): the next rung's x.py is +# cargo-driven and derive-heavy, so a rustc that cannot dlopen a proc-macro must fail here. +# The gate sources are heredoc'd inline so the recipe is self-contained; the gate*.rs files in +# this directory are readable copies of the same bodies. Every gated command is rc-captured +# because `set -e` would abort before the named assert. +RUSTC="${DST}/bin/rustc" +CARGO="${DST}/bin/cargo" +RLIB="${DST}/lib/rustlib/${TRIPLE}/lib" +G="${BUILDROOT}/gate"; mkdir -p "${G}" + +# --- GATE-1: identity (not a functional gate) --- +# channel="stable" gives a bare `rustc (...)` with no suffix. +set +e; RV="$("${RUSTC}" --version 2>&1)"; rc=$?; set -e +[ ${rc} -eq 0 ] || { echo "rustc GATE-1: FAIL (installed rustc did not execute, rc=${rc}) — ${RV}" >&2; exit 1; } +echo "${RV}" | grep -qF "${VERSION}" || { + echo "rustc GATE-1: FAIL — rustc --version = '${RV}', expected to contain '${VERSION}'" >&2; exit 1; } +echo "rustc GATE-1: PASS (identity ${RV})" >&2 + +# --- GATE-2: rlib production + cross-crate read-back --- +cat > "${G}/gatelib.rs" <<'RSEOF' +pub trait Shape { fn area(&self) -> i64; } +pub struct Sq(pub i64); +impl Shape for Sq { fn area(&self) -> i64 { self.0 * self.0 } } +/// wrapping arithmetic so the result is a computed value, not a constant. +pub fn checksum(v: &[i64]) -> i64 { + let mut acc: i64 = 7; + for x in v { acc = acc.wrapping_mul(31).wrapping_add(*x); } + acc +} +RSEOF +set +e +( cd "${G}" && "${RUSTC}" --crate-type=rlib --crate-name=gatelib -L "${RLIB}" gatelib.rs -o libgatelib.rlib ) >"${G}/g2.log" 2>&1 +rc=$?; set -e +[ ${rc} -eq 0 ] && [ -s "${G}/libgatelib.rlib" ] || { + echo "rustc GATE-2: FAIL (rc=${rc}) — could not emit an rlib." >&2; tail -40 "${G}/g2.log" >&2 || true; exit 1; } +echo "rustc GATE-2: PASS (emitted a non-empty rlib)" >&2 + +# --- GATE-3: ten std constructs, compiled and executed, computed sum == 42 --- +# Each construct exits with its own code (111-120) so a failure names the miscompiled path. +# c4 dispatches across the crate boundary into GATE-2's rlib, proving it was read back. +cat > "${G}/gatestd.rs" <<'RSEOF' +extern crate gatelib; +use std::collections::{BTreeMap, HashMap}; +use std::sync::{Arc, Mutex}; +use gatelib::{Shape, Sq}; +fn c6_inner(s: &str) -> Result { + let n: i64 = s.parse()?; + let doubled = Some(n).map(|v| v + 3).unwrap_or(0); + Ok(doubled) +} +fn main() { + // 111: Vec + iterator adaptors + heap + let squares: Vec = (1..=10i64).filter(|n| n % 2 == 1).map(|n| n * n).collect(); + let s: i64 = squares.iter().sum(); + if s != 165 { std::process::exit(111); } + let c1 = s / 33; // 5 + // 112: core::fmt + String + str::parse round-trip + let hex = format!("{:04x}", 29); + let back: i64 = format!("{}", s).parse().unwrap_or(-1); + if hex != "001d" || back != 165 { std::process::exit(112); } + let c2 = hex.len() as i64; // 4 + // 113: BTreeMap ordering + HashMap hashing (RandomState -> OS entropy) + let mut bt: BTreeMap = BTreeMap::new(); + bt.insert(30, "c"); bt.insert(10, "a"); bt.insert(20, "b"); + let ordered: Vec = bt.keys().cloned().collect(); + let mut hm: HashMap<&str, i64> = HashMap::new(); + hm.insert("a", 1); hm.insert("b", 2); hm.insert("c", 3); + if ordered != vec![10, 20, 30] || hm.get("b") != Some(&2) || hm.len() != 3 { std::process::exit(113); } + let c3 = bt.len() as i64; // 3 + // 114: cross-crate Box vtable dispatch into the rlib + let shapes: Vec> = vec![Box::new(Sq(5)), Box::new(Sq(2))]; + let area: i64 = shapes.iter().map(|sh| sh.area()).sum(); + let ck = gatelib::checksum(&[1, 2, 3]); + if area != 29 || ck != 209_563 { std::process::exit(114); } + let c4 = shapes[0].area() / 5; // 5 + // 115: generics + FnMut capture + fn apply(times: i64, mut f: F) { for i in 0..times { f(i); } } + let mut counter: i64 = 0; + apply(4, |_| counter += 2); + if counter != 8 { std::process::exit(115); } + let c5 = counter / 2; // 4 + // 116: Result + `?` + Option combinators + let r = c6_inner("14"); + let bad = c6_inner("not-a-number"); + if r != Ok(17) || bad.is_ok() { std::process::exit(116); } + let c6 = r.unwrap() % 14; // 3 + // 117: catch_unwind — unwinding through panic_unwind + let prev = std::panic::take_hook(); + std::panic::set_hook(Box::new(|_| {})); + let caught = std::panic::catch_unwind(|| { panic!("boomba"); }); + std::panic::set_hook(prev); + let plen = match caught { + Ok(_) => std::process::exit(117), + Err(e) => match e.downcast_ref::<&str>() { Some(msg) => msg.len() as i64, None => std::process::exit(117) }, + }; + if plen != 6 { std::process::exit(117); } + let c7 = plen; // 6 + // 118: checked/wrapping overflow semantics + if i64::max_value().checked_add(1).is_some() { std::process::exit(118); } + let w: u8 = 250u8.wrapping_add(10); + if w != 4 { std::process::exit(118); } + let c8 = w as i64; // 4 + // 119: f64 format + parse round-trip + let f: f64 = "2.5".parse().unwrap_or(0.0); + let prod = f * 1.6; + if format!("{:.1}", prod) != "4.0" { std::process::exit(119); } + let c9 = prod as i64; // 4 + // 120: threads + join + Arc> (pthreads, TLS, atomics) + let shared = Arc::new(Mutex::new(0i64)); + let mut handles = Vec::new(); + for _ in 0..4 { + let h = Arc::clone(&shared); + handles.push(std::thread::spawn(move || { let mut g = h.lock().unwrap(); *g += 1; })); + } + for h in handles { let joined = h.join(); if joined.is_err() { std::process::exit(120); } } + let threaded = *shared.lock().unwrap(); + if threaded != 4 { std::process::exit(120); } + let c10 = threaded; // 4 + // 5+4+3+5+4+3+6+4+4+4 == 42, computed, never a literal. + let total = c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9 + c10; + std::process::exit(total as i32); +} +RSEOF +set +e +( cd "${G}" && "${RUSTC}" -L "${RLIB}" --extern gatelib="${G}/libgatelib.rlib" gatestd.rs -o gatestd ) >"${G}/g3-compile.log" 2>&1 +rc=$?; set -e +[ ${rc} -eq 0 ] || { echo "rustc GATE-3: FAIL (rc=${rc}) — could not compile the gate program:" >&2; tail -60 "${G}/g3-compile.log" >&2 || true; exit 1; } +set +e; "${G}/gatestd"; rc=$?; set -e +case ${rc} in + 42) : ;; + 111) echo "rustc GATE-3: FAIL — iterator/closure/heap" >&2; exit 1 ;; + 112) echo "rustc GATE-3: FAIL — core::fmt / parse round-trip" >&2; exit 1 ;; + 113) echo "rustc GATE-3: FAIL — BTreeMap/HashMap" >&2; exit 1 ;; + 114) echo "rustc GATE-3: FAIL — CROSS-CRATE vtable dispatch into the rlib" >&2; exit 1 ;; + 115) echo "rustc GATE-3: FAIL — generics + FnMut capture" >&2; exit 1 ;; + 116) echo "rustc GATE-3: FAIL — Result + '?' + Option" >&2; exit 1 ;; + 117) echo "rustc GATE-3: FAIL — catch_unwind / UNWINDING" >&2; exit 1 ;; + 118) echo "rustc GATE-3: FAIL — checked/wrapping overflow" >&2; exit 1 ;; + 119) echo "rustc GATE-3: FAIL — f64 round-trip" >&2; exit 1 ;; + 120) echo "rustc GATE-3: FAIL — threads + Arc" >&2; exit 1 ;; + 139) echo "rustc GATE-3: FAIL — SIGSEGV (rc=139). Suspect an rlib/dylib std ABI mismatch." >&2; exit 1 ;; + 126|127) echo "rustc GATE-3: FAIL — rc=${rc}: bad interpreter or missing DSO (loader/rpath)" >&2; exit 1 ;; + *) echo "rustc GATE-3: FAIL — gate binary exited ${rc}, expected the computed 42" >&2; exit 1 ;; +esac +echo "rustc GATE-3: PASS (ten std constructs compiled, linked and RAN; computed 42)" >&2 + +# --- GATE-4: proc-macro built as a dylib, loaded, expanded, run -> computed 42 --- +cat > "${G}/gate_pm.rs" <<'RSEOF' +extern crate proc_macro; +use proc_macro::TokenStream; +#[proc_macro_derive(GateVal)] +pub fn gate_val(_input: TokenStream) -> TokenStream { + // 13 is produced inside the proc-macro dylib and checked by the consumer. + "impl Target { fn val(&self) -> i64 { 13 } }".parse().unwrap() +} +RSEOF +cat > "${G}/gate_pm_use.rs" <<'RSEOF' +#[macro_use] +extern crate gate_pm; +#[derive(GateVal)] +struct Target; +fn main() { + let t = Target; + let v = t.val(); // exists only because the proc macro ran + if v != 13 { std::process::exit(121); } + std::process::exit((v * 3 + 3) as i32); // 42, computed +} +RSEOF +set +e +( cd "${G}" && "${RUSTC}" --crate-type=proc-macro --crate-name=gate_pm -L "${RLIB}" gate_pm.rs -o libgate_pm.so ) >"${G}/g4-pm.log" 2>&1 +rc=$?; set -e +if [ ${rc} -ne 0 ]; then + echo "rustc GATE-4: FAIL (rc=${rc}) — could not build a proc-macro crate; this rustc cannot serve as the next rung's stage0 (x.py needs proc-macros)." >&2 + ls -la "${RLIB}" | grep -i proc_macro >&2 || echo " (no proc_macro artifact in ${RLIB})" >&2 + tail -40 "${G}/g4-pm.log" >&2 || true; exit 1 +fi +set +e +( cd "${G}" && "${RUSTC}" -L "${RLIB}" --extern gate_pm="${G}/libgate_pm.so" gate_pm_use.rs -o gate_pm_use ) >"${G}/g4-use.log" 2>&1 +rc=$?; set -e +[ ${rc} -eq 0 ] || { echo "rustc GATE-4: FAIL (rc=${rc}) — rustc could not LOAD and EXPAND the proc macro:" >&2; tail -40 "${G}/g4-use.log" >&2 || true; exit 1; } +set +e; "${G}/gate_pm_use"; rc=$?; set -e +[ ${rc} -eq 42 ] || { echo "rustc GATE-4: FAIL — proc-macro consumer exited ${rc}, expected 42" >&2; [ ${rc} -eq 121 ] && echo " (121 = macro expanded but produced the wrong value)" >&2; exit 1; } +echo "rustc GATE-4: PASS (proc-macro crate built as a dylib, dlopen'd, expanded, and RAN)" >&2 + +# --- GATE-5: cargo drives a build of a proc-macro crate + a #[derive] consumer -> 42 --- +# Zero registry deps, so no vendor dir or network is involved. +CW="${G}/cargows" +mkdir -p "${CW}/pmderive/src" "${CW}/app/src" +cat > "${CW}/pmderive/Cargo.toml" <<'EOF' +[workspace] +[package] +name = "pmderive" +version = "0.0.0" +edition = "2015" +[lib] +proc-macro = true +EOF +cat > "${CW}/pmderive/src/lib.rs" <<'RSEOF' +extern crate proc_macro; +use proc_macro::TokenStream; +#[proc_macro_derive(GateVal)] +pub fn gate_val(_input: TokenStream) -> TokenStream { + "impl Target { fn val(&self) -> i64 { 13 } }".parse().unwrap() +} +RSEOF +cat > "${CW}/app/Cargo.toml" <<'EOF' +# an explicit [workspace] makes this app its own root, so cargo does not adopt a stray Cargo.toml above the build dir +[workspace] +[package] +name = "gateapp" +version = "0.0.0" +edition = "2015" +[dependencies] +pmderive = { path = "../pmderive" } +EOF +cat > "${CW}/app/src/main.rs" <<'RSEOF' +#[macro_use] +extern crate pmderive; +#[derive(GateVal)] +struct Target; +fn main() { + let t = Target; + let v = t.val(); + if v != 13 { std::process::exit(121); } + std::process::exit((v * 3 + 3) as i32); // 42, computed +} +RSEOF +set +e +( cd "${CW}/app" && CARGO_HOME="${CW}/home" RUSTC="${RUSTC}" \ + "${CARGO}" build --offline --release --target-dir "${CW}/target" ) >"${G}/g5.log" 2>&1 +rc=$?; set -e +[ ${rc} -eq 0 ] || { echo "rustc GATE-5: FAIL (rc=${rc}) — cargo could not drive a proc-macro + derive build:" >&2; tail -50 "${G}/g5.log" >&2 || true; exit 1; } +set +e; "${CW}/target/release/gateapp"; rc=$?; set -e +[ ${rc} -eq 42 ] || { echo "rustc GATE-5: FAIL — cargo-built binary exited ${rc}, expected 42" >&2; exit 1; } +echo "rustc GATE-5: PASS (cargo built a proc-macro crate + a #[derive] consumer, and the binary RAN; computed 42)" >&2 + +# --- GATE-6: glibc interpreter + offline re-assert --- +INTERP="$(readelf -l "${DST}/bin/rustc" 2>/dev/null | grep -o '/[^]]*ld-linux[^]]*' | head -1 || true)" +case "${INTERP}" in + */ld-linux-*) echo "rustc GATE-6: rustc interp = ${INTERP}" >&2 ;; + *) echo "rustc GATE-6: FAIL — rustc has no recognizable glibc interpreter (got '${INTERP}')" >&2; exit 1 ;; +esac +if [ -e "${BUILDROOT}/NETWORK-TRIPWIRE" ]; then + echo "rustc: FATAL a network fetch was attempted during the gate phase:" >&2; cat "${BUILDROOT}/NETWORK-TRIPWIRE" >&2; exit 1 +fi +echo "rustc GATE-6: PASS (glibc interp; network tripwire clean after all gates)" >&2 + +# --- P6 seal --- +# If rustc-${VERSION}.answers carries sha256 pins, the installed bin/rustc and bin/cargo must +# match them; with no pins the check is skipped. Sealing is a data edit to the .answers file. +ANS="${BUILDROOT}/rustc-${VERSION}.answers" +if [ -f "${ANS}" ] && grep -Eq '^[0-9a-f]{64} ' "${ANS}"; then + if ( cd "${OUTPUT_DIR}" && sha256sum -c "${ANS}" ); then + echo "rustc SEAL: PASS (byte-identical to the pinned answers)" >&2 + else + echo "rustc SEAL: FAIL (output drifted from rustc-${VERSION}.answers)" >&2; exit 1 + fi +else + echo "rustc SEAL: no pins present; seal not checked" >&2 +fi + +echo "rustc: ALL GATES PASSED — rustc ${VERSION} installed at ${PREFIX}, ready as the next rung's stage0." >&2 diff --git a/packages/rustc-1.98.1/gate_pm.rs b/packages/rustc-1.98.1/gate_pm.rs new file mode 100644 index 000000000..8af08a17a --- /dev/null +++ b/packages/rustc-1.98.1/gate_pm.rs @@ -0,0 +1,13 @@ +// gate_pm.rs — GATE-4a. Compiled with `--crate-type=proc-macro`, so the installed rustc must +// produce a host dylib that gate_pm_use.rs then loads and executes at compile time. +// Readable copy of the body build.sh embeds as a heredoc; keep the two in sync. + +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[proc_macro_derive(GateVal)] +pub fn gate_val(_input: TokenStream) -> TokenStream { + // 13 is produced inside the dylib that rustc loaded and ran, and is checked by the consumer. + "impl Target { fn val(&self) -> i64 { 13 } }".parse().unwrap() +} diff --git a/packages/rustc-1.98.1/gate_pm_use.rs b/packages/rustc-1.98.1/gate_pm_use.rs new file mode 100644 index 000000000..b4edbb47c --- /dev/null +++ b/packages/rustc-1.98.1/gate_pm_use.rs @@ -0,0 +1,23 @@ +// gate_pm_use.rs — GATE-4b. Consumes the proc-macro dylib built from gate_pm.rs: compiling it +// makes the installed rustc load and execute that dylib; running it checks the expansion. +// Readable copy of the body build.sh embeds as a heredoc; keep the two in sync. +// Edition 2015 (no --edition is passed), so `#[macro_use] extern crate` brings the derive in. + +#[macro_use] +extern crate gate_pm; + +#[derive(GateVal)] +struct Target; + +fn main() { + let t = Target; + // val() exists only because the proc macro ran; without expansion this file does not compile. + let v = t.val(); + if v != 13 { + // expanded, but to the wrong value: reported separately from a load failure + std::process::exit(121); + } + // 42 is computed from the macro-produced value, never a literal. + let total = v * 3 + 3; + std::process::exit(total as i32); +} diff --git a/packages/rustc-1.98.1/gatelib.rs b/packages/rustc-1.98.1/gatelib.rs new file mode 100644 index 000000000..79fe08ee2 --- /dev/null +++ b/packages/rustc-1.98.1/gatelib.rs @@ -0,0 +1,28 @@ +// gatelib.rs — GATE-2's crate, compiled with `--crate-type=rlib`. +// Readable copy of the body build.sh embeds as a heredoc; keep the two in sync. Edition-2015 +// Rust, identical across every rung. +// Emitting an rlib exercises the archive builder, which a single-binary gate never touches. +// gatestd.rs then consumes it across a crate boundary, proving the archive is read back and that +// vtable layout survives the boundary. + +pub trait Shape { + fn area(&self) -> i64; +} + +pub struct Sq(pub i64); + +impl Shape for Sq { + fn area(&self) -> i64 { + self.0 * self.0 + } +} + +/// A cheap rolling checksum with wrapping arithmetic, so the result is a computed value with +/// defined overflow behaviour rather than a constant. +pub fn checksum(v: &[i64]) -> i64 { + let mut acc: i64 = 7; + for x in v { + acc = acc.wrapping_mul(31).wrapping_add(*x); + } + acc +} diff --git a/packages/rustc-1.98.1/gatestd.rs b/packages/rustc-1.98.1/gatestd.rs new file mode 100644 index 000000000..94c012191 --- /dev/null +++ b/packages/rustc-1.98.1/gatestd.rs @@ -0,0 +1,153 @@ +// gatestd.rs — GATE-3, the functional gate for this rung's rustc. +// Readable copy of the body build.sh embeds as a heredoc; keep the two in sync. Edition-2015 +// Rust, identical across every rung. +// The pass value 42 is never written in the success path: it is the sum of ten independently +// computed quantities, so a compiler that miscompiled `!=`/`==` into a constant cannot produce it. +// Each check also exits with its own code (111-120) so a failure names the miscompiled construct. +// Edition 2015 (no --edition is passed), so `extern crate` is required. + +extern crate gatelib; + +use std::collections::{BTreeMap, HashMap}; +use std::sync::{Arc, Mutex}; + +use gatelib::{Shape, Sq}; + +fn c6_inner(s: &str) -> Result { + let n: i64 = s.parse()?; + let doubled = Some(n).map(|v| v + 3).unwrap_or(0); + Ok(doubled) +} + +fn main() { + // --- 111: Vec + iterator adaptors (map/filter/sum), heap allocation, monomorphisation --- + let squares: Vec = (1..=10i64).filter(|n| n % 2 == 1).map(|n| n * n).collect(); + let s: i64 = squares.iter().sum(); // 1+9+25+49+81 + if s != 165 { + std::process::exit(111); + } + let c1 = s / 33; // 5 + + // --- 112: core::fmt + String + str::parse round-trip --- + let hex = format!("{:04x}", 29); // "001d" + let back: i64 = format!("{}", s).parse().unwrap_or(-1); + if hex != "001d" || back != 165 { + std::process::exit(112); + } + let c2 = hex.len() as i64; // 4 + + // --- 113: BTreeMap ordering + HashMap hashing (RandomState -> OS entropy) --- + let mut bt: BTreeMap = BTreeMap::new(); + bt.insert(30, "c"); + bt.insert(10, "a"); + bt.insert(20, "b"); + let ordered: Vec = bt.keys().cloned().collect(); + let mut hm: HashMap<&str, i64> = HashMap::new(); + hm.insert("a", 1); + hm.insert("b", 2); + hm.insert("c", 3); + if ordered != vec![10, 20, 30] || hm.get("b") != Some(&2) || hm.len() != 3 { + std::process::exit(113); + } + let c3 = bt.len() as i64; // 3 + + // --- 114: cross-crate Box vtable dispatch into the rlib from GATE-2 --- + // proves the archive was read back, not just written + let shapes: Vec> = vec![Box::new(Sq(5)), Box::new(Sq(2))]; + let area: i64 = shapes.iter().map(|sh| sh.area()).sum(); // 25 + 4 + let ck = gatelib::checksum(&[1, 2, 3]); // ((7*31+1)*31+2)*31+3 == 209563 + if area != 29 || ck != 209_563 { + std::process::exit(114); + } + let c4 = shapes[0].area() / 5; // 5 + + // --- 115: generics + FnMut closure capture --- + fn apply(times: i64, mut f: F) { + for i in 0..times { + f(i); + } + } + let mut counter: i64 = 0; + apply(4, |_| counter += 2); + if counter != 8 { + std::process::exit(115); + } + let c5 = counter / 2; // 4 + + // --- 116: Result + `?` + Option combinators --- + let r = c6_inner("14"); + let bad = c6_inner("not-a-number"); // hoisted out of the guard, see the note at 120 + if r != Ok(17) || bad.is_ok() { + std::process::exit(116); + } + let c6 = r.unwrap() % 14; // 3 + + // --- 117: catch_unwind — unwinding through panic_unwind --- + let prev = std::panic::take_hook(); + std::panic::set_hook(Box::new(|_| {})); // keep the build log clean + let caught = std::panic::catch_unwind(|| { + panic!("boomba"); + }); + std::panic::set_hook(prev); + let plen = match caught { + Ok(_) => { + // the panic did not unwind at all + std::process::exit(117); + } + Err(e) => match e.downcast_ref::<&str>() { + Some(msg) => msg.len() as i64, // 6 + None => std::process::exit(117), + }, + }; + if plen != 6 { + std::process::exit(117); + } + let c7 = plen; // 6 + + // --- 118: checked_add / wrapping_add — overflow semantics --- + if i64::max_value().checked_add(1).is_some() { + std::process::exit(118); + } + let w: u8 = 250u8.wrapping_add(10); // 4 + if w != 4 { + std::process::exit(118); + } + let c8 = w as i64; // 4 + + // --- 119: f64 format + parse round-trip --- + let f: f64 = "2.5".parse().unwrap_or(0.0); + let prod = f * 1.6; // 4.0 + if format!("{:.1}", prod) != "4.0" { + std::process::exit(119); + } + let c9 = prod as i64; // 4 + + // --- 120: thread::spawn + join + Arc> — pthreads, TLS, atomics --- + let shared = Arc::new(Mutex::new(0i64)); + let mut handles = Vec::new(); + for _ in 0..4 { + let h = Arc::clone(&shared); + handles.push(std::thread::spawn(move || { + let mut g = h.lock().unwrap(); + *g += 1; + })); + } + for h in handles { + // join() is called unconditionally and its result bound before being tested: a + // side-effecting call inside the guard condition would make the accumulated value depend + // on the guard executing, which defeats the non-vacuity argument. + let joined = h.join(); + if joined.is_err() { + std::process::exit(120); + } + } + let threaded = *shared.lock().unwrap(); + if threaded != 4 { + std::process::exit(120); + } + let c10 = threaded; // 4 + + // 5 + 4 + 3 + 5 + 4 + 3 + 6 + 4 + 4 + 4 == 42, computed, never a literal. + let total = c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9 + c10; + std::process::exit(total as i32); +} diff --git a/packages/rustc-1.98.1/rustc-1.98.1.answers b/packages/rustc-1.98.1/rustc-1.98.1.answers new file mode 100644 index 000000000..99ca2e1da --- /dev/null +++ b/packages/rustc-1.98.1/rustc-1.98.1.answers @@ -0,0 +1,9 @@ +# rustc-1.98.1.answers — byte-seal pins for packages/rustc-1.98.1, in `sha256sum` format. +# build.sh P6 runs `sha256sum -c` on this file from ${OUTPUT_DIR} when it contains a `<64 hex> ` +# line; with none present the seal is skipped. To arm: add `{ file = "rustc-1.98.1.answers" } | Local` +# to build.ncl's build_deps and paste the two sums below, uncommented. +# Pin only bin/rustc and bin/cargo; lib/rustlib/** is covered transitively by them. +# +# UNPINNED +# usr/lib/rustc-1.98.1/bin/rustc +# usr/lib/rustc-1.98.1/bin/cargo From 3adbc7c81ad2c52bde80a295848c43be92f0f9d1 Mon Sep 17 00:00:00 2001 From: bryan Date: Sun, 4 Oct 2026 16:23:05 -0700 Subject: [PATCH 2/2] rust 1.99.0: drop build.compiletest-use-stage0-libtest (removed upstream) x.py 1.99.0 rejects it ("unknown field ... for key build"). Its own change tracker: "compiletest is now always built with the stage 0 compiler, so build.compiletest-use-stage0-libtest has no effect" (146929), then "Obsolete option ... has been removed" (159878). Every other key in bootstrap.toml was checked against the 1.99.0 config parser and is still accepted. The rustc-1.98.1 rung itself built on both arches in the failed run (rust reported "stage0: rustc-1.98.1" on amd64 and arm64). Co-Authored-By: Claude Opus 5.5 --- packages/rust/bootstrap.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/rust/bootstrap.toml b/packages/rust/bootstrap.toml index 7996b1239..116294185 100644 --- a/packages/rust/bootstrap.toml +++ b/packages/rust/bootstrap.toml @@ -15,8 +15,6 @@ extended = true # No "src": the rust-src install step is gated on `extended && tools.contains("src")`, and a # bundled rust-src is what x.py would compile instead of the in-tree source. tools = ["cargo", "clippy", "rustfmt", "rust-analyzer"] -# Use libtest built from the source tree instead of the precompiled one from stage 0. -compiletest-use-stage0-libtest = false docs = false