cargo
cargo copied to clipboard
Encoded `CARGO_TARGET_<triple>_RUSTFLAGS` just like `CARGO_ENCODED_RUSTFLAGS`?
Problem
According to https://doc.rust-lang.org/cargo/reference/environment-variables.html there's CARGO_ENCODED_RUSTFLAGS to properly escape independent arguments with separators, when those arguments themselves (i.e. file paths) already contain spaces. However, no similar environment argument appears to exist for CARGO_TARGET_<triple>_RUSTFLAGS so that I cannot set up per-target RUSTFLAGS containing arguments with spaces.
Proposed Solution
Would it be possible to add CARGO_TARGET_<triple>_ENCODED_RUSTFLAGS?
Notes
No response
If you have access to Command, config command line override is available. See a relevant discussion #14381 and other alternatives in https://github.com/rust-lang/cargo/issues/3686#issuecomment-1324128725.
See also #10462
I am slightly inclined to close, given that there are a number of alternatives listed in https://github.com/rust-lang/cargo/issues/3686#issuecomment-1324128725.
I can see how it seems like there is a correlation between RUSTFLAGS and CARGO_TARGET_*_RUSTFLAGS, and thus would have the same extension as CARGO_ENCODED_RUSTFLAGS and CARGO_TARGET_*_ENCODED_RUSTFLAGS, but that's not how it works in cargo. The target flags are driven by the config system, whereas RUSTFLAGS (and CARGO_ENCODED_RUSTFLAGS) is a separate thing.
I'm a little concerned about the complexity of the number of ways that rustflags are set, and the interaction with things like target-applies-to-host and host-config.
I also have a slight inclination to lean on something like the undocumented -Z advanced-env, since that would be a general-purpose solution that would address all TOML config values. However, I would strongly encourage using --config instead.