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
82 changes: 1 addition & 81 deletions scripts/build/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,6 @@ function windowsShimDestPath(cfg: Config): string {
return resolve(cfg.cwd, "src", "install", "windows-shim", "bun_shim_impl.exe");
}

/**
* Path to the `rustup` binary that owns `cfg.cargo`, or `undefined` if
* `cfg.cargo` isn't a rustup proxy (a distro/Homebrew cargo, say).
* `rustup target add` is only meaningful when rustup is the toolchain
* manager — `rust_build_cross` requires it; everyone else gets `rust_build`.
*/
function findRustup(cfg: Config): string | undefined {
if (cfg.cargo === undefined) return undefined;
const rustup = join(dirname(cfg.cargo), `rustup${cfg.host.exeSuffix}`);
return existsSync(rustup) ? rustup : undefined;
}

// ───────────────────────────────────────────────────────────────────────────
// Paths
// ───────────────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -243,47 +231,6 @@ export function registerRustRules(n: Ninja, cfg: Config): void {
restat: true,
});

// Variant that ensures the pinned toolchain (and `rust-std` for
// `$rust_target` when it has a prebuilt one) is fully installed before
// building. CI agents pin the toolchain via `RUSTUP_TOOLCHAIN`, which
// bypasses `rust-toolchain.toml`'s `targets`/`components` install list, and
// rustup-proxy auto-install can leave a *partial* toolchain dir (rustc/cargo
// present, no `rust-std`, no `lib/rustlib/multirust-channel-manifest.toml`).
// That surfaces as either `error[E0463]: can't find crate for core` (cargo
// ran, no std) or `error: Missing manifest in toolchain '<channel>-<host>'`
// (rustup-proxy refused to even resolve cargo). `rustup toolchain install`
// repairs both, and is an offline ~70ms no-op when the toolchain is already
// complete. No `--force`: that means "update even if the manifest lacks a
// component", which re-fetches the channel manifest on every build.
//
// `$rust_target_arg` is `--target <triple>` for Tier 1/2 (also installs the
// prebuilt `rust-std-<triple>`), and empty for Tier 3 (no prebuilt; cargo
// gets `-Zbuild-std` instead — see emitRust). Both still get `rust-src`
// (needed for `-Zbuild-std`).
//
// Only registered when `cfg.rustToolchain` is pinned and `cfg.cargo` is a
// rustup proxy — otherwise there's no channel to install / no `rustup` to
// call, and toolchain management is the user's problem.
// `--console` on the rustup step too: it's sequential with cargo (both
// sides of `&&`) and the rule already takes the console pool, so there's
// no interleaving risk — and `--console` inherits stdio directly, which
// matters because stream.ts's pipe path can drop a fast-failing child's
// output (it `process.exit()`s on `close` before the async stdout writes
// drain). Without it, a failed `toolchain install` shows no error at all.
//
// No `--profile minimal`: the agent already has the default profile, and
// rustup applies `--profile` to the install spec, not just first-install —
// requesting a *narrower* profile on a reinstall is asking for
// trouble. We only care that `rust-src` and `rust-std-<triple>` exist on
// top of whatever profile is there.
//
// Windows: ninja spawns commands via CreateProcess directly (no shell), so
// `&&` would be passed as a literal argument to the first node.exe — rustup
// then sees the second half of the chain as extra argv and rejects
// `--experimental-strip-types`. Wrap in `cmd /c "..."` so cmd.exe handles
// the chain (cmd's quote-stripping rule removes only the outermost pair,
// preserving the embedded `"..."` around paths/env values). Same pattern as
// codegen.ts / bun.ts.
// Windows .bin/ shim PE: cargo build → copy into the source tree for
// `include_bytes!`. One rule does both; cargo's own output path and the
// source-tree copy are undeclared side effects (see below for what $out is).
Expand Down Expand Up @@ -320,21 +267,6 @@ export function registerRustRules(n: Ninja, cfg: Config): void {
// exists for cargo's dep-info on $shim_dest, not for restat.
});
}

const rustup = findRustup(cfg);
if (rustup !== undefined && cfg.rustToolchain !== undefined) {
// `-q` + `--no-self-update` silence the five `info:` lines rustup prints
// on every no-op reinstall; warnings/errors still show.
const chain =
`${stream} --console $env ${q(rustup)} -q toolchain install ${cfg.rustToolchain} --no-self-update --component rust-src $rust_target_arg && ` +
`${stream} --console --cwd=$cwd $env ${q(cfg.cargo)} build $args`;
n.rule("rust_build_cross", {
command: hostWin ? `cmd /c "${chain}"` : chain,
description: "cargo bun_runtime → $label ($rust_target_arg)",
pool: "console",
restat: true,
});
}
}

// ───────────────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -894,20 +826,9 @@ export function emitRust(n: Ninja, cfg: Config, inputs: RustBuildInputs): string
}

// ─── Emit build node ───
// When the toolchain is rustup-managed and pinned, route through
// `rust_build_cross`, which does `rustup toolchain install ...`
// before cargo. That makes the first build after a `rust-toolchain.toml`
// channel bump (and a partially auto-installed toolchain) self-heal —
// see the rule comment above. Tier 1/2 also pass `--target <triple>` so
// the prebuilt `rust-std` for the cross triple is installed; Tier 3 omits
// it (no prebuilt — cargo gets `-Zbuild-std` instead) and just gets
// `rust-src`. Local builds without rustup, or without a pinned channel,
// fall back to plain `rust_build` and trust whatever toolchain `cfg.cargo`
// resolves to.
const useCrossRule = findRustup(cfg) !== undefined && cfg.rustToolchain !== undefined;
n.build({
outputs: [lib],
rule: useCrossRule ? "rust_build_cross" : "rust_build",
rule: "rust_build",
Comment on lines 827 to +832

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Unrelated deletion of rust_build_cross / findRustup() regresses CI toolchain self-healing

Extended reasoning...

This bundler PR deletes the findRustup() helper and the rust_build_cross ninja rule so emitRust now unconditionally emits plain rust_build. On the base branch, when cfg.rustToolchain is pinned and cargo is a rustup proxy (every CI agent), the build prefixed cargo with rustup toolchain install … --component rust-src [--target …] to repair a partially auto-installed toolchain (rustc/cargo present, no rust-std, no channel manifest). After merge, a CI agent in that state hits error[E0463]: can't find crate for core or error: Missing manifest in toolchain '<channel>-<host>' and the build fails instead of self-healing. Nothing in the PR title/description mentions this build-system change, and it leaves four stale references to rust_build_cross behind (rust-lto-fix-cli.ts:39, tools.ts:696, source.ts:638, source.ts:647). The fix is to drop the scripts/build/rust.ts hunk from this PR entirely (or, if the removal is intentional, land it separately with the stale comments cleaned up and the workarounds.ts self-obsoleting entry that scripts/build/CLAUDE.md…

Verification: normal — The diff at scripts/build/rust.ts deletes findRustup() (base lines 178-188), the entire rust_build_cross rule registration (base lines 246-337, including its 40-line rationale comment), and the useCrossRule selection in emitRust (base lines 897-907, 913), replacing it with an unconditional rule: "rust_build". Yet rust.ts:645 still sets `env.RUSTUP_TOOLCHAIN =… | normal — The…

@Jarred-Sumner Jarred-Sumner Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah

inputs: [],
// Cargo binary itself + every .rs/Cargo.toml so editing one re-invokes
// (cargo's own fingerprinting then decides what to actually recompile).
Expand All @@ -920,7 +841,6 @@ export function emitRust(n: Ninja, cfg: Config, inputs: RustBuildInputs): string
vars: {
cwd: cfg.cwd,
args: quoteArgs(args, hostWin),
...(useCrossRule ? { rust_target_arg: tier3 ? "" : `--target ${triple}` } : {}),
label: `${cfg.libPrefix}bun_runtime${cfg.libSuffix}`,
env: Object.entries(env)
.map(([k, v]) => `--env=${k}=${quote(v, hostWin)}`)
Expand Down
Loading
Loading