#!/usr/bin/env bash# `ensure_cargo_on_path` — a shell that cannot see `rustc` is a shell whose PATH# is missing `~/.cargo/bin`, not a Mac without a Rust toolchain.## THIS IS A SOURCED SNIPPET, NOT A COMMAND. It lives on its own so# `scripts/__tests__/cargo-path.test.ts` can run it with a stubbed PATH without# running a build, the way `scripts/lib/rust-targets.sh` beside it is run.## THE FAILURE IT EXISTS FOR. rustup does not install a compiler anywhere on the# default PATH — it writes `~/.cargo/bin` and appends a line to `~/.zshrc` and# `~/.profile`. A LOGIN shell therefore has it and a NON-INTERACTIVE one does# not, and every way this repo's heavy work is really started is the second# kind: a `bash -lc` that is not a login shell, an agent's tool call, a# `with-build-lock.sh` child, a LaunchAgent. On 16 Sep 2026 the first attempt at# the 0.4.7 Mac release died in TWELVE SECONDS with `cargo: command not found`# after the lane had already taken the machine-wide build lock — a failure that# says nothing about the release and everything about the shell it was typed in.## So the rule is: ASK, then fix, then say so. A shell that already resolves# `rustc` is left completely alone (CI, and any login shell), which is why this# can be called unconditionally at the top of a lane. A shell that does not gets# `$HOME/.cargo/bin` PREPENDED and one line on stderr naming what was done —# never a silent repair, because a PATH that is wrong here is usually wrong for# whatever the person runs next too.## And a Mac with no toolchain at all is REFUSED here rather than a `cargo` line# later: the message names rustup, and the caller has spent nothing yet.# The tag every line carries, so a caller's log reads as one voice.CARGO_PATH_LOG_PREFIX="${CARGO_PATH_LOG_PREFIX:-[cargo-path]}"ensure_cargo_on_path() {if command -v rustc >/dev/null 2>&1; thenreturn0filocal bin="${CARGO_HOME:-$HOME/.cargo}/bin"if [ -x "$bin/rustc" ]; then PATH="$bin:$PATH"export PATH echo "$CARGO_PATH_LOG_PREFIX no rustc on PATH — prepended $bin (a non-interactive shell does not read the line rustup put in your profile)" >&2return0fi echo "$CARGO_PATH_LOG_PREFIX there is no rustc on PATH and none at $bin/rustc — this Mac has no Rust toolchain." >&2 echo "$CARGO_PATH_LOG_PREFIX install one: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh" >&2return1}