fix(cargo-rustc): stabilize higher precedence trailing flags (#14900)

### What does this PR try to resolve?

This was always enabled on nightly since 1.83-nightly (2024-09).
We have no feedback since then, so assume it is a low-impact change.

This stabilization is targeted at 1.85 (2025-02-20)

Fixes #14346

### How should we test and review this PR?

Let's do an FCP.
This commit is contained in:
Ed Page 2024-12-18 14:59:09 +00:00 committed by GitHub
commit 72ffd28eb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 78 deletions

View File

@ -696,11 +696,9 @@ fn prepare_rustc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult
base.inherit_jobserver(&build_runner.jobserver);
build_deps_args(&mut base, build_runner, unit)?;
add_cap_lints(build_runner.bcx, unit, &mut base);
if cargo_rustc_higher_args_precedence(build_runner) {
if let Some(args) = build_runner.bcx.extra_args_for(unit) {
base.args(args);
}
}
base.args(&unit.rustflags);
if build_runner.bcx.gctx.cli_unstable().binary_dep_depinfo {
base.arg("-Z").arg("binary-dep-depinfo");
@ -754,12 +752,6 @@ fn prepare_rustdoc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResu
rustdoc.args(unit.pkg.manifest().lint_rustflags());
if !cargo_rustc_higher_args_precedence(build_runner) {
if let Some(args) = build_runner.bcx.extra_args_for(unit) {
rustdoc.args(args);
}
}
let metadata = build_runner.metadata_for_doc_units[unit];
rustdoc
.arg("-C")
@ -800,11 +792,9 @@ fn prepare_rustdoc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResu
rustdoc::add_output_format(build_runner, unit, &mut rustdoc)?;
if cargo_rustc_higher_args_precedence(build_runner) {
if let Some(args) = build_runner.bcx.extra_args_for(unit) {
rustdoc.args(args);
}
}
rustdoc.args(&unit.rustdocflags);
if !crate_version_flag_already_present(&rustdoc) {
@ -1107,11 +1097,6 @@ fn build_base_args(
cmd.args(unit.pkg.manifest().lint_rustflags());
cmd.args(&profile_rustflags);
if !cargo_rustc_higher_args_precedence(build_runner) {
if let Some(args) = build_runner.bcx.extra_args_for(unit) {
cmd.args(args);
}
}
// `-C overflow-checks` is implied by the setting of `-C debug-assertions`,
// so we only need to provide `-C overflow-checks` if it differs from
@ -2007,19 +1992,3 @@ fn scrape_output_path(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoR
.outputs(unit)
.map(|outputs| outputs[0].path.clone())
}
/// Provides a way to change the precedence of `cargo rustc -- <flags>`.
///
/// This is intended to be a short-live function.
///
/// See <https://github.com/rust-lang/cargo/issues/14346>
fn cargo_rustc_higher_args_precedence(build_runner: &BuildRunner<'_, '_>) -> bool {
build_runner.bcx.gctx.nightly_features_allowed
&& build_runner
.bcx
.gctx
.get_env("__CARGO_RUSTC_ORIG_ARGS_PRIO")
.ok()
.as_deref()
!= Some("1")
}

View File

@ -28,7 +28,7 @@ fn lib() {
p.cargo("rustc --lib -v -- -C debug-assertions=off")
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C debuginfo=2 [..]-C debug-assertions=off[..]-C metadata=[..] [..]--out-dir [ROOT]/foo/target/debug/deps -L dependency=[ROOT]/foo/target/debug/deps`
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C debuginfo=2 [..]-C metadata=[..] [..]--out-dir [ROOT]/foo/target/debug/deps -L dependency=[ROOT]/foo/target/debug/deps[..]-C debug-assertions=off[..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
@ -46,7 +46,7 @@ fn build_main_and_allow_unstable_options() {
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C debuginfo=2 [..]-C metadata=[..] --out-dir [ROOT]/foo/target/debug/deps -L dependency=[ROOT]/foo/target/debug/deps`
[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin --emit=[..]link[..]-C debuginfo=2 [..]-C debug-assertions[..]-C metadata=[..] --out-dir [ROOT]/foo/target/debug/deps -L dependency=[ROOT]/foo/target/debug/deps --extern foo=[ROOT]/foo/target/debug/deps/libfoo-[HASH].rlib`
[RUNNING] `rustc --crate-name foo --edition=2015 src/main.rs [..]--crate-type bin --emit=[..]link[..]-C debuginfo=2 [..]-C metadata=[..] --out-dir [ROOT]/foo/target/debug/deps -L dependency=[ROOT]/foo/target/debug/deps --extern foo=[ROOT]/foo/target/debug/deps/libfoo-[HASH].rlib[..]-C debug-assertions[..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
@ -358,7 +358,7 @@ fn build_with_args_to_one_of_multiple_tests() {
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C debuginfo=2 [..]-C metadata=[..] --out-dir [..]`
[RUNNING] `rustc --crate-name bar --edition=2015 tests/bar.rs [..]--emit=[..]link[..]-C debuginfo=2 [..]-C debug-assertions --test[..]`
[RUNNING] `rustc --crate-name bar --edition=2015 tests/bar.rs [..]--emit=[..]link[..]-C debuginfo=2 [..]--test[..]-C debug-assertions[..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
@ -816,7 +816,6 @@ fn precedence() {
p.cargo("rustc --release -v -- --cfg cargo_rustc -C strip=symbols")
.env("RUSTFLAGS", "--cfg from_rustflags")
.masquerade_as_nightly_cargo(&["cargo-rustc-precedence"])
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[RUNNING] `rustc [..]-C strip=debuginfo [..]--cfg cargo_rustc -C strip=symbols --cfg from_rustflags`
@ -824,34 +823,4 @@ fn precedence() {
"#]])
.run();
// Ensure the short-live env var to work
p.cargo("clean").run();
p.cargo("rustc --release -v -- --cfg cargo_rustc -C strip=symbols")
.env("RUSTFLAGS", "--cfg from_rustflags")
.env("__CARGO_RUSTC_ORIG_ARGS_PRIO", "1")
.masquerade_as_nightly_cargo(&["cargo-rustc-precedence"])
.with_stderr_data(
str![[r#"
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[RUNNING] `rustc [..]--cfg cargo_rustc -C strip=symbols [..]-C strip=debuginfo [..]--cfg from_rustflags`
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
"#]]
)
.run();
// Ensure non-nightly to work as before
p.cargo("clean").run();
p.cargo("rustc --release -v -- --cfg cargo_rustc -C strip=symbols")
.env("RUSTFLAGS", "--cfg from_rustflags")
.with_stderr_data(
str![[r#"
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[RUNNING] `rustc [..]--cfg cargo_rustc -C strip=symbols [..]-C strip=debuginfo [..]--cfg from_rustflags`
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
"#]]
)
.run();
}

View File

@ -106,7 +106,7 @@ fn rustdoc_args() {
p.cargo("rustdoc -v -- --cfg=foo")
.with_stderr_data(str![[r#"
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..] --cfg=foo -C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]`
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..]-C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]--cfg=foo[..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
@ -159,7 +159,7 @@ fn rustdoc_foo_with_bar_dependency() {
[CHECKING] bar v0.0.1 ([ROOT]/bar)
[RUNNING] `rustc [..] [ROOT]/bar/src/lib.rs [..]`
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..] --cfg=foo -C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps --extern [..]`
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..]-C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps --extern [..]--cfg=foo[..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
@ -195,7 +195,7 @@ fn rustdoc_only_bar_dependency() {
.with_stderr_data(str![[r#"
[LOCKING] 1 package to latest compatible version
[DOCUMENTING] bar v0.0.1 ([ROOT]/bar)
[RUNNING] `rustdoc [..] --crate-name bar [ROOT]/bar/src/lib.rs -o [ROOT]/foo/target/doc [..] --cfg=foo -C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]`
[RUNNING] `rustdoc [..] --crate-name bar [ROOT]/bar/src/lib.rs -o [ROOT]/foo/target/doc [..]-C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]--cfg=foo[..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[GENERATED] [ROOT]/foo/target/doc/bar/index.html
@ -213,7 +213,7 @@ fn rustdoc_same_name_documents_lib() {
p.cargo("rustdoc -v -- --cfg=foo")
.with_stderr_data(str![[r#"
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..] --cfg=foo -C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]`
[RUNNING] `rustdoc [..] --crate-name foo src/lib.rs -o [ROOT]/foo/target/doc [..]-C metadata=[..] -L dependency=[ROOT]/foo/target/debug/deps [..]--cfg=foo[..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[GENERATED] [ROOT]/foo/target/doc/foo/index.html