From b1fbe029b6e4f8fe79eaa46d5423249866903c1b Mon Sep 17 00:00:00 2001 From: Brenton Strickler Date: Thu, 5 Nov 2026 12:02:44 -0500 Subject: [PATCH] setup.sh: resolve cargo/rustc via command -v when outside ~/.cargo ensure_cargo_on_system_path hard-coded the symlink source to ~/.cargo/bin/cargo and exited if absent. Some hosted CI images ship a working rustup toolchain on PATH but not under ~/.cargo (e.g. GitHub's macos-15-arm64 runner), so check_rust passes, install_rust returns early, and this function then aborts with "cargo not found". Resolve each of cargo and rustc independently: prefer ${CARGO_HOME:-$HOME/.cargo}/bin, else fall back to `command -v`, and error only when neither yields an executable. command -v is sound as a locator here (it is unreliable only as a test of whether Maven subprocesses will see the binary on their default PATH, which is why the system-dir probe above still avoids it). System-dir early return and symlink/sudo behaviour are unchanged. --- scripts/setup.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index 2202eb2d..43c1ad36 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -404,10 +404,30 @@ ensure_cargo_on_system_path() { fi done - local cargo_bin="$HOME/.cargo/bin/cargo" - local rustc_bin="$HOME/.cargo/bin/rustc" - if [[ ! -x "$cargo_bin" ]]; then - error "cargo not found at $cargo_bin" + # Resolve the real cargo/rustc binaries to symlink from. Prefer the + # rustup default location ($CARGO_HOME, or ~/.cargo), but fall back to + # `command -v` when the toolchain lives elsewhere -- some hosted CI + # images (e.g. GitHub's macos-15-arm64 runner) ship cargo/rustc on PATH + # outside ~/.cargo. Here `command -v` is fine as a *locator* of the + # installed binary: it is only unreliable as a test of "will Maven + # subprocesses see it on their default PATH" (that is why the system-dir + # check above does not use it), and we re-expose whatever it finds via + # the symlink below, which is exactly what makes it visible to Maven. + local cargo_home="${CARGO_HOME:-$HOME/.cargo}" + local cargo_bin="" + local rustc_bin="" + if [[ -x "$cargo_home/bin/cargo" ]]; then + cargo_bin="$cargo_home/bin/cargo" + else + cargo_bin="$(command -v cargo || true)" + fi + if [[ -x "$cargo_home/bin/rustc" ]]; then + rustc_bin="$cargo_home/bin/rustc" + else + rustc_bin="$(command -v rustc || true)" + fi + if [[ ! -x "$cargo_bin" ]] || [[ ! -x "$rustc_bin" ]]; then + error "cargo/rustc not found (tried $cargo_home/bin and 'command -v cargo'/'command -v rustc')" exit 1 fi