Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
7694b7b
feat(self-compile): enable StarryOS x86_64 self-compilation
Jun 22, 2026
4bfc7ef
feat(self-compile): add QEMU bootstrap via dedicated app template
Jun 22, 2026
423e13a
docs(self-compile): add bootstrap flow as recommended (no-sudo) path
Jun 22, 2026
c153940
Revert "feat(self-compile): add QEMU bootstrap via dedicated app temp…
Jun 22, 2026
6a9bedd
fix(self-compile): restore original Cargo.toml/Cargo.lock; remove sta…
Jun 22, 2026
0c8baff
docs(self-compile): fix stale references; add --help option descriptions
Jun 22, 2026
0681e94
refactor(rsext4): replace .unwrap() with if-let in read_blocks
Jun 22, 2026
7314486
fix(self-compile): remove redundant plat_dyn=true from x86_64 build c…
Jun 22, 2026
45cf300
feat(self-compile): add QEMU-based bootstrap for selfhost rootfs
Jun 22, 2026
50cb293
docs(self-compile): add bootstrap as recommended no-sudo path
Jun 22, 2026
5bc2e4c
refactor(rsext4): align loopfile direct-scan error handling with line…
Jun 23, 2026
9dd7537
fix(self-compile): rename selfhost rootfs blueprint, drop misleading …
Jun 23, 2026
b8062b5
fix(self-compile): set snapshot=false on selfhost qemu configs
Jun 23, 2026
e7b7e49
refactor(rsext4): tidy journal/cache block-IO edge cases
Jun 23, 2026
efd7bc3
fix(self-compile): fetch full locked dep closure for offline guest build
Jun 23, 2026
d33ea29
docs(self-compile): correct x86_64 status — final link blocked by bui…
Jun 23, 2026
ce9240a
fix(self-compile): drive x86_64 guest build via canonical xtask musl-…
Jun 24, 2026
ddce178
docs(self-compile): flip x86_64 status to verified (SELF_COMPILE_SUCC…
Jun 24, 2026
7ac6f35
docs(self-compile): align rootfs preparation path with xtask prerequi…
Jun 24, 2026
a9a7bca
fix(self-compile): update code comment and error message to reflect b…
Jun 24, 2026
c53eb40
docs(self-compile): scope prepare-selfhost-rootfs.sh as maintainer tool
Jun 24, 2026
fd8be37
docs(self-compile): frame prepare-selfhost-rootfs.sh as maintainer tool
Jun 24, 2026
8cafce0
fix(self-compile): address self-review nits
Jun 25, 2026
0824052
fix(self-compile): address second-round self-review consistency nits
Jun 25, 2026
654c016
feat(self-compile): add downloadable blueprint with SHA-256 verification
Jun 25, 2026
1f430e4
fix(self-compile): harden blueprint download fallback and log direct-…
Jun 25, 2026
b90c326
fix(axfs-ng): flush before link() lookup to mirror create() coherence…
Jun 25, 2026
7b55f5a
test(rsext4): add LRU write-invalidation regression test and dir-laye…
Jun 25, 2026
0c8fdd5
fix(axbuild): inject -fno-stack-protector into std seed-build C flags
Jun 26, 2026
b1384ca
feat(self-compile): bootstrap provisions complete toolchain rootfs; h…
Jun 26, 2026
30fe892
fix(self-compile): resolve .gitignore rebase conflict; sync download …
Jun 26, 2026
0eb3d72
fix(self-compile): sync bootstrap qemu config comment with provisioni…
Jun 26, 2026
f15362e
docs(self-compile): correct --bootstrap comment to match provisioning…
Jun 27, 2026
3d6c92d
fix(self-compile): make --bootstrap provision a usable rootfs then stop
Jun 27, 2026
579bfb2
fix(self-compile): make --bootstrap the default no-sudo blueprint pat…
Jun 30, 2026
2941a4d
fix(self-compile): address self-review findings — docs sync, early fa…
Jun 30, 2026
a4952ab
fix(self-compile): honest --bootstrap scoping, correct stale docs, co…
Jun 30, 2026
06ecafd
fix(self-compile): correct doc-vs-code inaccuracies found in converge…
Jun 30, 2026
96d441e
fix(self-compile): make --bootstrap produce a self-compile-capable ro…
Jul 1, 2026
7f2034e
fix(bootstrap): download AIC8800 firmware in-guest during provisioning
Jul 1, 2026
446d342
docs(self-compile): sync bootstrap comments with current provisioning…
Jul 1, 2026
1e25b27
docs(self-compile): mention cargo fetch in bootstrap tree diagram
Jul 1, 2026
b290ba2
docs(self-compile): add Alpine base prerequisite to usage flow
Jul 5, 2026
9030e1e
docs(self-compile): sync CI note, script table, and env requirements …
Jul 5, 2026
81820c7
fix(self-compile): address comprehensive self-review findings
Jul 5, 2026
af6c526
fix(bootstrap): keep /bin/sh on busybox, don't replace with bash
Jul 6, 2026
110ce16
fix(docs): remove stale plat_dyn/axconfig_overrides references remove…
Jul 6, 2026
d7c9dc9
fix(self-compile): change inner script shebang from /usr/bin/bash to …
Jul 7, 2026
df9bf07
fix(self-compile): rewrite relative rustup symlinks to absolute in bo…
Jul 7, 2026
6638d59
docs(self-compile): replace remaining plat_dyn references in inner sc…
Jul 7, 2026
0df1cf5
fix(bootstrap): work around Alpine busybox trigger segfault
Jul 7, 2026
bd2801c
fix(bootstrap): add retry logic for rustup component/target downloads
Jul 7, 2026
87c31bc
fix(self-compile): create absolute cargo/rustc symlinks at runtime
Jul 7, 2026
5529f17
fix(bootstrap): remove symlink fix loop, always install kallsyms
Jul 7, 2026
803784d
fix(bootstrap): skip apk post-install scripts to avoid busybox segfault
Jul 7, 2026
b405e68
fix(bootstrap): increase rustup retry attempts from 3 to 5
Jul 7, 2026
8c8451c
fix(bootstrap): increase QEMU timeout to 4h for slow network
Jul 7, 2026
66a66f3
fix(bootstrap): re-add idempotent guards, support two-pass provisioning
Jul 8, 2026
cfe0aa0
fix(self-compile): verify SELFHOST_BOOTSTRAP_SUCCESS before relocatin…
Jul 8, 2026
d518e42
fix(self-compile): reuse existing bootstrap image on retry
Jul 8, 2026
a608b7c
fix(bootstrap): make apk install idempotent — skip if tools exist
Jul 8, 2026
c64eee7
fix(bootstrap): use -f instead of -x for idempotent toolchain check
Jul 8, 2026
c318241
fix(bootstrap): skip apk update, use base image cached package index
Jul 8, 2026
72702b0
fix(bootstrap): manually install busybox symlinks after apk
Jul 8, 2026
7dba8d4
fix(bootstrap): create busybox symlinks unconditionally, not only aft…
Jul 8, 2026
c960d64
fix(rsext4): propagate invalidate_cache Result to satisfy clippy -D w…
Jul 9, 2026
f2ee4c6
docs(rsext4): correct component doc — rsext4 is the active ax-fs-ng e…
Jul 9, 2026
34e990b
docs(self-compile): sync guide and prebuild comments with actual beha…
Jul 9, 2026
4b297b5
docs(rsext4): fix crate version (0.7.3) and dependency list
Jul 9, 2026
ffdddb5
docs(self-compile): fix bootstrap timeout and riscv64 tmpfs description
Jul 9, 2026
3bfedf1
fix(selfhost): stage AIC8800 firmware into the guest cache path
Jul 9, 2026
6a8cbd1
docs(selfhost): align prebuild/script comments with implementation
Jul 9, 2026
37e0d67
docs(starryos): sync self-compilation mirror doc with current app-run…
Jul 9, 2026
f18334c
fix(selfhost): harden bootstrap against stale-blueprint reuse and par…
Jul 9, 2026
42b03f5
docs(starryos): rewrite mirror doc bug-log/status to current truth
Jul 9, 2026
6653166
fix(selfhost): harden bootstrap for no-sudo reliability — tar guard +…
Jul 9, 2026
b207dab
fix(selfhost): also skip rustup installer when toolchain is pre-staged
Jul 9, 2026
c057215
fix(selfhost): create ~/.cargo/env in overlay instead of copying from…
Jul 9, 2026
b1ad377
fix(selfhost): pre-stage Rust DATA components (not glibc binaries) + …
Jul 9, 2026
e9cfbe3
feat(selfhost): pre-download rustup toolchain tarballs into overlay d…
Jul 9, 2026
eb0c30e
feat(selfhost): use host pre-staged rustup-init binary to skip all QE…
Jul 9, 2026
e6db60a
feat(selfhost): extract toolchain tarballs directly into overlay — ze…
Jul 9, 2026
2c8253b
fix(selfhost): add --strip-components=1 to tar extraction
Jul 9, 2026
b80058c
Revert "feat(selfhost): pre-download/extract toolchain tarballs; rust…
Jul 9, 2026
58e2e77
fix(selfhost): populate rustup download cache with SHA-256 hashed tar…
Jul 9, 2026
d447beb
fix(selfhost): install rustup on tmpfs to bypass rsext4 bottleneck
Jul 9, 2026
17c8e92
fix(selfhost): allow network in self-compile to download missing crates
Jul 10, 2026
22c242b
fix(selfhost): symlink /bin/sh to bash before kernel build
Jul 10, 2026
b5222d8
fix(selfhost): set DNS to QEMU slirp 10.0.2.3 for cargo network
Jul 10, 2026
5bcfa61
fix(selfhost): bake DNS and bash fixes into Debian rootfs provisioning
Jul 10, 2026
708fa15
feat(selfhost): auto-download pre-built selfhost rootfs (no sudo)
Jul 10, 2026
da3942b
Merge remote-tracking branch 'origin/dev' into codex/impl-pr-1076-dir…
ZR233 Jul 10, 2026
f1651f6
fix(selfhost): address HIGH/MED audit findings — robustness and corre…
Jul 10, 2026
8770ac6
fix(docs): update self-compilation guide — auto-download is implemented
Jul 10, 2026
4d8c327
fix(selfhost): fix trap overwrite and update remaining stale docs
Jul 10, 2026
31d5589
feat(starry): run x86 self-build in app guest
ZR233 Jul 10, 2026
08407b4
Merge remote-tracking branch 'origin/dev' into codex/impl-pr-1076-dir…
ZR233 Jul 10, 2026
a158efb
fix(selfhost): publish the canonical guest build output
ZR233 Jul 10, 2026
4470fac
fix(selfhost): parallelize guest Rustup unpacking
ZR233 Jul 10, 2026
e5fd5bb
fix(selfhost): retry transient Rustup downloads
ZR233 Jul 10, 2026
e6a33b7
fix(selfhost): pin guest cargo to the musl toolchain
ZR233 Jul 13, 2026
cf4a06c
Merge remote-tracking branch 'seek-hope/dev' into codex/impl-pr-1076-…
ZR233 Jul 13, 2026
0b08bf6
fix(rsext4): use enqueue_journal_update return value for commit detec…
Jul 13, 2026
eed2a71
fix(selfhost): keep guest build artifacts off tmpfs
ZR233 Jul 13, 2026
ff35823
Merge remote-tracking branch 'seek-hope/dev' into codex/impl-pr-1076-…
ZR233 Jul 13, 2026
7648c60
Merge remote-tracking branch 'origin/dev' into codex/impl-pr-1076-dir…
ZR233 Jul 13, 2026
651bfbd
refactor(starry): narrow x86_64 self-build changes
ZR233 Jul 13, 2026
1397108
fix(axfs-ng): sync to disk after write_at/append for cross-process co…
Jul 13, 2026
6c0b680
fix(selfhost): run busybox --install before apk, sync after apk
Jul 13, 2026
c672fbc
fix(selfhost): absorb non-fatal apk exit SIGSEGV, verify toolchain af…
Jul 13, 2026
755763d
feat(selfhost): pre-download rust toolchain tarballs on host side
Jul 13, 2026
4fc1e1d
fix(selfhost): pre-cache all 6 rustup component tarballs
Jul 13, 2026
c7f8ca0
perf(selfhost): install Rust toolchain on tmpfs to bypass rsext4 bott…
Jul 13, 2026
3dad0c8
perf(selfhost): pre-extract Rust toolchain on host, inject as single tar
Jul 13, 2026
f652c75
fix(selfhost): extract toolchain tar directly to ext4, keep rustup on…
Jul 13, 2026
85e5d5f
perf(selfhost): increase QEMU timeout to 8h for full E2E build
Jul 14, 2026
2df0639
fix(ci): format rsext4 coherence test
ZR233 Jul 14, 2026
16479ef
Merge remote-tracking branch 'seek-hope/dev' into codex/impl-pr-1076-…
ZR233 Jul 14, 2026
7f64747
docs(starry): publish self-compilation guide
ZR233 Jul 14, 2026
f34e1f5
fix(selfhost): use verified pre-extracted toolchain
ZR233 Jul 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/starry/selfhost/build-x86_64-unknown-none.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
target = "x86_64-unknown-none"
log = "Warn"
features = [
"axplat-dyn/efi",
"ax-driver/virtio-blk",
"ax-driver/virtio-net",
"ax-driver/virtio-gpu",
"ax-driver/virtio-input",
"ax-driver/virtio-socket",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

# This file is sourced by Alpine's login profile on every Starry boot. The
# app runner writes its current phase to persistent ext4 before doing work, so
# a kernel reset can be distinguished from the initial ready state.

state_file="${SELFHOST_STATE_FILE:-/opt/starry-selfhost.state}"

if [ -r "$state_file" ]; then
state=""
run_id=""
phase="unknown"
IFS=' ' read -r state run_id phase <"$state_file"

if [ "$state" = "running" ]; then
echo "SELF_COMPILE_FAILED: unexpected guest reboot during $phase (run_id=$run_id)"
sync 2>/dev/null || true

poweroff -f 2>/dev/null || poweroff 2>/dev/null || true
return 1 2>/dev/null || exit 1
fi
fi

unset state_file state run_id phase
true
294 changes: 294 additions & 0 deletions apps/starry/selfhost/selfhost-full-kernel/guest-selfbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
#!/bin/sh

set -eu

TOOLCHAIN="nightly-2026-05-28"
HOST_TRIPLE="x86_64-unknown-linux-musl"
TOOLCHAIN_DIR_NAME="${TOOLCHAIN}-${HOST_TRIPLE}"
RUSTUP_TOOLCHAIN="starry-selfhost-${TOOLCHAIN#nightly-}-${HOST_TRIPLE}"
SOURCE_TAR="${SELFHOST_SOURCE_TAR:-/opt/tgoskits-src.tar}"
SOURCE_META="${SELFHOST_SOURCE_META:-/opt/tgoskits-src.meta}"
SOURCE_DIR="${SELFHOST_SOURCE_DIR:-/tmp/tgoskits-src}"
TARGET_DIR="${SELFHOST_TARGET_DIR:-/opt/starry-selfhost-target}"
ARTIFACT="${SELFHOST_ARTIFACT:-/opt/starryos-selfbuilt}"
STATE_FILE="${SELFHOST_STATE_FILE:-/opt/starry-selfhost.state}"
RUN_ID_FILE="${SELFHOST_RUN_ID_FILE:-/opt/starry-selfhost.run-id}"
FAILURE_REASON="guest command failed"
CURRENT_PHASE="bootstrap"
RUN_ID="unknown"

write_state() {
state="$1"
phase="$2"
state_tmp="${STATE_FILE}.tmp"

printf '%s %s %s\n' "$state" "$RUN_ID" "$phase" >"$state_tmp"
mv "$state_tmp" "$STATE_FILE"
sync
}

mark_phase() {
CURRENT_PHASE="$1"
write_state running "$CURRENT_PHASE"
echo "SELF_COMPILE_PHASE=$CURRENT_PHASE"
}

finish_failure() {
status="$1"
trap - EXIT
write_state failed "$CURRENT_PHASE" 2>/dev/null || true
echo "SELF_COMPILE_FAILED: $FAILURE_REASON (phase=$CURRENT_PHASE, status=$status)"
sync 2>/dev/null || true
poweroff -f 2>/dev/null || poweroff 2>/dev/null || true
exit "$status"
}

handle_exit() {
status="$?"
if [ "$status" -ne 0 ]; then
finish_failure "$status"
fi
}

fail() {
FAILURE_REASON="$1"
exit 1
}

finish_success() {
artifact_size="$1"

trap - EXIT
write_state success publish
echo "SELF_COMPILE_ARTIFACT=$ARTIFACT"
echo "SELF_COMPILE_ARTIFACT_SIZE=$artifact_size"
echo "SELF_COMPILE_SUCCESS"
poweroff -f 2>/dev/null || poweroff 2>/dev/null || true
exit 0
}

load_run_id() {
[ -s "$RUN_ID_FILE" ] || fail "run id is missing: $RUN_ID_FILE"
IFS= read -r RUN_ID <"$RUN_ID_FILE"
[ -n "$RUN_ID" ] || fail "run id is empty: $RUN_ID_FILE"
}

install_build_packages() {
# Ensure busybox symlinks exist BEFORE apk touches the rootfs. The
# base image's busybox is statically linked and known-good; after apk
# upgrades musl libc / libcrypto / libssl, exec-ing the new busybox
# binary may SIGSEGV when the dynamic linker loads the just-upgraded
# shared libraries. Running this step first avoids that crash.
/bin/busybox --install -s /bin 2>/dev/null || true

# apk upgrades libcrypto3 and libssl3 first (packages 1-2/53). The
# new .so files are written to disk and all 53 packages install
# successfully, but apk's atexit / libc _fini cleanup may SIGSEGV
# when the dynamic linker touches the just-upgraded libraries during
# process exit. This is a known StarryOS ELF-loader limitation,
# not an rsext4 data corruption — apk reports "OK: … in 97 packages"
# before the crash. Absorb the non-fatal exit signal and validate
# the installed tools below.
apk add --no-cache --no-scripts \
bash build-base ca-certificates clang clang-dev cmake curl git libudev-zero-dev \
linux-headers musl-dev openssl-dev perl pkgconf python3 tar xz \
|| true

sync

# Re-create busybox symlinks (apk may have replaced busybox).
/bin/busybox --install -s /bin 2>/dev/null || true
update-ca-certificates 2>/dev/null || true

# Verify the build toolchain actually landed — if any critical binary
# is missing, fail explicitly rather than crashing later with a
# confusing "command not found".
for bin in bash gcc g++ make git curl perl python3 tar xz pkg-config cmake; do
command -v "$bin" >/dev/null 2>&1 || fail "$bin missing after apk"
done
[ -x /bin/bash ] || fail "/bin/bash not executable after apk"
[ -x /usr/bin/gcc ] || fail "/usr/bin/gcc not executable after apk"
}

verify_network() {
curl --fail --silent --show-error --location --retry 3 \
--connect-timeout 20 --max-time 120 \
https://static.rust-lang.org/dist/channel-rust-nightly.toml \
-o /tmp/channel-rust-nightly.toml
}

configure_musl_toolchain_aliases() {
gcc_path="$(command -v gcc)" || fail "gcc is unavailable after apk install"
ar_path="$(command -v ar)" || fail "ar is unavailable after apk install"

mkdir -p /usr/local/bin
ln -sf "$gcc_path" /usr/local/bin/x86_64-linux-musl-cc
ln -sf "$gcc_path" /usr/local/bin/x86_64-linux-musl-gcc
ln -sf "$ar_path" /usr/local/bin/x86_64-linux-musl-ar
}

install_rust() {
# The prebuild host extracts all six rustup component tarballs and
# bundles them into a single uncompressed tar (~2.5 GiB). We extract
# it directly to the ext4 rootfs — rsext4 is slow for small-file writes
# (~1-4 KiB/s during tar extraction) but `tar xf` streams the data
# through a pipe and does not deadlock the way `cp -a` from tmpfs does.
# Once the toolchain is on ext4, reads (rustc, std libs) are fast.
local toolchain_tar="/opt/rust-toolchain.tar"
local toolchain_name="$TOOLCHAIN_DIR_NAME"
local toolchain_dir="/root/.rustup/toolchains/$toolchain_name"

[ -f "$toolchain_tar" ] || fail "rust toolchain tar is missing: $toolchain_tar"

echo "[self-compile] extracting pre-built Rust toolchain to ext4 rootfs..."
mkdir -p /root/.rustup/toolchains
tar xf "$toolchain_tar" -C /root/.rustup/toolchains/ \
|| fail "failed to extract toolchain tar to ext4"
rm -f "$toolchain_tar"
[ -x "$toolchain_dir/bin/rustc" ] \
|| fail "pre-extracted rustc is missing: $toolchain_dir/bin/rustc"
[ -x "$toolchain_dir/bin/cargo" ] \
|| fail "pre-extracted cargo is missing: $toolchain_dir/bin/cargo"

# Install rustup to tmpfs (rsext4 is too slow for rustup's many small
# writes during cargo install of cargo-binutils / ksym).
local tmp_rustup=/tmp/rustup-home
local tmp_cargo=/tmp/cargo-home
mkdir -p "$tmp_rustup" "$tmp_cargo"
rm -f "$tmp_rustup/settings.toml"

export RUSTUP_HOME="$tmp_rustup"
export CARGO_HOME="$tmp_cargo"
export PATH="$tmp_cargo/bin:/usr/local/bin:/usr/bin:/bin"
export RUSTUP_IO_THREADS="${SELFHOST_RUSTUP_IO_THREADS:-4}"
export RUSTUP_MAX_RETRIES="${SELFHOST_RUSTUP_MAX_RETRIES:-5}"

if [ ! -x "$tmp_cargo/bin/rustup" ]; then
curl --fail --silent --show-error --location https://sh.rustup.rs \
-o /tmp/rustup-init.sh
sh /tmp/rustup-init.sh -y --no-modify-path --default-host "$HOST_TRIPLE" \
--default-toolchain none \
|| fail "rustup-init failed"
fi

# Official channel-like names are not valid custom toolchain aliases.
# Link the pre-extracted directory under a distinct name, then export the
# alias so the workspace rust-toolchain.toml cannot trigger a download.
rustup toolchain link "$RUSTUP_TOOLCHAIN" "$toolchain_dir" \
|| fail "rustup toolchain link failed"
rustup default "$RUSTUP_TOOLCHAIN" \
|| fail "rustup default failed"
export RUSTUP_TOOLCHAIN

command -v rustc >/dev/null 2>&1 || fail "rustc not found after install"
command -v cargo >/dev/null 2>&1 || fail "cargo not found after install"
rustc --version || fail "rustc --version failed"
cargo --version || fail "cargo --version failed"

echo "[self-compile] Rust toolchain ready."
echo "[self-compile] $(rustc --version)"
echo "[self-compile] $(cargo --version)"
}

install_kallsyms_tools() {
# cargo install downloads source + compiles — small enough to tolerate
# rsext4 throughput and slirp latency.
if ! cargo install --list | grep -q '^cargo-binutils v0.4.0:'; then
cargo install cargo-binutils --version 0.4.0 --locked
fi
if ! cargo install --list | grep -q '^ksym v0.6.0:'; then
cargo install ksym --version 0.6.0 --locked
fi

command -v rust-nm >/dev/null 2>&1 || fail "cargo-binutils did not install rust-nm"
command -v rust-objcopy >/dev/null 2>&1 || fail "cargo-binutils did not install rust-objcopy"
command -v gen_ksym >/dev/null 2>&1 || fail "ksym did not install gen_ksym"
}

prepare_source_tree() {
[ -f "$SOURCE_TAR" ] || fail "source archive is missing: $SOURCE_TAR"
rm -rf "$SOURCE_DIR"
mkdir -p "$SOURCE_DIR"
tar -xf "$SOURCE_TAR" -C "$SOURCE_DIR"
[ -f "$SOURCE_DIR/Cargo.toml" ] || fail "source archive does not contain Cargo.toml"

mkdir -p "$TARGET_DIR"
rm -rf "$SOURCE_DIR/target"
ln -s "$TARGET_DIR" "$SOURCE_DIR/target"
[ -d "$SOURCE_DIR/target" ] || fail "persistent target directory is unavailable"

if [ -f "$SOURCE_META" ]; then
echo "SELF_COMPILE_SOURCE_METADATA_BEGIN"
cat "$SOURCE_META"
echo "SELF_COMPILE_SOURCE_METADATA_END"
fi
}

report_build_storage() {
echo "SELF_COMPILE_STORAGE_BEGIN"
mount | grep -E ' on /(tmp|opt) ' || true
df -T / /tmp "$TARGET_DIR" 2>/dev/null || df -h / /tmp "$TARGET_DIR"
free -m 2>/dev/null || sed -n '1,5p' /proc/meminfo
echo "SELF_COMPILE_STORAGE_END"
}

detect_rust_host() {
DETECTED_HOST="$(rustc -vV | sed -n 's/^host: //p')"
[ "$DETECTED_HOST" = "$HOST_TRIPLE" ] \
|| fail "Rust host must be $HOST_TRIPLE, got ${DETECTED_HOST:-unknown}"
echo "SELF_COMPILE_RUST_HOST=$DETECTED_HOST"
}

build_host_xtask() {
cd "$SOURCE_DIR"
RUSTFLAGS= CARGO_ENCODED_RUSTFLAGS= \
cargo "+$RUSTUP_TOOLCHAIN" build --locked -p tg-xtask --target "$DETECTED_HOST"
XTASK="$SOURCE_DIR/target/$DETECTED_HOST/debug/tg-xtask"
[ -x "$XTASK" ] || fail "tg-xtask was not built for $DETECTED_HOST"
}

build_kernel() {
cd "$SOURCE_DIR"
"$XTASK" starry build \
-c apps/starry/selfhost/build-x86_64-unknown-none.toml \
--arch x86_64
}

publish_artifact() {
built_artifact="$SOURCE_DIR/target/x86_64-unknown-linux-musl/release/starryos"
[ -s "$built_artifact" ] || fail "x86_64 kernel artifact is missing: $built_artifact"

cp "$built_artifact" "$ARTIFACT"
chmod 0755 "$ARTIFACT"
[ -s "$ARTIFACT" ] || fail "failed to persist self-built kernel"
wc -c <"$ARTIFACT"
}

trap handle_exit EXIT

echo "SELF_COMPILE_START"
load_run_id
export CARGO_BUILD_JOBS="${SELFHOST_CARGO_BUILD_JOBS:-2}"
export AXBUILD_STARRY_KALLSYMS_AUTO_INSTALL=0
unset CARGO_BUILD_TARGET

mark_phase packages
install_build_packages
mark_phase network
verify_network
mark_phase rust
configure_musl_toolchain_aliases
install_rust
mark_phase tools
install_kallsyms_tools
mark_phase source
prepare_source_tree
report_build_storage
detect_rust_host
mark_phase xtask-host
build_host_xtask
mark_phase kernel
build_kernel
mark_phase publish
artifact_size="$(publish_artifact)"
finish_success "$artifact_size"
Loading