feat: Stabilize MSRV-aware resolver config

This includes
- `cargo generate-lockfile --ignore-rust-version`
- `cargo update --ignore-rust-version`

This does not include
- `edition = "2024"`
- `resolver = "3"`
This commit is contained in:
Ed Page 2024-09-19 13:06:58 -05:00
parent 6f92aaa31f
commit 0498e84f89
14 changed files with 10 additions and 217 deletions

View File

@ -8,23 +8,13 @@ pub fn cli() -> Command {
.arg_silent_suggestion()
.arg_manifest_path()
.arg_lockfile_path()
.arg_ignore_rust_version_with_help(
"Ignore `rust-version` specification in packages (unstable)",
)
.arg_ignore_rust_version_with_help("Ignore `rust-version` specification in packages")
.after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help generate-lockfile</>` for more detailed information.\n"
))
}
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
if args.honor_rust_version().is_some() {
gctx.cli_unstable().fail_if_stable_opt_custom_z(
"--ignore-rust-version",
9930,
"msrv-policy",
gctx.cli_unstable().msrv_policy,
)?;
}
let ws = args.workspace(gctx)?;
ops::generate_lockfile(&ws)?;
Ok(())

View File

@ -53,24 +53,13 @@ pub fn cli() -> Command {
)
.arg_manifest_path()
.arg_lockfile_path()
.arg_ignore_rust_version_with_help(
"Ignore `rust-version` specification in packages (unstable)",
)
.arg_ignore_rust_version_with_help("Ignore `rust-version` specification in packages")
.after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help update</>` for more detailed information.\n"
))
}
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
if args.honor_rust_version().is_some() {
gctx.cli_unstable().fail_if_stable_opt_custom_z(
"--ignore-rust-version",
9930,
"msrv-policy",
gctx.cli_unstable().msrv_policy,
)?;
}
let mut ws = args.workspace(gctx)?;
if args.is_present_with_zero_values("package") {

View File

@ -306,31 +306,12 @@ impl<'gctx> Workspace<'gctx> {
}
}
}
match self.gctx().get::<CargoResolverConfig>("resolver") {
Ok(CargoResolverConfig {
incompatible_rust_versions: Some(incompatible_rust_versions),
}) => {
if self.gctx().cli_unstable().msrv_policy {
self.resolve_honors_rust_version =
incompatible_rust_versions == IncompatibleRustVersions::Fallback;
} else {
self.gctx()
.shell()
.warn("ignoring `resolver` config table without `-Zmsrv-policy`")?;
}
}
Ok(CargoResolverConfig {
incompatible_rust_versions: None,
}) => {}
Err(err) => {
if self.gctx().cli_unstable().msrv_policy {
return Err(err);
} else {
self.gctx()
.shell()
.warn("ignoring `resolver` config table without `-Zmsrv-policy`")?;
}
}
if let CargoResolverConfig {
incompatible_rust_versions: Some(incompatible_rust_versions),
} = self.gctx().get::<CargoResolverConfig>("resolver")?
{
self.resolve_honors_rust_version =
incompatible_rust_versions == IncompatibleRustVersions::Fallback;
}
Ok(())

View File

@ -20,13 +20,11 @@ fn case() {
let cwd = &project_root;
snapbox::cmd::Command::cargo_ui()
.arg("-Zmsrv-policy")
.arg("add")
.arg("--ignore-rust-version")
.arg_line("rust-version-user")
.current_dir(cwd)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.code(0)
.stdout_eq(str![""])

View File

@ -23,12 +23,10 @@ fn case() {
let cwd = &project_root;
snapbox::cmd::Command::cargo_ui()
.arg("-Zmsrv-policy")
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.failure()
.stdout_eq(str![""])

View File

@ -20,12 +20,10 @@ fn case() {
let cwd = &project_root;
snapbox::cmd::Command::cargo_ui()
.arg("-Zmsrv-policy")
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.success()
.stdout_eq(str![""])

View File

@ -20,12 +20,10 @@ fn case() {
let cwd = &project_root;
snapbox::cmd::Command::cargo_ui()
.arg("-Zmsrv-policy")
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.success()
.stdout_eq(str![""])

View File

@ -23,13 +23,11 @@ fn case() {
let cwd = &project_root;
snapbox::cmd::Command::cargo_ui()
.arg("-Zmsrv-policy")
.arg("add")
.arg("--ignore-rust-version")
.arg_line("rust-version-user")
.current_dir(cwd)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.code(0)
.stdout_eq(str![""])

View File

@ -17,12 +17,10 @@ fn case() {
let cwd = &project_root;
snapbox::cmd::Command::cargo_ui()
.arg("-Zmsrv-policy")
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.failure()
.stdout_eq(str![""])

View File

@ -23,12 +23,10 @@ fn case() {
let cwd = &project_root;
snapbox::cmd::Command::cargo_ui()
.arg("-Zmsrv-policy")
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.success()
.stdout_eq(str![""])

View File

@ -23,12 +23,10 @@ fn case() {
let cwd = &project_root;
snapbox::cmd::Command::cargo_ui()
.arg("-Zmsrv-policy")
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.success()
.stdout_eq(str![""])

View File

@ -51,7 +51,7 @@
</tspan>
<tspan x="10px" y="298px"><tspan> </tspan><tspan class="fg-cyan bold">--lockfile-path</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;PATH&gt;</tspan><tspan> Path to Cargo.lock (unstable)</tspan>
</tspan>
<tspan x="10px" y="316px"><tspan> </tspan><tspan class="fg-cyan bold">--ignore-rust-version</tspan><tspan> Ignore `rust-version` specification in packages (unstable)</tspan>
<tspan x="10px" y="316px"><tspan> </tspan><tspan class="fg-cyan bold">--ignore-rust-version</tspan><tspan> Ignore `rust-version` specification in packages</tspan>
</tspan>
<tspan x="10px" y="334px"><tspan> </tspan><tspan class="fg-cyan bold">--locked</tspan><tspan> Assert that `Cargo.lock` will remain unchanged</tspan>
</tspan>

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -67,7 +67,7 @@
</tspan>
<tspan x="10px" y="442px"><tspan> </tspan><tspan class="fg-cyan bold">--lockfile-path</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;PATH&gt;</tspan><tspan> Path to Cargo.lock (unstable)</tspan>
</tspan>
<tspan x="10px" y="460px"><tspan> </tspan><tspan class="fg-cyan bold">--ignore-rust-version</tspan><tspan> Ignore `rust-version` specification in packages (unstable)</tspan>
<tspan x="10px" y="460px"><tspan> </tspan><tspan class="fg-cyan bold">--ignore-rust-version</tspan><tspan> Ignore `rust-version` specification in packages</tspan>
</tspan>
<tspan x="10px" y="478px"><tspan> </tspan><tspan class="fg-cyan bold">--locked</tspan><tspan> Assert that `Cargo.lock` will remain unchanged</tspan>
</tspan>

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

@ -218,8 +218,6 @@ fn resolve_with_rust_version() {
p.cargo("generate-lockfile --ignore-rust-version")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
@ -237,8 +235,6 @@ foo v0.0.1 ([ROOT]/foo)
p.cargo("generate-lockfile")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions
@ -293,8 +289,6 @@ fn resolve_with_rustc() {
p.cargo("generate-lockfile --ignore-rust-version")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
@ -314,8 +308,6 @@ foo v0.0.1 ([ROOT]/foo)
p.cargo("generate-lockfile")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions
@ -368,8 +360,6 @@ fn resolve_with_backtracking() {
p.cargo("generate-lockfile --ignore-rust-version")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
@ -388,8 +378,6 @@ foo v0.0.1 ([ROOT]/foo)
// Ideally we'd pick `has-rust-version` 1.6.0 which requires backtracking
p.cargo("generate-lockfile")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions
@ -484,8 +472,6 @@ fn resolve_with_multiple_rust_versions() {
p.cargo("generate-lockfile --ignore-rust-version")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 6 packages to latest compatible versions
@ -505,8 +491,6 @@ higher v0.0.1 ([ROOT]/foo)
p.cargo("generate-lockfile")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 6 packages to latest Rust 1.50.0 compatible versions
@ -531,77 +515,6 @@ higher v0.0.1 ([ROOT]/foo)
.run();
}
#[cargo_test]
fn resolve_unstable_config_on_stable() {
Package::new("only-newer", "1.6.0")
.rust_version("1.65.0")
.file("src/lib.rs", "fn other_stuff() {}")
.publish();
Package::new("newer-and-older", "1.5.0")
.rust_version("1.55.0")
.file("src/lib.rs", "fn other_stuff() {}")
.publish();
Package::new("newer-and-older", "1.6.0")
.rust_version("1.65.0")
.file("src/lib.rs", "fn other_stuff() {}")
.publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
rust-version = "1.60.0"
[dependencies]
only-newer = "1.0.0"
newer-and-older = "1.0.0"
"#,
)
.file("src/main.rs", "fn main(){}")
.build();
p.cargo("generate-lockfile")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.with_stderr_data(str![[r#"
[WARNING] ignoring `resolver` config table without `-Zmsrv-policy`
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
"#]])
.run();
p.cargo("tree")
.with_stdout_data(str![[r#"
foo v0.0.1 ([ROOT]/foo)
newer-and-older v1.6.0
only-newer v1.6.0
"#]])
.run();
p.cargo("generate-lockfile")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "non-existent")
.with_stderr_data(str![[r#"
[WARNING] ignoring `resolver` config table without `-Zmsrv-policy`
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
"#]])
.run();
p.cargo("tree")
.with_stdout_data(str![[r#"
foo v0.0.1 ([ROOT]/foo)
newer-and-older v1.6.0
only-newer v1.6.0
"#]])
.run();
}
#[cargo_test(nightly, reason = "edition2024 in rustc is unstable")]
fn resolve_edition2024() {
Package::new("only-newer", "1.6.0")
@ -823,45 +736,6 @@ Caused by:
.run();
}
#[cargo_test]
fn generate_lockfile_ignore_rust_version_is_unstable() {
Package::new("bar", "1.5.0")
.rust_version("1.55.0")
.file("src/lib.rs", "fn other_stuff() {}")
.publish();
Package::new("bar", "1.6.0")
.rust_version("1.65.0")
.file("src/lib.rs", "fn other_stuff() {}")
.publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
rust-version = "1.60.0"
[dependencies]
bar = "1.0.0"
"#,
)
.file("src/main.rs", "fn main(){}")
.build();
p.cargo("generate-lockfile --ignore-rust-version")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] the `--ignore-rust-version` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
See https://github.com/rust-lang/cargo/issues/9930 for more information about the `--ignore-rust-version` flag.
"#]])
.run();
}
#[cargo_test]
fn update_msrv_resolve() {
Package::new("bar", "1.5.0")
@ -892,28 +766,15 @@ fn update_msrv_resolve() {
p.cargo("update")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest Rust 1.60.0 compatible version
[ADDING] bar v1.5.0 (available: v1.6.0, requires Rust 1.65.0)
"#]])
.run();
p.cargo("update --ignore-rust-version")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] the `--ignore-rust-version` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
See https://github.com/rust-lang/cargo/issues/9930 for more information about the `--ignore-rust-version` flag.
"#]])
.run();
p.cargo("update --ignore-rust-version")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
@ -953,8 +814,6 @@ fn update_precise_overrides_msrv_resolver() {
p.cargo("update")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest Rust 1.60.0 compatible version
@ -964,8 +823,6 @@ fn update_precise_overrides_msrv_resolver() {
.run();
p.cargo("update --precise 1.6.0 bar")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[UPDATING] bar v1.5.0 -> v1.6.0 (requires Rust 1.65.0)
@ -1010,8 +867,6 @@ fn check_msrv_resolve() {
p.cargo("check --ignore-rust-version")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(
str![[r#"
[UPDATING] `dummy-registry` index
@ -1040,8 +895,6 @@ foo v0.0.1 ([ROOT]/foo)
std::fs::remove_file(p.root().join("Cargo.lock")).unwrap();
p.cargo("check")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions
@ -1086,8 +939,6 @@ fn cargo_install_ignores_msrv_config() {
"CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS",
"fallback",
)
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[DOWNLOADING] crates ...
@ -1205,8 +1056,6 @@ fn report_rust_versions() {
p.cargo("update")
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 9 packages to latest Rust 1.60.0 compatible versions