Skip to content

Commit

Permalink
Auto merge of #10911 - Nemo157:override-to-resolver-1, r=epage
Browse files Browse the repository at this point in the history
Override to resolver=1 in published package

As discussed in #10112 this avoids inconsistent dependency resolution in development and packaged builds when an edition 2021 crate is published from a workspace using the default resolver=1.
  • Loading branch information
bors committed Jul 29, 2022
2 parents 015143c + d953c3b commit 281989f
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/cargo/core/resolver/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ impl ResolveBehavior {
}
}

pub fn to_manifest(&self) -> Option<String> {
pub fn to_manifest(&self) -> String {
match self {
ResolveBehavior::V1 => None,
ResolveBehavior::V2 => Some("2".to_string()),
ResolveBehavior::V1 => "1",
ResolveBehavior::V2 => "2",
}
.to_owned()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ impl TomlManifest {
.unwrap()
.clone();
package.workspace = None;
package.resolver = ws.resolve_behavior().to_manifest();
package.resolver = Some(ws.resolve_behavior().to_manifest());
if let Some(license_file) = &package.license_file {
let license_file = license_file
.as_defined()
Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/features_namespaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ version = "0.1.0"
description = "foo"
homepage = "https://example.com/"
license = "MIT"
resolver = "1"
[dependencies.opt-dep1]
version = "1.0"
Expand Down Expand Up @@ -1058,6 +1059,7 @@ version = "0.1.0"
description = "foo"
homepage = "https://example.com/"
license = "MIT"
resolver = "1"
[dependencies.bar]
version = "1.0"
Expand Down
5 changes: 5 additions & 0 deletions tests/testsuite/inheritable_workspace_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ keywords = ["cli"]
categories = ["development-tools"]
license = "MIT"
repository = "https://github.com/example/example"
resolver = "1"
[badges.gitlab]
branch = "master"
Expand Down Expand Up @@ -348,6 +349,7 @@ fn inherit_own_dependencies() {
name = "bar"
version = "0.2.0"
authors = []
resolver = "1"
[dependencies.dep]
version = "0.1"
Expand Down Expand Up @@ -452,6 +454,7 @@ fn inherit_own_detailed_dependencies() {
name = "bar"
version = "0.2.0"
authors = []
resolver = "1"
[dependencies.dep]
version = "0.1.2"
Expand Down Expand Up @@ -688,6 +691,7 @@ categories = ["development-tools"]
license = "MIT"
license-file = "LICENSE"
repository = "https://github.com/example/example"
resolver = "1"
[badges.gitlab]
branch = "master"
Expand Down Expand Up @@ -819,6 +823,7 @@ fn inherit_dependencies() {
name = "bar"
version = "0.2.0"
authors = []
resolver = "1"
[dependencies.dep]
version = "0.1"
Expand Down
45 changes: 45 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ authors = []
exclude = ["*.txt"]
description = "foo"
license = "MIT"
resolver = "1"
[package.metadata]
foo = "bar"
Expand Down Expand Up @@ -1189,6 +1190,7 @@ fn ignore_workspace_specifier() {
name = "bar"
version = "0.1.0"
authors = []
resolver = "1"
"#,
cargo::core::package::MANIFEST_PREAMBLE
);
Expand Down Expand Up @@ -2325,3 +2327,46 @@ See [..]
assert!(p.root().join("target/package/foo-0.0.1.crate").is_file());
assert!(p.root().join("target/package/bar-0.0.1.crate").is_file());
}

#[cargo_test]
fn workspace_overrides_resolver() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["bar"]
"#,
)
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.1.0"
edition = "2021"
"#,
)
.file("bar/src/lib.rs", "")
.build();

p.cargo("package --no-verify").cwd("bar").run();

let f = File::open(&p.root().join("target/package/bar-0.1.0.crate")).unwrap();
let rewritten_toml = format!(
r#"{}
[package]
edition = "2021"
name = "bar"
version = "0.1.0"
resolver = "1"
"#,
cargo::core::package::MANIFEST_PREAMBLE
);
validate_crate_contents(
f,
"bar-0.1.0.crate",
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
&[("Cargo.toml", &rewritten_toml)],
);
}
2 changes: 2 additions & 0 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ fn publish_git_with_version() {
authors = []\n\
description = \"foo\"\n\
license = \"MIT\"\n\
resolver = \"1\"\n\
\n\
[dependencies.dep1]\n\
version = \"1.0\"\n\
Expand Down Expand Up @@ -1284,6 +1285,7 @@ homepage = "foo"
documentation = "foo"
license = "MIT"
repository = "foo"
resolver = "1"
[dev-dependencies]
"#,
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/weak_dep_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ version = "0.1.0"
description = "foo"
homepage = "https://example.com/"
license = "MIT"
resolver = "1"
[dependencies.bar]
version = "1.0"
Expand Down

0 comments on commit 281989f

Please sign in to comment.