rust-lang / cargo

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

Tracking Issue: Exposing RUSTFLAGS in cargo #12739

Open epage opened 1 year ago

epage commented 1 year ago

RUSTFLAGS is a low level mechanism

This is meant to track the RUSTFLAGS that should have a cargo-native way of being exposed. This won't always be one-to-one mappings and won't necessarily cover every rustc CLI feature.

Note: Keep in mind the cargo-native solution could live in:

See also

soloturn commented 7 months ago

@epage is this the same as people always discuss when finding the config language toml is ok, but not ideal? compared to:

epage commented 7 months ago

This issue is about finding ways to expose environment config as project config and is unrelated to what format is used for either

kornelski commented 2 months ago

Would it make sense to support arbitrary unstable rustc flags, which are project-specific or profile-specific?

For example, there's -Z location-detail=none that I'd like to set in release profile.

Cargo probably won't rush to add first-class options for rustc features that haven't been stabilized yet. OTOH without Cargo's help, they still require RUSTFLAGS.

Maybe something like:

cargo-features = ["unstable"]

[profiles.release]
unstable = {
    location-detail = "none"
}
epage commented 2 months ago

Would profile rustflags be a way of handling this since you are already using unstable features anyways?

This issue is more about how to create abstractions for uses of rustflags. Creating another pass-through mechanism doesn't seem in the spirit of this issue.

Kixunil commented 2 months ago

Some perspective from various production projects:

epage commented 2 months ago

Please keep in mind that this is a tracking issue. If you have specific requests, feel free to open an issue and we can add it to this. Trying to have too much design discussion for these individual items here will likely get them lost in the noise as this tracking issue covers a wide breadth of features.

having only the [lints] table and no command-line options is not sufficient - there's a use case when one wants to simply check if a crate uses unsafe to decide whether it's worth running miri on the crate or not. This also implies that --forbid is needed. (The check is cargo check with -F unsafe-code and if it fails run miri, skip otherwise.)

Do we need to provide an abstraction over this or continue to leave it to RUSTFLAGS?

Generally, it's not sufficient to have something configurable via Cargo.toml because CI might need to change things and patching a toml to do that is fragile.

This issue is not prescriptive about where they may live and where they will live depends on circumstances.

They could live

12738 is our issue for identifying environment config (.cargo/config.toml) that should live in project config (Cargo.toml) and find a way to migrate it.