Repository navigation
feat(cargo-oxide): select extra-rustflags by target triple - #1
Conversation
`extra-rustflags` in `.cargo/cuda-oxide.toml` was one flat list, and the `CARGO_ENCODED_RUSTFLAGS` cargo-oxide exports hides Cargo's own `target.<triple>.rustflags`. A project whose host code wants a CPU flag therefore gave it to every host: `-C target-cpu=znver3` written for an x86_64 workstation reached an aarch64 build (DGX Spark), where rustc warns that znver3 is not a processor on every crate and crashes inside LLVM on some. A `[target.<triple>]` table now holds an `extra-rustflags` list for one triple. A build gets the top-level list, then the table of the triple it builds for: the command's `--target` (before any `--`), else `CARGO_BUILD_TARGET`, else the host triple of `rustc -vV` run where Cargo runs. A triple with no table gets the top-level list alone. With tables present and no triple known, or two different `--target` values in one command, the build stops with a named error instead of guessing. A config without tables resolves exactly as before and runs no extra `rustc -vV`. `cfg(...)` keys and fields other than `extra-rustflags` are refused by name, so a table cargo-oxide cannot honor never builds without its flags; `doctor` reports them through the existing config check. Tests: a per-target config built with `--target aarch64-unknown-linux-gnu` gets `-C target-cpu=native` and no znver3, and with `--target x86_64-unknown-linux-gnu` the x86 list (red before this change: the table was ignored and aarch64 got no flags); a flat list still reaches every triple in the same position; selection order, unlisted and unknown triples, the host fallback, `--target` parsing and the refused shapes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Alis Volat Propriis <[email protected]>
Review of the per-target `extra-rustflags` selection found three gaps: - `--target host-tuple` (or `CARGO_BUILD_TARGET=host-tuple`), which Cargo accepts as the host triple, was looked up as a table named `host-tuple`, so the host's table was silently skipped. It now resolves through the host probe, asked at most once, and counts as the same target as the host's own name. - The host probe ran `rustc` from PATH with the process environment. It now runs the compiler Cargo would run for the command (`RUSTC`, else `CARGO_BUILD_RUSTC`, the command's own value before the inherited one, else `rustc`) with the command's directory and environment changes, so a project `RUSTUP_TOOLCHAIN` reaches it too. The probe lives next to its one caller, and `backend::active_host_triple_in` goes. - The README placed `--target` before `--`; Cargo arguments follow the first `--`. It now says so, names `CARGO_BUILD_TARGET` for commands without Cargo arguments, and lists `host-tuple`, the unread `[build] target` / `[build] rustc`, and that the probe does not go through `RUSTC_WRAPPER`. The error for an unknown triple now also covers a probe that could not run. Tests: `host-tuple` on the command line and in both env sources, its dedup against the host's name, one probe for several mentions, and the named error when the probe fails; the probe's compiler choice, directory and environment; and a fake compiler whose `host:` line is read, and one that fails. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Alis Volat Propriis <[email protected]>
|
Merged as 87bc951, with your authorship. Thank you, @avlp12. The old pin is tagged Next, please open the bloomery PR that moves the This change is useful beyond bloomery. Upstream (NVIDIA/cuda-rust) main still has the flat list, and we found no open issue or PR for it. If you are willing, please send the same patch there under your name. When it merges upstream, we will move our pin to their version. |
|
@avlp12 Your upstream issue NVIDIA#1481 has had no reply for 10 days, and no PR is open for it. Would you open the PR there now, under your name, and link NVIDIA#1481? The patch is 87bc951 here. A PR gives the maintainers code to review. When it merges, we will move our pin to the upstream version. |
…handshakes (NVIDIA#1716) ## What This PR Does Replaces fixed 30ms `thread::sleep` delays with deterministic synchronization in two concurrency/retry unit tests: 1. **`ETXTBSY` Version-Probe Retry Test (`cuda-artifact-finalizer`)** 2. **Single-Flight LTOIR Cache Lock Test (`cuda-host`)** --- ### 1. Deterministic Retry & Lock Contention Hooks Previously, both tests slept for 30ms to approximate thread ordering, which could either fail spuriously on loaded runners or pass without exercising the retry/lock path: ```text BEFORE: ptx.rs: background thread sleeps 30ms, then drops write fd ltoir_cache.rs: winner sleeps 30ms hoping 7 other threads contend on lock AFTER: ptx.rs: `BUSY_RETRY_WAIT` hook drops write fd inside retry #1 (plus a second test asserting all 8 doubling delays: 2ms..256ms) ltoir_cache.rs: `KEY_LOCK_ARRIVALS` condvar holds the build until all 8 threads reach `acquire_key_lock` ``` * Guarantees that `PtxAssembler::from_path` observes `ExecutableFileBusy` at least once before succeeding. * Guarantees that all 8 threads miss the cache fast path and contend on the per-key lockfile before the build publishes. --- ## Verification * **Tests & CI Gates**: * `cargo test -p cuda-artifact-finalizer -p cuda-host --lib`: **PASS** * `cargo clippy -p cuda-artifact-finalizer -p cuda-host --all-targets -- -D warnings`: **PASS** * `cargo oxide fmt --check`: **PASS** Part of NVIDIA#1680 Signed-off-by: Vyncint Ng <[email protected]>
## 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: ```text 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 NVIDIA#1688 --------- Signed-off-by: Praveen Perera <[email protected]>
Requested by Alis
Summary
extra-rustflagsin.cargo/cuda-oxide.tomlis one flat list, and theCARGO_ENCODED_RUSTFLAGScargo-oxide exports hides Cargo's owntarget.<triple>.rustflags. So a project that wants a CPU flag for its host code gives it to every host.Bloomery's
-C target-cpu=znver3, written for an x86_64 workstation, reaches aarch64 builds on DGX Spark. There rustc warns on every crate that znver3 is not a processor, and on some crates it crashes inside LLVM (midagedev/bloomery#13).This change lets a
[target.<triple>]table hold anextra-rustflagslist for one triple. It is the PR asked for in midagedev/bloomery#13. Once it lands, a Bloomery PR moves the[patch]pin and adds the tables.Changes
crates/cargo-oxideonly. No backend or codegen crate changes.Which flags a build gets. It gets the top-level
extra-rustflags, then the table of the triple it builds for. A triple with no table gets the top-level list alone.How the triple is found, in this order:
--targetamong the Cargo arguments. These followcargo oxide build --, in both the--target Xand--target=Xforms. A later--that starts test or program arguments ends the search.CARGO_BUILD_TARGET. The command's own value comes before the inherited one. This also serves commands with no Cargo arguments, such ascargo oxide run <example>.rustc -vV, run as the build would run it:RUSTC, elseCARGO_BUILD_RUSTC, elserustc.host-tuplein 1 or 2 means the host triple from 3. It counts as the same target as the host's own name.Configs without tables. They resolve exactly as before and run no extra
rustc -vV.Named errors. A build stops with a named error instead of guessing when:
host-tupleand the host probe fails.Config errors.
cfg(...)keys, fields other thanextra-rustflags, and wrong types are config errors.cargo oxide doctorreports these too. The target errors above appear only when a build command is constructed.Known limits. Cargo's
[build] targetand[build] rustcin a config file are not read, and the host probe does not go throughRUSTC_WRAPPER. A cross build passes--target. The README says so.The second commit addresses review findings on the first: the
host-tupleresolution, the probe's compiler and environment, and the README. Both commits are signed off. They can be squashed if you prefer one.Testing
FAIL-first.
per_target_extra_rustflags_reach_only_their_triplefails on4da6c138: the table was ignored, and aarch64 got[]. With this change, aarch64 gets-C target-cpu=nativeand no znver3, and x86_64 gets the x86 list.flat_extra_rustflags_still_reach_every_triplepasses before and after. I ran these on a Mac with a stable toolchain.New tests. They cover:
--targetparsing and the refused shapes;host-tupleon the command line, in the command's env and in the inherited env, including dedup against the host's name, one probe for several mentions, and the error when the probe fails;host:line is read, and one that fails.Results.
cargo test -p cargo-oxidecargo fmt -p cargo-oxide -- --checkandcargo clippy -p cargo-oxide --all-targets -- -D warningscleanThe first-commit Spark runs used a pre-sign-off copy of the first commit, with the same tree. On the Mac, the same 3 tests also fail on
4da6c138.End to end in Bloomery. This was on one Spark, inside
nvidia/cuda:13.3.1-devel-ubuntu24.04, with the first commit's cargo-oxide installed.cargo oxide build --arch sm_86 -- -p bloomery-gpu-gates --features gpu --release --bin generate_qwen3moe -vbuilds:--target, so the host fallback picks the aarch64 table.-C target-cpu=native, none carries znver3, and nothing crashes. The log has 20 moreRunninglines, which are build-script runs.bloomery-gpustops on CUDA 13.3 graph APIs. That is why the end-to-end build ran in the container.x86_64. The flag list this code computes for Bloomery's per-target config with
--target x86_64-unknown-linux-gnuis byte-identical to the list the old code computed for the flat config. Both were printed from a test harness, not from an x86 build. The x86 batch that the Bloomery maintainers described in midagedev/bloomery#13 is the real check.Not run. I did not run
just -f cuda-oxide/Justfile check.justandcargo-denywere not installed where I ran, and I ran the cargo-oxide crate's own gates instead.just -f cuda-oxide/Justfile checkpasses. Not run, see above.cargo oxide run <example>passes. Not run: the checks above cover flag selection and a Bloomery build, not running an example on a GPU.Checklist
git commit -s)AI help: Claude (Anthropic) wrote the change and the tests, and ran the checks above on my machines at my direction.
🤖 Generated with Claude Code