Repository navigation
Description
cargo oxide fmt resolves its context with resolve_context(), which calls backend::find_or_build_backend. On a checkout with no cached librustc_codegen_cuda.so that compiles the entire codegen backend before the first file is formatted, and in standalone mode (a project from cargo oxide new) it clones the backend first.
Formatting compiles no device code, so none of that work is used.
Repro
Workspace checkout, host-build backend absent:
$ mv crates/rustc-codegen-cuda/target/x86_64-unknown-linux-gnu/debug/librustc_codegen_cuda.so /tmp/
$ cargo oxide fmt --check
Building rustc-codegen-cuda backend...
Compiling mir-transforms v0.2.1 (.../crates/mir-transforms)
Compiling mir-lower v0.2.1 (.../crates/mir-lower)
Compiling cuda-oxide-codegen v0.1.0 (.../crates/cuda-oxide-codegen)
Compiling mir-importer v0.2.1 (.../crates/mir-importer)
Compiling rustc_codegen_cuda v0.2.1 (.../crates/rustc-codegen-cuda)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 16.94s
✓ Backend built: .../librustc_codegen_cuda.so
📦 Checking root workspace...
The 16.94s is with the rest of the workspace already compiled. From a cold target/ it is minutes, and standalone mode adds a clone on top.
Why the backend is not needed here
format_all reads three fields of Context — workspace_root, codegen_crate and examples_dir — and never backend_so or config.
Its call graph is closed against Context: run_cargo_fmt, run_cargo_fmt_manifest, run_fmt_command and collect_example_manifests all take &Path / &mut Vec<PathBuf>, so there is no indirection through which the backend could be reached.
resolve_passive_context() fills those three fields identically in every discovery branch — workspace, standalone, and the not-found branch, which is byte-identical between the two resolvers. The only difference that reaches fmt is that an invalid .cargo/cuda-oxide.toml degrades to defaults with a warning instead of exiting.
Precedent
doctor, clean, list and update already resolve passively for exactly this reason; doctor's arm carries a comment saying it must never build the backend before it can diagnose the environment. fmt is the only read-only command left resolving eagerly.
Impact
CONTRIBUTING.md:147-152 tells contributors to use this command specifically — "Use cargo oxide fmt rather than a bare cargo fmt" — so the command a new contributor is pointed at pays for a backend build it never uses.
Relation to #1048
#1048's second option (have the fmt job run cargo oxide fmt --check directly) names its blocker as "compiling cargo-oxide first costs more than the check itself". That is the cost of the CLI binary and it remains. This defect stacks a second, larger cost on top of it. Fixing this is a step toward that option, not a fix for it, so #1048 should stay open.
Happy to take this — the fix is one line at the dispatch.
Activity