diff --git a/scripts/run-rs-task.ts b/scripts/run-rs-task.ts index 302715808..2f4e60d1f 100644 --- a/scripts/run-rs-task.ts +++ b/scripts/run-rs-task.ts @@ -137,9 +137,21 @@ async function resolveCargoBinary(): Promise { async function runCommand(command: readonly string[]): Promise { const [head, ...rest] = command; - const argv = head === "cargo" ? [cargoBinary, ...rest] : [head, ...rest]; + const isCargo = head === "cargo"; + const argv = isCargo ? [cargoBinary, ...rest] : [head, ...rest]; + const env: Record = { ...(process.env as Record) }; + if (isCargo) { + // Cargo subprocesses (notably `rustc -vV` from `cargo metadata`) resolve + // via PATH; ensure the active toolchain bin dir wins over Homebrew's + // rustup-init shadow on macOS runners. + const toolchainBin = path.dirname(cargoBinary); + const pathSep = process.platform === "win32" ? ";" : ":"; + const currentPath = env.PATH ?? env.Path ?? ""; + env.PATH = currentPath === "" ? toolchainBin : `${toolchainBin}${pathSep}${currentPath}`; + } const proc = Bun.spawn(argv, { cwd: repoRoot, + env, stdin: "inherit", stdout: "inherit", stderr: "inherit",