From 5554889f88794f9ed529da68cf88ff8e1049373a Mon Sep 17 00:00:00 2001 From: cassaundra Date: Fri, 24 Mar 2023 13:46:59 -0700 Subject: [PATCH] Include rust-version in publish request crates.io reads rust-version from the tarball directly, but we can include it in the publish request for the sake of consistency for third-party registries. --- crates/crates-io/lib.rs | 1 + src/cargo/core/manifest.rs | 1 + src/cargo/ops/registry.rs | 2 ++ src/cargo/util/toml/mod.rs | 5 +++++ tests/testsuite/alt_registry.rs | 3 +++ tests/testsuite/artifact_dep.rs | 1 + tests/testsuite/features_namespaced.rs | 2 ++ tests/testsuite/inheritable_workspace_fields.rs | 5 +++++ tests/testsuite/publish.rs | 9 +++++++++ tests/testsuite/weak_dep_features.rs | 1 + 10 files changed, 30 insertions(+) diff --git a/crates/crates-io/lib.rs b/crates/crates-io/lib.rs index e0197568a6c..3d7608a2900 100644 --- a/crates/crates-io/lib.rs +++ b/crates/crates-io/lib.rs @@ -57,6 +57,7 @@ pub struct NewCrate { pub repository: Option, pub badges: BTreeMap>, pub links: Option, + pub rust_version: Option, } #[derive(Serialize, Deserialize)] diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 182882dad75..9f77b1301fb 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -110,6 +110,7 @@ pub struct ManifestMetadata { pub documentation: Option, // URL pub badges: BTreeMap>, pub links: Option, + pub rust_version: Option, } #[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index e04f7ba2cff..cc15d47f56a 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -345,6 +345,7 @@ fn transmit( ref categories, ref badges, ref links, + ref rust_version, } = *manifest.metadata(); let readme_content = readme .as_ref() @@ -398,6 +399,7 @@ fn transmit( license_file: license_file.clone(), badges: badges.clone(), links: links.clone(), + rust_version: rust_version.clone(), }, tarball, ) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 7b8c916cc65..12698b70310 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -2433,6 +2433,11 @@ impl TomlManifest { .transpose()? .unwrap_or_default(), links: package.links.clone(), + rust_version: package + .rust_version + .clone() + .map(|mw| mw.resolve("rust-version", || inherit()?.rust_version())) + .transpose()?, }; package.description = metadata .description diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index 97da909b83c..e9dd0071e06 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -366,6 +366,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "repository": null, "homepage": null, "documentation": null, + "rust_version": null, "vers": "0.0.1" }"#, "foo-0.0.1.crate", @@ -515,6 +516,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "repository": null, "homepage": null, "documentation": null, + "rust_version": null, "vers": "0.0.1" }"#, "foo-0.0.1.crate", @@ -607,6 +609,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "repository": null, "homepage": null, "documentation": null, + "rust_version": null, "vers": "0.0.1" }"#, "foo-0.0.1.crate", diff --git a/tests/testsuite/artifact_dep.rs b/tests/testsuite/artifact_dep.rs index ec6bb7103a2..08e413bf511 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -1956,6 +1956,7 @@ You may press ctrl-c [..] "readme": null, "readme_file": null, "repository": "foo", + "rust_version": null, "vers": "0.1.0" } "#, diff --git a/tests/testsuite/features_namespaced.rs b/tests/testsuite/features_namespaced.rs index 8ec2fc2e35d..d090235d5ab 100644 --- a/tests/testsuite/features_namespaced.rs +++ b/tests/testsuite/features_namespaced.rs @@ -942,6 +942,7 @@ You may press ctrl-c [..] "readme": null, "readme_file": null, "repository": null, + "rust_version": null, "vers": "0.1.0" } "#, @@ -1057,6 +1058,7 @@ You may press ctrl-c [..] "readme": null, "readme_file": null, "repository": null, + "rust_version": null, "vers": "0.1.0" } "#, diff --git a/tests/testsuite/inheritable_workspace_fields.rs b/tests/testsuite/inheritable_workspace_fields.rs index d63437260fb..cc261a47f47 100644 --- a/tests/testsuite/inheritable_workspace_fields.rs +++ b/tests/testsuite/inheritable_workspace_fields.rs @@ -201,6 +201,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "readme": null, "readme_file": null, "repository": "https://github.com/example/example", + "rust_version": "1.60", "vers": "1.2.3" } "#, @@ -376,6 +377,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "readme": null, "readme_file": null, "repository": null, + "rust_version": null, "vers": "0.2.0" } "#, @@ -503,6 +505,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "readme": null, "readme_file": null, "repository": null, + "rust_version": null, "vers": "0.2.0" } "#, @@ -734,6 +737,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "readme": "README.md", "readme_file": "../README.md", "repository": "https://github.com/example/example", + "rust_version": "1.60", "vers": "1.2.3" } "#, @@ -917,6 +921,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "readme": null, "readme_file": null, "repository": null, + "rust_version": null, "vers": "0.2.0" } "#, diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index bae940eb7a6..45b7c7da5ab 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -25,6 +25,7 @@ const CLEAN_FOO_JSON: &str = r#" "readme": null, "readme_file": null, "repository": "foo", + "rust_version": null, "vers": "0.0.1" } "#; @@ -49,6 +50,7 @@ fn validate_upload_foo() { "readme": null, "readme_file": null, "repository": null, + "rust_version": null, "vers": "0.0.1" } "#, @@ -77,6 +79,7 @@ fn validate_upload_li() { "readme": null, "readme_file": null, "repository": null, + "rust_version": "1.69", "vers": "0.0.1" } "#, @@ -1270,6 +1273,7 @@ You may press ctrl-c [..] "readme": null, "readme_file": null, "repository": null, + "rust_version": null, "vers": "0.0.1" } "#, @@ -1469,6 +1473,7 @@ You may press ctrl-c [..] "readme": null, "readme_file": null, "repository": null, + "rust_version": null, "vers": "0.1.0" } "#, @@ -1581,6 +1586,7 @@ You may press ctrl-c [..] "readme": null, "readme_file": null, "repository": "foo", + "rust_version": null, "vers": "0.1.0" } "#, @@ -2049,6 +2055,7 @@ fn in_package_workspace() { [package] name = "li" version = "0.0.1" + rust-version = "1.69" description = "li" license = "MIT" "#, @@ -2151,6 +2158,7 @@ fn in_package_workspace_with_members_with_features_old() { [package] name = "li" version = "0.0.1" + rust-version = "1.69" description = "li" license = "MIT" "#, @@ -2246,6 +2254,7 @@ fn in_virtual_workspace_with_p() { [package] name = "li" version = "0.0.1" + rust-version = "1.69" description = "li" license = "MIT" "#, diff --git a/tests/testsuite/weak_dep_features.rs b/tests/testsuite/weak_dep_features.rs index ee91114df5f..6f7c035476a 100644 --- a/tests/testsuite/weak_dep_features.rs +++ b/tests/testsuite/weak_dep_features.rs @@ -601,6 +601,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "readme": null, "readme_file": null, "repository": null, + "rust_version": null, "vers": "0.1.0" } "#,