Files
nucleic/scripts/build-nash-macos.sh
T

62 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Build nash (shell/nash — docs/NASH.md) as a UNIVERSAL macOS binary: the one darwin artifact
# that M5 (macOS-VM provisioning stages it → guest /usr/local/bin/nash, NASH.md §7.5) and
# M5.5 (the in-app-bundle host copy, §7.7/§8) both consume. Linux slices are built elsewhere
# (naros.yml, static musl); this script is the darwin counterpart, run on the HOST or CI —
# never in the guest.
#
# ./scripts/build-nash-macos.sh [output-dir] # default output: shell/dist/macos
#
# Produces <output-dir>/nash (arm64 + x86_64, lipo'd). Needs cargo with both darwin std
# targets; when rustup is present the targets are added automatically. Escape hatch:
# NUCLEIC_NASH_SKIP_X86_64=1 emits an arm64-only binary for a quick local round-trip (the
# VM guest is arm64) — fine for dev provisioning, but never ship it: packaging and NASH.md
# §8 require the universal slice.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
WORKSPACE="$REPO_ROOT/shell"
OUT_DIR="${1:-$WORKSPACE/dist/macos}"
# Keep cargo's target dir off virtiofs when building from a macOS-VM share — same rationale as
# scripts/lib/build-scratch.sh for SwiftPM; cargo takes the redirect via CARGO_TARGET_DIR. An
# explicit CARGO_TARGET_DIR from the caller always wins.
if [ -z "${CARGO_TARGET_DIR:-}" ]; then
SCRATCH_ARGS="$(bash "$REPO_ROOT/scripts/lib/build-scratch.sh" "$WORKSPACE")"
if [ -n "$SCRATCH_ARGS" ]; then
export CARGO_TARGET_DIR="${SCRATCH_ARGS#--scratch-path }/cargo-target"
fi
fi
TARGET_DIR="${CARGO_TARGET_DIR:-$WORKSPACE/target}"
TARGETS=(aarch64-apple-darwin)
[ "${NUCLEIC_NASH_SKIP_X86_64:-0}" = "1" ] || TARGETS+=(x86_64-apple-darwin)
SLICES=()
for target in "${TARGETS[@]}"; do
if command -v rustup >/dev/null 2>&1; then
rustup target add "$target" >/dev/null 2>&1 || true
fi
echo "▸ Building nash ($target, release) …"
(cd "$WORKSPACE" && cargo build --release --target "$target" -p nash)
SLICES+=("$TARGET_DIR/$target/release/nash")
done
mkdir -p "$OUT_DIR"
if [ "${#SLICES[@]}" -eq 1 ]; then
echo "⚠ arm64-only nash (NUCLEIC_NASH_SKIP_X86_64=1) — dev use only, do not ship (NASH.md §8)." >&2
cp "${SLICES[0]}" "$OUT_DIR/nash"
else
echo "▸ lipo → universal …"
lipo -create -output "$OUT_DIR/nash" "${SLICES[@]}"
fi
chmod 0755 "$OUT_DIR/nash"
echo " slices: $(lipo -archs "$OUT_DIR/nash")"
echo " version: $("$OUT_DIR/nash" --version)"
echo "✓ $OUT_DIR/nash"
echo " Stage it for provisioning (next to provision-macos-guest.sh in the guest share) or let"
echo " scripts/package-app.sh embed it at Resources/macvm/nash."