ci(scripts/run-rs-task): prepended toolchain bin to PATH for cargo subprocesses

This commit is contained in:
can1357
2026-05-13 06:32:36 +02:00
parent 9418a3a8be
commit e2af4db461
+13 -1
View File
@@ -137,9 +137,21 @@ async function resolveCargoBinary(): Promise<string> {
async function runCommand(command: readonly string[]): Promise<number> {
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<string, string> = { ...(process.env as Record<string, string>) };
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",