Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): Adjust MSRV resolve config field name / values #14296

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 10 additions & 9 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,26 +338,27 @@ 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.
If there is no MSRV set then your toolchain version will be used, allowing it to pick up the toolchain version from pinned in rustup (e.g. `rust-toolchain.toml`).

#### `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
When resolving a version for a dependency, select how versions with incompatible `package.rust-version`s are treated.
Values include:
- `allow`: treat `rust-version`-incompatible versions like any other version
- `fallback`: only consider `rust-version`-incompatible versions if no other 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 higher than any version with a compatible `rust-version`
- 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