diff --git a/src/cargo/core/resolver/types.rs b/src/cargo/core/resolver/types.rs index 4617e3ea8e5..6ea5b796a31 100644 --- a/src/cargo/core/resolver/types.rs +++ b/src/cargo/core/resolver/types.rs @@ -119,11 +119,12 @@ impl ResolveBehavior { } } - pub fn to_manifest(&self) -> Option { + 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() } } diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index e71ca757941..58647e03f05 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -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() diff --git a/tests/testsuite/features_namespaced.rs b/tests/testsuite/features_namespaced.rs index 0fe1c964bc1..c1f422a6b5f 100644 --- a/tests/testsuite/features_namespaced.rs +++ b/tests/testsuite/features_namespaced.rs @@ -951,6 +951,7 @@ version = "0.1.0" description = "foo" homepage = "https://example.com/" license = "MIT" +resolver = "1" [dependencies.opt-dep1] version = "1.0" @@ -1058,6 +1059,7 @@ version = "0.1.0" description = "foo" homepage = "https://example.com/" license = "MIT" +resolver = "1" [dependencies.bar] version = "1.0" diff --git a/tests/testsuite/inheritable_workspace_fields.rs b/tests/testsuite/inheritable_workspace_fields.rs index 9f136453665..07661d72d59 100644 --- a/tests/testsuite/inheritable_workspace_fields.rs +++ b/tests/testsuite/inheritable_workspace_fields.rs @@ -218,6 +218,7 @@ keywords = ["cli"] categories = ["development-tools"] license = "MIT" repository = "https://github.com/example/example" +resolver = "1" [badges.gitlab] branch = "master" @@ -348,6 +349,7 @@ fn inherit_own_dependencies() { name = "bar" version = "0.2.0" authors = [] +resolver = "1" [dependencies.dep] version = "0.1" @@ -452,6 +454,7 @@ fn inherit_own_detailed_dependencies() { name = "bar" version = "0.2.0" authors = [] +resolver = "1" [dependencies.dep] version = "0.1.2" @@ -688,6 +691,7 @@ categories = ["development-tools"] license = "MIT" license-file = "LICENSE" repository = "https://github.com/example/example" +resolver = "1" [badges.gitlab] branch = "master" @@ -819,6 +823,7 @@ fn inherit_dependencies() { name = "bar" version = "0.2.0" authors = [] +resolver = "1" [dependencies.dep] version = "0.1" diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 32fe238e410..5a138d70894 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -1119,6 +1119,7 @@ authors = [] exclude = ["*.txt"] description = "foo" license = "MIT" +resolver = "1" [package.metadata] foo = "bar" @@ -1189,6 +1190,7 @@ fn ignore_workspace_specifier() { name = "bar" version = "0.1.0" authors = [] +resolver = "1" "#, cargo::core::package::MANIFEST_PREAMBLE ); @@ -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)], + ); +} diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index 77de699f6c7..3c72b941d12 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -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\ @@ -1284,6 +1285,7 @@ homepage = "foo" documentation = "foo" license = "MIT" repository = "foo" +resolver = "1" [dev-dependencies] "#, diff --git a/tests/testsuite/weak_dep_features.rs b/tests/testsuite/weak_dep_features.rs index 07d86470081..0db7bb9c21e 100644 --- a/tests/testsuite/weak_dep_features.rs +++ b/tests/testsuite/weak_dep_features.rs @@ -608,6 +608,7 @@ version = "0.1.0" description = "foo" homepage = "https://example.com/" license = "MIT" +resolver = "1" [dependencies.bar] version = "1.0"