Repository navigation
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) <noreply@anthropic.com> Signed-off-by: Alis Volat Propriis <alisvolatprop12@proton.me>
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) <noreply@anthropic.com> Signed-off-by: Alis Volat Propriis <alisvolatprop12@proton.me>
avlp12
force-pushed
the
feat/cargo-oxide-per-target-extra-rustflags
branch
from
November 15, 2026 15:27
a77f18a to
54eb964
Compare
avlp12
marked this pull request as ready for review
November 15, 2026 15:28
This was referenced Nov 16, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1481.
extra-rustflagsin.cargo/cuda-oxide.tomlis one flat list, and theCARGO_ENCODED_RUSTFLAGSthat cargo-oxide exports hides Cargo's owntarget.<triple>.rustflags. A CPU flag meant for one host therefore reaches every host: a config carrying-C target-cpu=znver3for an x86_64 workstation breaks the build on an aarch64 DGX Spark. This PR adds[target.<triple>]tables whoseextra-rustflagsare appended after the top-level list for the triple being built.Changes
commands/context.rs: parse[target.<triple>]tables intotarget_extra_rustflags.extra_rustflags_for(triple)returns the top-level list, then the table of that triple.cfg(...)keys, fields other thanextra-rustflags, and non-table values are named errors.commands/codegen_env.rs: find the triple a command builds for, in this order:--targetamong the Cargo arguments (after the first--; a later--ends the search);CARGO_BUILD_TARGET;rustc -vV, run as the build would run it (RUSTC, elseCARGO_BUILD_RUSTC, elserustc, with the command's directory and environment).host-tupleresolves to the host triple. Two different targets in one command are refused.[target.*]tables behaves as before and runs no extrarustc -vV.README.md: document the tables and the lookup order.commands/tests.rs: 12 new tests for the selection rules, the host probe, and the config-shape errors.Not covered, as noted in #1481:
[build] targetand[build] rustcin a Cargo config file are not read, and the host probe does not go throughRUSTC_WRAPPER. I am happy to change either if maintainers prefer.Testing
Run on x86_64 Linux (WSL2) with the toolchain pinned in
cuda-oxide/rust-toolchain.toml(1.99.1), on top ofmainat 348895e.justis not installed on that machine, so I ran the commands of thecheckrecipe directly.cargo test -p cargo-oxide: 301 passed onmain, 313 passed on this branch, 0 failed on both.checkstepfmt-checkclippy(workspace andrustc-codegen-cuda,-D warnings)testtest-cudacheck-intrinsics(withbase_ref=origin/main)doc-checkcheck-guardscheck-*.shscripts andcheck-spdx-headers.shpass; four items did not run (below)Four guard items could not run on that machine, and they fail the same way on
mainthere:check-device-only-build.sh(offline, the fixture's crates were not available), thecargo denysteps andcheck-example-license-policy.sh(cargo-denynot installed), andcheck-dependency-licenses.sh(needs the root-workspace toolchain 1.98.0, not installed). The change touches no manifest or lock file.The version before this rebase was also tested on DGX Spark (aarch64); those results are in #1481.
just -f cuda-oxide/Justfile checkpasses (the local mirror of CI: fmt, clippy, tests, guards, docs) — all steps pass except the four guard items above, which did not run locallycargo oxide run <example>passes, orcuda-oxide/scripts/smoketest.sh -o '^<example>$'— not run on this branchChecklist
git commit -s)git commit -S)🤖 Generated with Claude Code