Skip to content

Commit

Permalink
fix(config): Adjust MSRV resolve config field name / values
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 24, 2024
1 parent ca330a2 commit feecbd7
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 119 deletions.
8 changes: 4 additions & 4 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::util::lints::{
};
use crate::util::toml::{read_manifest, InheritableFields};
use crate::util::{
context::CargoResolverConfig, context::CargoResolverPrecedence, context::ConfigRelativePath,
context::CargoResolverConfig, context::ConfigRelativePath, context::IncompatibleRustVersions,
Filesystem, GlobalContext, IntoUrl,
};
use cargo_util::paths;
Expand Down Expand Up @@ -320,19 +320,19 @@ impl<'gctx> Workspace<'gctx> {
}
match self.gctx().get::<CargoResolverConfig>("resolver") {
Ok(CargoResolverConfig {
something_like_precedence: Some(precedence),
incompatible_rust_versions: Some(incompatible_rust_versions),
}) => {
if self.gctx().cli_unstable().msrv_policy {
self.resolve_honors_rust_version =
precedence == CargoResolverPrecedence::SomethingLikeRustVersion;
incompatible_rust_versions == IncompatibleRustVersions::Fallback;
} else {
self.gctx()
.shell()
.warn("ignoring `resolver` config table without `-Zmsrv-policy`")?;
}
}
Ok(CargoResolverConfig {
something_like_precedence: None,
incompatible_rust_versions: None,
}) => {}
Err(err) => {
if self.gctx().cli_unstable().msrv_policy {
Expand Down
8 changes: 4 additions & 4 deletions src/cargo/util/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2680,14 +2680,14 @@ impl BuildTargetConfig {
#[derive(Debug, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct CargoResolverConfig {
pub something_like_precedence: Option<CargoResolverPrecedence>,
pub incompatible_rust_versions: Option<IncompatibleRustVersions>,
}

#[derive(Debug, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub enum CargoResolverPrecedence {
SomethingLikeMaximum,
SomethingLikeRustVersion,
pub enum IncompatibleRustVersions {
Allow,
Fallback,
}

#[derive(Deserialize, Default)]
Expand Down
16 changes: 8 additions & 8 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,26 +338,26 @@ This was stabilized in 1.79 in [#13608](https://github.com/rust-lang/cargo/pull/
### MSRV-aware resolver

`-Zmsrv-policy` allows access to an MSRV-aware resolver which can be enabled with:
- `resolver.something-like-precedence` config field
- `resolver.incompatible-rust-versions` config field
- `workspace.resolver = "3"` / `package.resolver = "3"`
- `package.edition = "2024"` (only in workspace root)

The resolver will prefer dependencies with a `package.rust-version` that is the same or older than your project's MSRV.
Your project's MSRV is determined by taking the lowest `package.rust-version` set among your workspace members.
If there is none set, your toolchain version will be used with the intent to pick up the version from rustup's `rust-toolchain.toml`, if present.

#### `resolver.something-like-precedence`
#### `resolver.incompatible-rust-versions`
* Type: string
* Default: "something-like-maximum"
* Environment: `CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE`
* Default: "allow"
* Environment: `CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS`

Select which policy should be used when resolving dependencies. Values include
- `something-like-maximum`: prefer highest compatible versions of a package
- `something-like-rust-version`: prefer versions of packages compatible with your project's Rust version
Select how packages with incompatible rust-versions should be resolved. Values include:
- `allow`: treat them like any other dependency
- `fallback`: only consider them if no other dependency version matched

Can be overridden with
- `--ignore-rust-version` CLI option
- Setting the dependency's version requirement too high
- Setting the dependency's version requirement above any version that is rust-version compatible
- Specifying the version to `cargo update` with `--precise`

## precise-pre-release
Expand Down
5 changes: 1 addition & 4 deletions tests/testsuite/cargo_add/rust_version_ignore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ fn case() {
.arg("--ignore-rust-version")
.arg_line("rust-version-user")
.current_dir(cwd)
.env(
"CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE",
"something-like-rust-version",
)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.code(0)
Expand Down
5 changes: 1 addition & 4 deletions tests/testsuite/cargo_add/rust_version_incompatible/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ fn case() {
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.env(
"CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE",
"something-like-rust-version",
)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.failure()
Expand Down
5 changes: 1 addition & 4 deletions tests/testsuite/cargo_add/rust_version_latest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ fn case() {
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.env(
"CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE",
"something-like-rust-version",
)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.success()
Expand Down
5 changes: 1 addition & 4 deletions tests/testsuite/cargo_add/rust_version_older/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ fn case() {
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.env(
"CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE",
"something-like-rust-version",
)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.success()
Expand Down
5 changes: 1 addition & 4 deletions tests/testsuite/cargo_add/rustc_ignore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ fn case() {
.arg("--ignore-rust-version")
.arg_line("rust-version-user")
.current_dir(cwd)
.env(
"CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE",
"something-like-rust-version",
)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.code(0)
Expand Down
5 changes: 1 addition & 4 deletions tests/testsuite/cargo_add/rustc_incompatible/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ fn case() {
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.env(
"CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE",
"something-like-rust-version",
)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.failure()
Expand Down
5 changes: 1 addition & 4 deletions tests/testsuite/cargo_add/rustc_latest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ fn case() {
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.env(
"CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE",
"something-like-rust-version",
)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.success()
Expand Down
5 changes: 1 addition & 4 deletions tests/testsuite/cargo_add/rustc_older/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ fn case() {
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.env(
"CARGO_RESOLVER_SOMETHING_LIKE_PRECEDENCE",
"something-like-rust-version",
)
.env("CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS", "fallback")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.success()
Expand Down
Loading

0 comments on commit feecbd7

Please sign in to comment.