boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

commit 060023ae36abcbc5aad2e62383201b9ef0f3834c
parent 4891b5e0b39db967260da5742589a3e6bfab01f5
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Wed, 29 Apr 2026 20:22:17 -0700

vendor: drop ../ reaches into sibling repos

Previously stage1-flatten.sh and friends read the upstream tcc tarball
from ../lb-work/distfiles/, mes/include from ../mes/include/, and
live-bootstrap's tcc simple-patches from ../live-bootstrap/...; the
build silently broke if a developer didn't have those siblings checked
out at exactly those paths. Move what the main `make tcc-boot2` chain
needs in-tree:

- vendor/upstream/tcc-0.9.26.tar.gz (was ../lb-work/distfiles/)
- scripts/simple-patches/tcc-0.9.26-lb/ (was ../live-bootstrap/steps/
  tcc-0.9.26/simple-patches/) — sits next to scripts/simple-patches/
  tcc-0.9.26/ (our own patches) for parity.

stage1-flatten.sh already used vendor/mes-libc/include (byte-identical
to ../mes/include), so the mes-include reach is gone too. Also picks
up the va_list -I addition for vendor/boot2-include from the previous
commit.

The three scripts that legitimately need external data — they're
diagnostics or opt-in dev helpers, not part of the bootstrap chain —
now require an explicit env var, no implicit ../ fallback:

- scripts/stage2-alpine.sh: legacy gcc-driven path the cc.scm chain
  replaces; needs mes-0.27.1.tar.gz. Set LIVE_BOOTSTRAP=<path> or
  MES_TAR=<path>.
- scripts/build-native-tools.sh: dev-loop helper compiling host-native
  M1/hex2 from mescc-tools. Set LIVE_BOOTSTRAP=<path> or
  MESCC_TOOLS_SRC=<path>.
- scripts/diag-livebootstrap-qemu.sh: diagnostic comparing against
  live-bootstrap's pipeline. Set LIVE_BOOTSTRAP=<path>.

After this commit, the repo's build path (everything under `make`)
is fully in-tree.

Diffstat:
Mscripts/build-native-tools.sh | 23++++++++++++++---------
Mscripts/diag-livebootstrap-qemu.sh | 26++++++++++++++++----------
Ascripts/simple-patches/tcc-0.9.26-lb/addback-fileopen.after | 7+++++++
Ascripts/simple-patches/tcc-0.9.26-lb/addback-fileopen.before | 1+
Ascripts/simple-patches/tcc-0.9.26-lb/remove-fileopen.after | 2++
Ascripts/simple-patches/tcc-0.9.26-lb/remove-fileopen.before | 8++++++++
Mscripts/stage1-flatten.sh | 20+++++++++++++++++---
Mscripts/stage2-alpine.sh | 14++++++++++++--
Avendor/upstream/tcc-0.9.26.tar.gz | 0
9 files changed, 77 insertions(+), 24 deletions(-)

diff --git a/scripts/build-native-tools.sh b/scripts/build-native-tools.sh @@ -9,9 +9,13 @@ ## m1pp — built from M1pp/M1pp.c (the C oracle) ## ## Source lookup for M1/hex2 (first match wins): -## 1. $MESCC_TOOLS_SRC (if set) -## 2. ../live-bootstrap/seed/stage0-posix/mescc-tools -## 3. ../mescc-tools +## 1. $MESCC_TOOLS_SRC (direct override) +## 2. $LIVE_BOOTSTRAP/seed/stage0-posix/mescc-tools +## +## No in-tree vendor copy — these tools are dev-loop helpers (the +## bootstrap path uses our seed/stage0 hex builds), so we keep the +## external dep explicit. Set LIVE_BOOTSTRAP=<path> the same way +## scripts/diag-livebootstrap-qemu.sh does. ## ## Usage: scripts/build-native-tools.sh <M1|hex2|m1pp> @@ -38,17 +42,18 @@ find_mescc_src() { echo "build-native-tools.sh: MESCC_TOOLS_SRC=$MESCC_TOOLS_SRC is not a complete mescc-tools tree" >&2 return 1 fi - for d in \ - "$REPO/../live-bootstrap/seed/stage0-posix/mescc-tools" \ - "$REPO/../mescc-tools" - do + if [ -n "${LIVE_BOOTSTRAP:-}" ]; then + d=$LIVE_BOOTSTRAP/seed/stage0-posix/mescc-tools if [ -f "$d/M1-macro.c" ] && [ -f "$d/M2libc/bootstrappable.c" ]; then echo "$d" return 0 fi - done + echo "build-native-tools.sh: LIVE_BOOTSTRAP=$LIVE_BOOTSTRAP has no mescc-tools at $d" >&2 + return 1 + fi echo "build-native-tools.sh: no mescc-tools source found." >&2 - echo " set MESCC_TOOLS_SRC to a directory containing M1-macro.c and M2libc/," >&2 + echo " set MESCC_TOOLS_SRC=<dir-with-M1-macro.c-and-M2libc/>," >&2 + echo " or LIVE_BOOTSTRAP=<live-bootstrap-checkout>," >&2 echo " or fall back to the bootstrap path with M1PP_BOOTSTRAP_TOOLS=1." >&2 return 1 } diff --git a/scripts/diag-livebootstrap-qemu.sh b/scripts/diag-livebootstrap-qemu.sh @@ -22,12 +22,18 @@ ## (32-bit) path with QEMU and accept the arch mismatch. ## ## Setup (host): -## - Distfiles at lb-work/distfiles. Currently we have -## mes-0.27.1.tar.gz, nyacc-1.00.2-lb1.tar.gz, tcc-0.9.26.tar.gz -## The diagnostic also needs tcc-0.9.27.tar.bz2; this script -## fetches it via curl on first run if missing. Stage0-posix tools -## (M2-Planet, mescc-tools, etc.) are bundled in -## ../live-bootstrap/seed/stage0-posix and don't need distfiles. +## - LIVE_BOOTSTRAP=<path>: required env var pointing at a working +## live-bootstrap checkout. Distfiles are taken from +## $LIVE_BOOTSTRAP/../lb-work/distfiles (the sibling layout +## live-bootstrap's own scripts produce). The diagnostic also +## needs tcc-0.9.27.tar.bz2; this script fetches it via curl on +## first run if missing. Stage0-posix tools (M2-Planet, +## mescc-tools, etc.) are bundled in +## $LIVE_BOOTSTRAP/seed/stage0-posix and don't need distfiles. +## +## The script has no implicit `../live-bootstrap` lookup — the rest +## of the build is in-tree, and this diagnostic is the sole script +## that needs the upstream tree, so make the dependency explicit. ## ## Pipeline: ## 1. (host) populate distfiles (curl tcc-0.9.27 if needed) @@ -52,14 +58,14 @@ set -eu ROOT=$(cd "$(dirname "$0")/.." && pwd) -BOOTSTRAP_ROOT=$(cd "$ROOT/.." && pwd) -LB=$BOOTSTRAP_ROOT/live-bootstrap -DISTFILES=$BOOTSTRAP_ROOT/lb-work/distfiles +: "${LIVE_BOOTSTRAP:?set LIVE_BOOTSTRAP=<path-to-live-bootstrap-checkout>}" +LB=$(cd "$LIVE_BOOTSTRAP" && pwd) +DISTFILES=${LB_DISTFILES:-$LB/../lb-work/distfiles} WORK=$ROOT/build/diag-livebootstrap ROOTFS=$WORK/rootfs [ -d "$LB" ] || { echo "missing live-bootstrap at $LB" >&2; exit 1; } -[ -d "$DISTFILES" ] || { echo "missing distfiles at $DISTFILES" >&2; exit 1; } +[ -d "$DISTFILES" ] || { echo "missing distfiles at $DISTFILES (override with LB_DISTFILES=<path>)" >&2; exit 1; } command -v podman >/dev/null 2>&1 || { echo "podman required" >&2; exit 2; } # --- (1) ensure distfiles populated ---------------------------------- diff --git a/scripts/simple-patches/tcc-0.9.26-lb/addback-fileopen.after b/scripts/simple-patches/tcc-0.9.26-lb/addback-fileopen.after @@ -0,0 +1,7 @@ + if ((fh = fopen(argv[i_lib], "wb")) == NULL) + { + fprintf(stderr, "tcc: ar: can't open file %s \n", argv[i_lib]); + goto the_end; + } + + // write header diff --git a/scripts/simple-patches/tcc-0.9.26-lb/addback-fileopen.before b/scripts/simple-patches/tcc-0.9.26-lb/addback-fileopen.before @@ -0,0 +1 @@ + // write header diff --git a/scripts/simple-patches/tcc-0.9.26-lb/remove-fileopen.after b/scripts/simple-patches/tcc-0.9.26-lb/remove-fileopen.after @@ -0,0 +1,2 @@ + if (ret == 1) + return ar_usage(ret); diff --git a/scripts/simple-patches/tcc-0.9.26-lb/remove-fileopen.before b/scripts/simple-patches/tcc-0.9.26-lb/remove-fileopen.before @@ -0,0 +1,8 @@ + if (ret == 1) + return ar_usage(ret); + + if ((fh = fopen(argv[i_lib], "wb")) == NULL) + { + fprintf(stderr, "tcc: ar: can't open file %s \n", argv[i_lib]); + goto the_end; + } diff --git a/scripts/stage1-flatten.sh b/scripts/stage1-flatten.sh @@ -42,12 +42,25 @@ case "$ARCH" in esac # --- paths ------------------------------------------------------------ +# Everything used by this script is in-tree under $ROOT. No reach into +# sibling repos. +# +# vendor/upstream/tcc-0.9.26.tar.gz — pristine upstream tarball +# scripts/simple-patches/tcc-0.9.26-lb/ — live-bootstrap's tcc +# simple-patches, copied in +# for in-tree builds +# scripts/simple-patches/tcc-0.9.26/ — our own tcc patches +# vendor/mes-libc/include/ — vendored mes-libc headers +# (byte-identical to upstream +# mes/include) +# vendor/boot2-include/ — our own header shim, wins +# -I priority for stdarg.h ROOT=$(cd "$(dirname "$0")/.." && pwd) WORK=$ROOT/build/tcc/$ARCH -DISTFILES=$ROOT/../lb-work/distfiles -LB_PATCHES=$ROOT/../live-bootstrap/steps/tcc-0.9.26/simple-patches +DISTFILES=$ROOT/vendor/upstream +LB_PATCHES=$ROOT/scripts/simple-patches/tcc-0.9.26-lb OUR_PATCHES=$ROOT/scripts/simple-patches/tcc-0.9.26 -MES_INCLUDE=$ROOT/../mes/include +MES_INCLUDE=$ROOT/vendor/mes-libc/include MES_INCLUDE_LINUX=$MES_INCLUDE/linux/$MES_ARCH TCC_TAR=$DISTFILES/tcc-0.9.26.tar.gz @@ -140,6 +153,7 @@ FLAT=$WORK/tcc.flat.c -nostdinc \ -I "$SRC" \ -I "$WORK/mes-overlay" \ + -I "$ROOT/vendor/boot2-include" \ -I "$MES_INCLUDE_LINUX" \ -I "$MES_INCLUDE" \ -D __linux__=1 \ diff --git a/scripts/stage2-alpine.sh b/scripts/stage2-alpine.sh @@ -61,8 +61,18 @@ MES_ARCH=x86_64 ROOT=$(cd "$(dirname "$0")/.." && pwd) WORK=$ROOT/build/tcc/$ARCH -DISTFILES=$ROOT/../lb-work/distfiles -MES_TAR=$DISTFILES/mes-0.27.1.tar.gz +# This is the legacy gcc-driven path the cc.scm tcc-boot2 chain +# replaces (see docs/TCC.md). Not on the main `make tcc-boot2` +# build path; kept around as a verification fallback. Requires the +# upstream mes tarball, which lives outside the repo — set +# LIVE_BOOTSTRAP=<path> or MES_TAR=<path-to-mes-0.27.1.tar.gz> +# explicitly. See scripts/diag-livebootstrap-qemu.sh for the same +# pattern. +: "${MES_TAR:=}" +if [ -z "$MES_TAR" ]; then + : "${LIVE_BOOTSTRAP:?set LIVE_BOOTSTRAP=<path-to-live-bootstrap-checkout> or MES_TAR=<mes-0.27.1.tar.gz>}" + MES_TAR=$LIVE_BOOTSTRAP/../lb-work/distfiles/mes-0.27.1.tar.gz +fi MES_PKG=mes-0.27.1 FLAT=$WORK/tcc.flat.c diff --git a/vendor/upstream/tcc-0.9.26.tar.gz b/vendor/upstream/tcc-0.9.26.tar.gz Binary files differ.