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/src/doc/src/reference/registry-index.md b/src/doc/src/reference/registry-index.md index 1b779c2772f..9e5be3e5bf6 100644 --- a/src/doc/src/reference/registry-index.md +++ b/src/doc/src/reference/registry-index.md @@ -224,9 +224,8 @@ The JSON objects should not be modified after they are added except for the > * The publish API includes several other fields, such as `description` and `readme`, which don't appear in the index. > These are intended to make it easier for a registry to obtain the metadata about the crate to display on a website without needing to extract and parse the `.crate` file. > This additional information is typically added to a database on the registry server. -> * `rust_version` is not included. If a registry chooses to support this -> field, they must read it from the `Cargo.toml` contained in the `.crate` -> file. +> * Although `rust_version` is included here, [crates.io] will ignore this field +> and instead read it from the `Cargo.toml` contained in the `.crate` file. > > For [`cargo metadata`], the differences are: > diff --git a/src/doc/src/reference/registry-web-api.md b/src/doc/src/reference/registry-web-api.md index 147ababd54e..347eb7280b9 100644 --- a/src/doc/src/reference/registry-web-api.md +++ b/src/doc/src/reference/registry-web-api.md @@ -161,7 +161,10 @@ considered as an exhaustive list of restrictions [crates.io] imposes. }, // The `links` string value from the package's manifest, or null if not // specified. This field is optional and defaults to null. - "links": null + "links": null, + // The minimal supported Rust version (optional) + // This must be a valid version requirement without an operator (e.g. no `=`) + "rust_version": null } ``` 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" } "#,