rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.78k stars 2.42k forks source link

Encoded `CARGO_TARGET_<triple>_RUSTFLAGS` just like `CARGO_ENCODED_RUSTFLAGS`? #14398

Open MarijnS95 opened 3 months ago

MarijnS95 commented 3 months ago

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

weihanglo commented 3 months ago

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.

epage commented 3 weeks ago

See also #10462

ehuss commented 3 weeks ago

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.