-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Open
Labels
A-documenting-cargo-itselfArea: Cargo's documentationArea: Cargo's documentationA-rustflagsArea: rustflagsArea: rustflagsC-bugCategory: bugCategory: bugE-hardExperience: HardExperience: HardS-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.Z-cargo-configNightly: cargo config subcommandNightly: cargo config subcommand
Description
Problem
cargo config get build.rustdocflags
and cargo config get build.rustflags
do not seem to behave as I would have expected.
If the respective environment variables are set (i.e. RUSTDOCFLAGS
and RUSTFLAGS
) but no value is set in .cargo/config.toml
, I'd expect the environment variable value to be returned.
Instead, the command fails with:
error: config value `build.rustdocflags` is not set
Steps
export RUSTDOCFLAGS="--cfg tokio_unstable"
cargo -Z unstable-options config get build.rustdocflags
and
export RUSTFLAGS="--cfg tokio_unstable"
cargo -Z unstable-options config get build.rustflags
Possible Solution(s)
No response
Notes
Is this intended behaviour?
Version
No response
Metadata
Metadata
Assignees
Labels
A-documenting-cargo-itselfArea: Cargo's documentationArea: Cargo's documentationA-rustflagsArea: rustflagsArea: rustflagsC-bugCategory: bugCategory: bugE-hardExperience: HardExperience: HardS-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.Z-cargo-configNightly: cargo config subcommandNightly: cargo config subcommand
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
weihanglo commentedon May 5, 2023
I would say it is kinda intentional. The Cargo configuration system only cares about environment variables starting with
CARGO_
12. Or more precisely, those that listed in the doc are officially supported; those not may be subject to change.Try this instead:
However, we must admit that the story around rustflags management is a bit messy.
Footnotes
https://github.com/rust-lang/cargo/blob/2d693e20ea2dd3a55af94c56372c960503a6c673/src/cargo/util/config/key.rs#L31 ↩
https://doc.rust-lang.org/cargo/reference/config.html#environment-variables ↩
LukeMathWalker commentedon May 5, 2023
I see, but the docs do mention
RUSTFLAGS
as well:LukeMathWalker commentedon May 5, 2023
The usecase here is being able to accurately predict what extra flags will be passed when invoking
rustc
orrustdoc
without actually performing the invocation.If
cargo config get
shows a value that differs from whatcargo
actually does, its value is greatly diminished.weihanglo commentedon May 6, 2023
Since
RUSTFLAGS
is essentially not a cargo configuration, I guess it won't be included incargo config get
in the near future. #11452 (comment) also pointed out this issue. This comment also listed ways to configure rustflags.For now, I'll triage this issue as A-documenting-cargo-itselfArea: Cargo's documentation
. Like you just said in #12087 (comment), we can improve the doc of
build.rustflags
a bit. We can state that settingCARGO_ENCODED_RUSTFLAGS
orRUSTFLAGS
won't set the config value. Instead, we can say they affectbuild.rustflags
.Bhardwaj-Himanshu commentedon May 7, 2023
After going through the discussion above, a with very little knowledge of what's going on, I think you guys are talking about changing this-
to-
But Idk what N-stating a line means, so if you could shower some more light on the issue,I would be happy to do the doc work for this issue!
Thanks
LukeMathWalker commentedon May 7, 2023
I'd like to understand this better:
Are we saying that
cargo
ignores entirelyRUSTFLAGS
and it'srustc
that picks it up on its own? If that's the case, I agree, this is a documentation issue.But if that is not the case (i.e.
cargo
does look atRUSTFLAGS
and performs some behaviour according to its value), I think the documentation is correct and this should be treated as a bug incargo config
.My impression is that the latter is happening.
6 remaining items
CARGO_BUILD_RUSTFLAGS
#12257cnpryer commentedon Jul 16, 2023
Is there any interest in this?
LukeMathWalker commentedon Jul 16, 2023
Most definitely—it would be a solution here.
weihanglo commentedon Jul 16, 2023
To avoid any misleading, I'll relabel this issue for some solution like
cargo config rustflags
. And the solution might involve lots of different place in the codebase, so it might be a bit not easy.@rustbot label +S-needs-design -S-accepted +E-hard -E-easy
cargo config get
print warning if proxy config found in git/libcurl ? #12572