From d48b0968688043561d59db082d9fbfd5cfc8dd9b Mon Sep 17 00:00:00 2001 From: Test User Date: Fri, 12 Jun 2026 21:34:44 +0800 Subject: [PATCH] fix(setup): prefer Linux-native Bun on WSL and respect STEP_BUN_BIN On WSL, a Windows bun (e.g. installed under /mnt/c) is picked up first by command -v, but it cannot build or run a working Linux native binary. Add resolve_bun() to detect this case and prefer a Linux-native bun ($HOME/.bun/bin/bun, /usr/local/bin/bun, /opt/bun/bin/bun). Also honor STEP_BUN_BIN when explicitly set. --- scripts/setup.sh | 49 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index 557f836..91a480b 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -58,6 +58,40 @@ warn() { printf " \033[33m! %s\033[0m\n" "$*"; } err() { printf " \033[31m✗ %s\033[0m\n" "$*"; } step_cli() { node scripts/run-step.mjs --stale-only "$@"; } +# Resolve a usable Bun binary. On WSL, a Windows bun (under /mnt) cannot build +# or run a working Linux native binary, so we explicitly look for a +# Linux-native installation first. +resolve_bun() { + if [[ -n "${STEP_BUN_BIN:-}" ]]; then + if [[ -x "$STEP_BUN_BIN" ]]; then + echo "$STEP_BUN_BIN" + return 0 + fi + warn "STEP_BUN_BIN=$STEP_BUN_BIN is not executable; ignoring" >&2 + fi + + local bun_path + bun_path=$(command -v bun || true) + if [[ -n "$bun_path" && "$bun_path" != /mnt/* ]]; then + echo "$bun_path" + return 0 + fi + + if [[ -n "$bun_path" && "$bun_path" == /mnt/* ]]; then + warn "Detected Windows Bun at $bun_path; looking for a Linux-native Bun..." >&2 + fi + + for candidate in "$HOME/.bun/bin/bun" "/usr/local/bin/bun" "/opt/bun/bin/bun"; do + if [[ -x "$candidate" ]]; then + info "Using Linux-native Bun: $candidate" >&2 + echo "$candidate" + return 0 + fi + done + + return 1 +} + # ── 0. pre-flight ───────────────────────────────────────────────────────── # pnpm may be missing on a fresh clone. Try to bootstrap it via corepack # (bundled with Node ≥ 16.10) before bailing out. @@ -185,13 +219,16 @@ if [[ "$SKIP_BUILD" == 1 ]]; then if [[ -x "dist/bin/step" ]]; then INSTALL_NATIVE_BINARY=1 fi -elif command -v "${STEP_BUN_BIN:-bun}" >/dev/null 2>&1; then - info "Bun found; building native binary (dist/bin/step)." - pnpm build:bin - ok "dist/bin/step built" - INSTALL_NATIVE_BINARY=1 else - warn "Bun not found; installing a Node-based launcher instead of a native binary." + BUN_PATH=$(resolve_bun || true) + if [[ -n "$BUN_PATH" ]]; then + info "Bun found; building native binary (dist/bin/step)." + STEP_BUN_BIN="$BUN_PATH" pnpm build:bin + ok "dist/bin/step built" + INSTALL_NATIVE_BINARY=1 + else + warn "Bun not found; installing a Node-based launcher instead of a native binary." + fi fi # ── 7. Install to ~/.step-cli/bin/ + ensure PATH ──────────────────────────