-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add target-specific RUSTFLAGS variants #10462
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
I did, as part of this, discover a problem with cargo/src/cargo/core/compiler/build_context/target_info.rs Lines 616 to 619 in 0a3f2b4
and instead takes the path intended for host artifacts here cargo/src/cargo/core/compiler/build_context/target_info.rs Lines 621 to 625 in 0a3f2b4
The net result of this is that if This limitation continues to apply with this PR — if To fix this, I think we need a way to tell cargo/src/cargo/core/compiler/build_context/target_info.rs Lines 595 to 602 in fb47df7
|
/cc @messense given #4423 (comment) |
Thanks for the PR, but I'm going to be stepping down from the Cargo team so I'm going to un-assign myself from this. The Cargo team will help review this when they get a chance. |
☔ The latest upstream changes (presumably #10486) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #10566) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the extremely late review 😅
The implementation itself works for me, though I am entirely not sure whether this is a thing we are going to merge. As you know, we already have a few stable and unstable features interacting with each other in this area. It might be more confusing for users who want to tweak their compiler flags. Specifically, we have a bunch of ways to set them
CARGO_ENCODED_RUSTFLAGS
RUSTFLAGS
target.<cfg|triple>.rustflags
build.rustflags
profile.<name>.rustflags
cargo rustc -- <some flags>
cargo build --config <value>
And maybe more. I could have missed some. I wonder how we teach newcomers about this mess 😞
I totally understand the motivations behind your pull request and other features. Just feel a bit overwhelmed.
`HOST_RUSTFLAGS` allows setting flags to be passed to rustc for | ||
host-artifacts (like build scripts) when cross-compiling, or _all_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this interact with artifact dependencies (RFC 3028)?
If an artifact dependency specified with a { …, target = "<triple>" }
, even without --target
specified, Cargo will still try to build that dependency on that target platform.
- Should it receive
HOST_RUSTFLAGS
orTARGET_RUSTFLAGS
? - If it is a build-deps, which one it should get?
More specific flags always take precedence over less specific ones, with | ||
ties broken in favor of `CARGO_ENCODED_RUSTFLAGS`. So, for example, if | ||
`RUSTFLAGS_$TARGET` and `TARGET_CARGO_ENCODED_RUSTFLAGS` are both | ||
specified, `RUSTFLAGS_$TARGET` would be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to make an example of this precedence chain? Such as
cargo/src/doc/src/reference/profiles.md
Lines 422 to 430 in 99ff79e
The precedence for which value is used is done in the following order (first | |
match wins): | |
1. `[profile.dev.package.name]` — A named package. | |
2. `[profile.dev.package."*"]` — For any non-workspace member. | |
3. `[profile.dev.build-override]` — Only for build scripts, proc macros, and | |
their dependencies. | |
4. `[profile.dev]` — Settings in `Cargo.toml`. | |
5. Default values built-in to Cargo. |
Generic = 0, | ||
Kind = 1, | ||
Target = 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why setting discriminant manually, supposed rustc can derive Ord
with default discriminants?
if allow_generic { | ||
env::var(var_base).ok().map(|v| (Specificity::Generic, v)) | ||
} else { | ||
None | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) I believe here we can use allow_generic.then(…)
🎉
if a.is_empty() { | ||
(s, Vec::new()) | ||
} else { | ||
(s, a.split('\x1f').map(str::to_string).collect()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If str::split
is a no-op for empty string, could we reduce these to one line?
Target = 2, | ||
} | ||
|
||
fn get_var_variants( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new functions and enum are not immediately clear to me. Should we add some docs for them?
@@ -606,22 +606,35 @@ fn env_args( | |||
kind: CompileKind, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also update doc comment for fn env_args
?
As this is waiting on the author for a couple of years for an issue without an acknowledged solution by the Cargo team, I'm going to go ahead and close this. I'd recommend picking this back up by proposing the solution on the issue and getting consensus before moving on to a PR, per our policy at https://doc.crates.io/contrib/process/working-on-cargo.html |
@epage Seems reasonable to me 👍 I have since moved on from the place where I needed this, so don't have much incentive to continue pushing on it. The reason it didn't move earlier was mostly because it didn't seem like there was a clear path forward that the Cargo team would be comfortable with (which is also fair, RUSTFLAGS is a thorny thing already), and I didn't have any radically good solutions to those concerns. I still think something like this would be valuable, so hoping this might at least serve as a useful starting point to someone else to pick up from at some later point in time. |
What does this PR try to resolve?
This is a continuation from the discussion in #10395 (comment), and is aimed at being able to solve problems like #4423 by extending the current
RUSTFLAGS
environment variable to also have per-target variants as in rust-lang/cc-rs#9.To quote the unstable docs I wrote for the feature:
How should we test and review this PR?
The PR includes two new tests that check for the expected behavior of these flags, and how they behave when more than one is provided.