-
Couldn't load subscription status.
- Fork 2.7k
Description
Problem
https://doc.rust-lang.org/cargo/reference/config.html#environment-variables says:
Cargo can also be configured through environment variables in addition to the TOML configuration files. For each configuration key of the form foo.bar the environment variable CARGO_FOO_BAR can also be used to define the value.
This unfortunately isn't true for e.g. target.x86_64-unknown-linux-gnu.foo.rustc_flags.
Cc: @thomcc
Steps
cargo new testcase --libcd testcase- Edit
Cargo.tomlto addlinks = "foo" echo "fn main() { panic!(); }" > build.rsenv CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_FOO_RUSTC_FLAGS="" cargo build(assuming you're on x86_64-unknown-linux-gnu)
The build script will still be executed.
The environment variable is recognized by cargo config, which could be a source of confusion.
$ env CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_FOO_RUSTC_FLAGS="" cargo +nightly -Z unstable-options config get target.x86_64-unknown-linux-gnu.foo.rustc_flags
target.x86_64-unknown-linux-gnu.foo.rustc_flags = ""
Obviously, setting the same variable via .cargo/config.toml works.
Possible Solution(s)
cargo::util::config::load_config_table calls cargo::util::config::Config::get_table, which explicitly leaves taking environment variables into account to its callers, but it doesn't. Making either of those handle environment variables would solve the problem. If I didn't miss anything, the only two other uses of Config::get_table are ConfigMapAccess::new_map and ConfigMapAccess::new_struct, and the former handles environment variables. I'm not sure why the latter doesn't, but maybe it should, at which point it would seem like get_table should be doing it.
Notes
No response
Version
No response