Skip to content

fix(cargo-oxide): build standalone setup from deps - #1708

Merged
nihalpasham merged 3 commits into
NVIDIA:mainfrom
praveenperera:fix/cargo-oxide-setup-standalone-1688
Nov 9, 2026
Merged

nihalpasham merged 3 commits into
NVIDIA:mainfrom
praveenperera:fix/cargo-oxide-setup-standalone-1688

Conversation

@praveenperera

@praveenperera praveenperera commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What This PR Does

Fixes cargo oxide setup in standalone projects so it builds the project's cuda-oxide dependency once instead of attempting to compile the user's crate as the codegen backend:

  1. Build-Free Setup Context & Standalone Refresh (crates/cargo-oxide/src/commands/)
  2. Cache-Preserving Refresh Planning (crates/cargo-oxide/src/backend.rs)

1. Standalone cargo oxide setup Resolution and Refresh

Previously, Commands::Setup called resolve_context(), which eagerly built the backend once and set ctx.codegen_crate = cwd outside the workspace. setup() then tried to build ctx.codegen_crate as rustc-codegen-cuda, compiling the user's project and failing:

BEFORE (standalone project):
  cargo oxide setup
  ──► resolve_context() builds backend #1, sets codegen_crate = <user-project>
  ──► setup() runs build_backend_from_source(<user-project>) ──► fails ("no library targets found")

AFTER:
  cargo oxide setup
  ──► resolve_setup_context() locates backend without building
  ──► workspace:  SetupPlan::BuildAndPublish (builds local backend once, publishes to cache)
  ──► standalone: SetupPlan::RefreshFromDependency (rebuilds from project's cuda-oxide dependency)
  ──► pinned:     SetupPlan::RefusePinned (refuses when CUDA_OXIDE_BACKEND or config pin is set)
  • refresh_plan resolves Cargo.lock and checks toolchain compatibility before clearing ~/.cargo/cuda-oxide/, so lockless path dependencies and refused toolchains never wipe a valid shared cache.

Verification

  • Tests & CI Gates:
    • cargo test -p cargo-oxide: PASS (287 passed)
    • cargo clippy -p cargo-oxide --all-targets -- -D warnings: PASS
    • RUSTDOCFLAGS="-D warnings" cargo doc -p cargo-oxide --no-deps: PASS

Closes #1688

Outside the cuda-oxide workspace, Context::codegen_crate is the user's
project directory, yet setup built it as the backend source. A
`cargo oxide new` project failed with "no library targets found", and
a library crate compiled itself and then found no backend artifact.

Standalone setup now takes the same path as `update`'s RefreshCache:
it rebuilds the backend from the commit the project's cuda-oxide
dependency resolves to (in place for a path dependency, from a main
clone without one) and installs it into the shared cache. Both
commands share that code, and setup refuses a CUDA_OXIDE_BACKEND or
`.cargo/cuda-oxide.toml` pin the way update does, since the pin
outranks the cache it would rebuild.

setup now resolves its context without building the backend, so a
cold cache is built once instead of once during resolution and again
in setup. Workspace setup still builds the local source and publishes
it to the shared cache.

Fixes NVIDIA#1688

Signed-off-by: Praveen Perera <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

`refresh_cached_backend` decided whether to clear the shared cache from
a read-only `cargo metadata --offline --locked`, which fails on a
project with no `Cargo.lock` yet. The failure counted as "uses the
cache", so the first `setup` or `update` of a fresh project with a path
dependency cleared the shared cache, and the in-place build never
repopulated it. Decide from the full resolution instead, which also
leaves the cache intact when resolution fails.

Signed-off-by: Praveen Perera <[email protected]>
A standalone refresh cleared the shared cache before checking that the
project's toolchain can build and load the dependency's backend. On a
mismatch it then refused and exited, leaving other projects without the
cached backend they were using and nothing in its place. `setup` now
reaches this path, so settle the refusal while planning the refresh,
before anything is cleared.

Also note in `update`'s doc comment that a path dependency builds in
place and leaves the shared cache alone.

Signed-off-by: Praveen Perera <[email protected]>
@praveenperera
praveenperera marked this pull request as ready for review November 3, 2026 13:45
praveenperera added a commit to praveenperera/cuda-rust that referenced this pull request Nov 3, 2026
Replace the fork's earlier standalone-setup fix with the reviewed
version from upstream NVIDIA#1708.

Standalone `cargo oxide setup` now rebuilds the backend the way
`update` refreshes the cache, from the commit the project's cuda-oxide
dependency resolves to, and refuses a backend pin as `update` does.
Context resolution no longer builds the backend, so a cold cache is
built once.

Two cache fixes came out of review. The decision to clear the shared
cache now uses the full resolution, so a fresh project with a path
dependency and no Cargo.lock no longer clears it. A toolchain mismatch
is refused while planning the refresh, before the cache is cleared.

Signed-off-by: Praveen Perera <[email protected]>
@nihalpasham nihalpasham added cuda-oxide SIMT programming model: rustc backend, cargo oxide, cuda-device, cuda-host, book bug Something isn't working cargo-oxide The `cargo oxide` subcommand and build automation build-related Build scripts, toolchain discovery, or compilation setup labels Nov 9, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

/ok to test dc633ac

@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks, routing standalone cargo oxide setup through resolve_setup_context and refresh_from_dependency while guarding the shared cache on lockless path dependencies and toolchain mismatches covers #1688 cleanly.

At dc633ac5, all 287 cargo-oxide tests, clippy, and rustdoc checks pass. Merging once CI is green.

@nihalpasham
nihalpasham merged commit 2eb2c0b into NVIDIA:main Nov 9, 2026
77 checks passed
@praveenperera
praveenperera deleted the fix/cargo-oxide-setup-standalone-1688 branch November 9, 2026 15:22
copy-pr-bot Bot pushed a commit that referenced this pull request Nov 22, 2026
…fication

Resolve `commands/context.rs` with #1708 (`resolve_context_in`) and refresh
`examples/safe_*/Cargo.lock` to workspace `0.4.0`.

Signed-off-by: nihalpasham <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup cargo-oxide The `cargo oxide` subcommand and build automation cuda-oxide SIMT programming model: rustc backend, cargo oxide, cuda-device, cuda-host, book

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: cargo oxide setup in a standalone project builds the project instead of the backend

2 participants