Repository navigation
Open
Labels
A-profilesArea: profilesArea: profilesA-rustflagsArea: rustflagsArea: rustflagsC-tracking-issueCategory: A tracking issue for something unstable.Category: A tracking issue for something unstable.S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.S-waiting-on-feedbackStatus: An implemented feature is waiting on community feedback for bugs or design concerns.Status: An implemented feature is waiting on community feedback for bugs or design concerns.Z-profile-rustflagsNightly: profile-rustflagsNightly: profile-rustflags
Description
Summary
Original issue: #7878
Implementation: #10217
Documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#profile-rustflags-option
The profile-rustflags feature allows setting RUSTFLAGS per-profile.
Status update: #10271 (comment)
For per-target-profiles, see #4897
Unresolved Issues
- Are we ok with rustflags that can be set in
Cargo.toml - How should things interact with rustdoc? If there is a flag that is required to correctly build a project, then
cargo testmay fail if they aren't passed to rustdoc. However, rustdoc doesn't accept all of rustc's flags. Adding arustdocflagsoption seems to be adding more unwanted complexity, though. - This introduces potential backwards-compatibility hazards. For example, when Cargo adds new features or changes the way it invokes rustc, that can interfere with pre-existing flags. Is documenting this sufficient?
- What should the behavior be with build scripts and proc-macros? Those have historically been a pain point with rustflags. Perhaps there should be a default
build-override.rustflags = []. - Profile rustflags are not considered as part of
TargetInfo, which impacts feature resolution and other things.
Future Extensions
No response
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Reacted by Chris Price, León Orell Valerian Liehr, recatek, Lily, justhaug, Howard Zuo, Dzenan Jupic, Elichai Turkel, NotSqrt, Alexander Zaitsev and 48 more
Metadata
Metadata
Assignees
Labels
A-profilesArea: profilesArea: profilesA-rustflagsArea: rustflagsArea: rustflagsC-tracking-issueCategory: A tracking issue for something unstable.Category: A tracking issue for something unstable.S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.S-waiting-on-feedbackStatus: An implemented feature is waiting on community feedback for bugs or design concerns.Status: An implemented feature is waiting on community feedback for bugs or design concerns.Z-profile-rustflagsNightly: profile-rustflagsNightly: profile-rustflags
Type
Projects
- StatusShow more project fieldsUnstable, baking
Activity
bstrie commentedon Apr 29, 2022
I see something like this as necessary for the usability of RFC 3028 (artifact dependencies): #9096 . Historically Cargo has not supported passing arbitrary flags in profile overrides because many of them made no sense to pass to a dependency (e.g.
-C linker). However, with binary artifacts, now literally all rustc flags become something that users will have valid reasons to want to specify. Currently this leads to lots of pain and workarounds with trying to use binary dependencies, either by hacking things up with Cargo config files (which don't work in all cases) or build scripts (which don't support all flags) or environment variables (which are difficult to set in all circumstances).That doesn't mean that this feature is the only way to satisfy this need, but I think anything that does satisfy this need would have to be functionally equivalent to profile-rustflags.
Qubasa commentedon Sep 29, 2022
cargo-features = ["per-package-target", "profile-rustflags"] don't work together.
By this I mean the target does not get applied when profile-rustflags get used.
Will fail with
gcc: error: unrecognized command-line option '--image-base=0x200000'even though target defines ld.lld as linkerMauriceKayser commentedon Jan 28, 2023
ehuss commentedon Jan 28, 2023
MauriceKayser commentedon Jan 29, 2023
nuzzles commentedon Dec 5, 2023
15 remaining items
RalfJung commentedon Aug 10, 2024
JohnstonJ commentedon Oct 5, 2024
weihanglo commentedon Oct 5, 2024
BatmanAoD commentedon Oct 8, 2024
It appears to me that this permits Cargo users to expose themselves to potential soundness issues to which they were previously immune. There's a discussion here about it, but the short version is that when the user has control over per-package Rust-flags, they can choose to compile some packages with
panic=abortand others withpanic=unwind. So far, I think that's still safe, becauserustcitself will refuse to link thepanic=unwindruntime if any crates in the dependency graph were compiled withpanic=abort(unless the relevant part of RFC 1513 is no longer correct). But even if thepanic=abortruntime is linked, it's still possible to run into UB by calling functions in other languages that unwind.If my understanding is correct, there should be a prominent warning in the documentation for this feature that by changing the compilation flags for individual crates, the user loses some of the protections typically afforded to Cargo users.
Additionally, when this feature is stabilized, the "note" in the "Prohibited Linkage Scenarios" section of the reference (not merged yet) should be changed to acknowledge that this feature enables bypassing Cargo's protection against this particular UB:
RalfJung commentedon Oct 8, 2024
Generally the expectation is that rustc must ensure that the crates it is linking are actually compatible for linking. So if this cargo feature can be used to cause unsoundness, that sounds like a soundness bug in rustc to me.
BatmanAoD commentedon Oct 8, 2024
It's not just this feature, though: it's this feature, in conjunction with an FFI call to another language that then starts an unwind operation.
rustccan't detect all the conditions required to cause UB here, which is why we created a lint,ffi_unwind_calls, to help users avoid it.Edit: I think I was mistaken;
rustcshould simply refuse to linked in this case, not produce a binary with UB. rust-lang/rust#97235loynoir commentedon Apr 15, 2025
weihanglo commentedon Apr 15, 2025
epage commentedon Sep 5, 2025
We discussed this briefly in a cargo team meeting on 2025-05-20 and the impression I had is that the following unresolved question is the biggest blocker for stabilizing this feature:
[profile]is present in both.cargo/config.tomlandCargo.tomland afaik we don't specialize some settings to only work in one or the other. This means within our current approach to things, to have this feature for.cargo/config.toml, we'd have to have it also inCargo.toml.The problem with it in
Cargo.tomlis a matter of layer of abstractions:cargo rustccargo buildThe lower level abstractions are more raw where you can hold it wrong, be broken by changes in cargo, could be platform specific, or even be environment specific. Config works well for these because it is low level, out of the users face, and dependent on the environment you are running in and overrideable.
Manifests are part of the primary UX of cargo and, like the basic commands, it is more approachable and offers more guard rails around your actions.
kornelski commentedon Sep 6, 2025
Although I'd like having more control over build settings per profile, I don't think
rustflagsis the right mechanism for it.It's too broad and powerful. When it's treated as an opaque list of options, while also being merged with
rustflagsfrom other sources and Cargo's own flags, it's too easy to end up with conflicting flags.rustflagscan be target-specific and break cross-compilation when applied unconditionally. Supporting per-profilerustflagswithout also supporting per-profile-per-targetrustflagscould force users to choose between supporting profiles and supporting cross-compilation.Linker flags meant for a particular binary don't belong in
[profile]anyway. The same profile could end up being applied to build scripts, proc macros and other binaries that may not need the same linker flags (it will be even more problematic when Cargo starts supporting bin artifacts or dylib Rust dependencies and the linker flags meant for the top-level crate only end up getting applied to random crates in the dependency tree). A better place for linker flags would be in[lib],[[bin]],[[example]], etc.So instead I'd prefer Cargo to fast-track adding Cargo-native options for the features that users currently need
rustflagsfor: #12739 #5881ktlo(workspace): stabilize profile.rustflags in profiling profile
(PROJECT) NFC TODO use rustflags when stable
CI: override target-cpu=native via --config to fix clippy SIGILL
Cargo.toml: Remove line-tables-only for development builds