Skip to content

Commit

Permalink
Auto merge of #12041 - cassaundra:publish-rust-version, r=epage
Browse files Browse the repository at this point in the history
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. See [relevant Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/318791-t-crates-io/topic/rust-version.20field).

Validation for the field was already implemented in #8037.
  • Loading branch information
bors committed Apr 27, 2023
2 parents 8bcf8fe + c83f7bb commit 42a45c8
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/crates-io/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub struct NewCrate {
pub repository: Option<String>,
pub badges: BTreeMap<String, BTreeMap<String, String>>,
pub links: Option<String>,
pub rust_version: Option<String>,
}

#[derive(Serialize, Deserialize)]
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub struct ManifestMetadata {
pub documentation: Option<String>, // URL
pub badges: BTreeMap<String, BTreeMap<String, String>>,
pub links: Option<String>,
pub rust_version: Option<String>,
}

#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ fn transmit(
ref categories,
ref badges,
ref links,
ref rust_version,
} = *manifest.metadata();
let readme_content = readme
.as_ref()
Expand Down Expand Up @@ -398,6 +399,7 @@ fn transmit(
license_file: license_file.clone(),
badges: badges.clone(),
links: links.clone(),
rust_version: rust_version.clone(),
},
tarball,
)
Expand Down
5 changes: 5 additions & 0 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/doc/src/reference/registry-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
>
Expand Down
5 changes: 4 additions & 1 deletion src/doc/src/reference/registry-web-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,7 @@ You may press ctrl-c [..]
"readme": null,
"readme_file": null,
"repository": "foo",
"rust_version": null,
"vers": "0.1.0"
}
"#,
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 @@ -942,6 +942,7 @@ You may press ctrl-c [..]
"readme": null,
"readme_file": null,
"repository": null,
"rust_version": null,
"vers": "0.1.0"
}
"#,
Expand Down Expand Up @@ -1057,6 +1058,7 @@ You may press ctrl-c [..]
"readme": null,
"readme_file": null,
"repository": null,
"rust_version": null,
"vers": "0.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 @@ -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"
}
"#,
Expand Down Expand Up @@ -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"
}
"#,
Expand Down Expand Up @@ -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"
}
"#,
Expand Down Expand Up @@ -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"
}
"#,
Expand Down Expand Up @@ -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"
}
"#,
Expand Down
9 changes: 9 additions & 0 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const CLEAN_FOO_JSON: &str = r#"
"readme": null,
"readme_file": null,
"repository": "foo",
"rust_version": null,
"vers": "0.0.1"
}
"#;
Expand All @@ -49,6 +50,7 @@ fn validate_upload_foo() {
"readme": null,
"readme_file": null,
"repository": null,
"rust_version": null,
"vers": "0.0.1"
}
"#,
Expand Down Expand Up @@ -77,6 +79,7 @@ fn validate_upload_li() {
"readme": null,
"readme_file": null,
"repository": null,
"rust_version": "1.69",
"vers": "0.0.1"
}
"#,
Expand Down Expand Up @@ -1270,6 +1273,7 @@ You may press ctrl-c [..]
"readme": null,
"readme_file": null,
"repository": null,
"rust_version": null,
"vers": "0.0.1"
}
"#,
Expand Down Expand Up @@ -1469,6 +1473,7 @@ You may press ctrl-c [..]
"readme": null,
"readme_file": null,
"repository": null,
"rust_version": null,
"vers": "0.1.0"
}
"#,
Expand Down Expand Up @@ -1581,6 +1586,7 @@ You may press ctrl-c [..]
"readme": null,
"readme_file": null,
"repository": "foo",
"rust_version": null,
"vers": "0.1.0"
}
"#,
Expand Down Expand Up @@ -2049,6 +2055,7 @@ fn in_package_workspace() {
[package]
name = "li"
version = "0.0.1"
rust-version = "1.69"
description = "li"
license = "MIT"
"#,
Expand Down Expand Up @@ -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"
"#,
Expand Down Expand Up @@ -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"
"#,
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 @@ -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"
}
"#,
Expand Down

0 comments on commit 42a45c8

Please sign in to comment.