Skip to content

Commit

Permalink
feat: Stabilize MSRV-aware resolver config
Browse files Browse the repository at this point in the history
This includes
- `cargo generate-lockfile --ignore-rust-version`
- `cargo update --ignore-rust-version`

This does not include
- `edition = "2024"`
- `resolver = "3"`
  • Loading branch information
epage committed Oct 4, 2024
1 parent 42a774b commit 7975913
Show file tree
Hide file tree
Showing 14 changed files with 10 additions and 217 deletions.
12 changes: 1 addition & 11 deletions src/bin/cargo/commands/generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
13 changes: 1 addition & 12 deletions src/bin/cargo/commands/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
31 changes: 6 additions & 25 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
2 changes: 0 additions & 2 deletions tests/testsuite/cargo_add/rust_version_ignore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![""])
Expand Down
2 changes: 0 additions & 2 deletions tests/testsuite/cargo_add/rust_version_incompatible/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![""])
Expand Down
2 changes: 0 additions & 2 deletions tests/testsuite/cargo_add/rust_version_latest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![""])
Expand Down
2 changes: 0 additions & 2 deletions tests/testsuite/cargo_add/rust_version_older/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![""])
Expand Down
2 changes: 0 additions & 2 deletions tests/testsuite/cargo_add/rustc_ignore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![""])
Expand Down
2 changes: 0 additions & 2 deletions tests/testsuite/cargo_add/rustc_incompatible/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![""])
Expand Down
2 changes: 0 additions & 2 deletions tests/testsuite/cargo_add/rustc_latest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![""])
Expand Down
2 changes: 0 additions & 2 deletions tests/testsuite/cargo_add/rustc_older/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![""])
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_update/help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7975913

Please sign in to comment.