Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions scripts/build/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,8 @@ export interface CargoToolchain {
export function findRustLld(os: OS): {
rustLld: string | undefined;
rustLlvmVersion: string | undefined;
/** `rustc --print sysroot`. */
rustSysroot: string | undefined;
/** `host:` line from `rustc -vV` — the rustlib subdirectory name. */
rustHostTriple: string | undefined;
} {
const none = { rustLld: undefined, rustLlvmVersion: undefined, rustSysroot: undefined, rustHostTriple: undefined };
const none = { rustLld: undefined, rustLlvmVersion: undefined };
// Look up rustc the same way findCargo does cargo: $CARGO_HOME/bin first.
const cargoHome = process.env.CARGO_HOME ?? join(homedir(), ".cargo");
const rustc =
Expand Down Expand Up @@ -735,7 +731,7 @@ export function findRustLld(os: OS): {

const rustHostTriple = vv.match(/^host:\s*(\S+)/m)?.[1];
const rustLlvmVersion = vv.match(/^LLVM version:\s*(\d+\.\d+\.\d+)/m)?.[1];
if (rustHostTriple === undefined) return { ...none, rustSysroot: sysroot, rustLlvmVersion };
if (rustHostTriple === undefined) return { ...none, rustLlvmVersion };

const bin = join(sysroot, "lib", "rustlib", rustHostTriple, "bin");
const candidate =
Expand All @@ -745,7 +741,7 @@ export function findRustLld(os: OS): {
? join(bin, "gcc-ld", "ld64.lld")
: join(bin, "gcc-ld", "ld.lld");
const rustLld = isExecutable(candidate) ? candidate : undefined;
return { rustLld, rustLlvmVersion, rustSysroot: sysroot, rustHostTriple };
return { rustLld, rustLlvmVersion };
}

/**
Expand Down
36 changes: 19 additions & 17 deletions test/internal/build-rust-toolchain-probe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
* measured 36s per CI job, silently, because the proxy's output is piped).
* The probe must therefore pin the proxy to the channel with RUSTUP_TOOLCHAIN.
*
* The rustc here is a shell script that reports the RUSTUP_TOOLCHAIN it was
* given as its sysroot and as its host triple, so both probes are covered;
* PATH is emptied so no real rustup runs a pre-flight.
* The rustc here is a shell script that folds the RUSTUP_TOOLCHAIN it was
* given into its sysroot path and into its host triple, so both probes are
* covered. The fake sysroot has a `gcc-ld/ld.lld` only under the pinned
* names: an unpinned probe resolves to a path that does not exist and
* `rustLld` comes back undefined. PATH holds only the fixture's `bin`
* directory, so no real rustup runs a pre-flight.
*/
import { afterEach, expect, test } from "bun:test";
import { isWindows, tempDir } from "harness";
Expand All @@ -29,26 +32,25 @@ afterEach(() => {
});

test.skipIf(isWindows)("the configure-time rustc probe pins the rustup proxy to the pinned channel", () => {
const ldLld = join(`sysroot-for-${channel}`, "lib", "rustlib", `host-for-${channel}`, "bin", "gcc-ld", "ld.lld");
using dir = tempDir("build-rustc-probe", {
"bin/rustc": [
"#!/bin/sh",
'case "$1" in',
' --print) printf "%s\\n" "sysroot-for:${RUSTUP_TOOLCHAIN:-unset}" ;;',
' -vV) printf "host: host-for:%s\\nLLVM version: 22.1.4\\n" "${RUSTUP_TOOLCHAIN:-unset}" ;;',
"esac",
"",
].join("\n"),
"bin/rustc": ({ root }) =>
[
"#!/bin/sh",
'case "$1" in',
` --print) printf "%s\\n" "${root}/sysroot-for-\${RUSTUP_TOOLCHAIN:-unset}" ;;`,
' -vV) printf "host: host-for-%s\\nLLVM version: 22.1.4\\n" "${RUSTUP_TOOLCHAIN:-unset}" ;;',
"esac",
"",
].join("\n"),
[ldLld]: "",
});
chmodSync(join(String(dir), "bin", "rustc"), 0o755);
for (const executable of ["bin/rustc", ldLld]) chmodSync(join(String(dir), executable), 0o755);
process.env.CARGO_HOME = String(dir);
process.env.PATH = join(String(dir), "bin");

expect(findRustLld("linux")).toEqual({
rustSysroot: `sysroot-for:${channel}`,
// Both probes (sysroot and -vV) must carry the pin.
rustHostTriple: `host-for:${channel}`,
rustLld: join(String(dir), ldLld),
rustLlvmVersion: "22.1.4",
// The fake sysroot has no lib/rustlib/<host>/bin/gcc-ld/ld.lld.
rustLld: undefined,
});
});
Loading