From 88d31906d9e826c79ccf6bfd76a45616dbadd28a Mon Sep 17 00:00:00 2001 From: Vyncint Ng <115854244+vyncint@users.noreply.github.com> Date: Fri, 28 Aug 2026 21:32:02 +0700 Subject: [PATCH] fix(cargo-oxide): `fmt` no longer builds the backend before formatting `cargo oxide fmt` resolved its context with `resolve_context`, which calls `backend::find_or_build_backend`: on a checkout with no cached `librustc_codegen_cuda.so` the command compiled the entire codegen backend -- and in standalone mode cloned it first -- before formatting a single file. Formatting compiles no device code. `format_all` reads only `workspace_root`, `codegen_crate` and `examples_dir`; neither it nor `run_cargo_fmt`, `run_cargo_fmt_manifest`, `run_fmt_command` nor `collect_example_manifests` takes a `Context` at all, so `backend_so` is unreachable from this path. `resolve_passive_context` fills those three fields identically in every discovery branch, so the eager resolver bought nothing. `doctor`, `clean`, `list` and `update` already resolve passively for the same reason; `fmt` was the one read-only command left resolving eagerly. Its doc comment now names it alongside them. Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com> --- crates/cargo-oxide/src/commands/context.rs | 4 ++-- crates/cargo-oxide/src/main.rs | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/cargo-oxide/src/commands/context.rs b/crates/cargo-oxide/src/commands/context.rs index 7ec0f9a85b..100cc5d01e 100644 --- a/crates/cargo-oxide/src/commands/context.rs +++ b/crates/cargo-oxide/src/commands/context.rs @@ -97,8 +97,8 @@ pub fn resolve_context() -> Context { /// only located via [`backend::backend_so_candidate`], never built and never /// cloned, and an invalid `.cargo/cuda-oxide.toml` degrades to defaults with /// a warning instead of exiting (so `doctor` can report it as a failed -/// check). Passive commands such as `doctor` and `clean` must remain usable -/// without triggering backend setup or network access. +/// check). Passive commands such as `doctor`, `clean`, `list` and `fmt` must +/// remain usable without triggering backend setup or network access. /// `run`/`build`/`pipeline`/`setup` still build the backend on demand. pub fn resolve_passive_context() -> Context { if let Some(workspace_root) = backend::find_workspace_root() { diff --git a/crates/cargo-oxide/src/main.rs b/crates/cargo-oxide/src/main.rs index 8f1b2ef349..32bfa3eec8 100644 --- a/crates/cargo-oxide/src/main.rs +++ b/crates/cargo-oxide/src/main.rs @@ -1035,7 +1035,12 @@ fn main() { commands::list_examples(&ctx, json); } Commands::Fmt { check } => { - let ctx = commands::resolve_context(); + // Formatting compiles no device code. `format_all` reads only + // `workspace_root`, `codegen_crate` and `examples_dir`, which the + // passive resolver fills in identically, so eager resolution only + // added a backend build -- and a clone on a fresh checkout -- ahead + // of the first file being formatted. + let ctx = commands::resolve_passive_context(); commands::format_all(&ctx, check); } Commands::New { name, async_mode } => {