Skip to content

Commit 42a45c8

Browse files
committed
Auto merge of #12041 - cassaundra:publish-rust-version, r=epage
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.
2 parents 8bcf8fe + c83f7bb commit 42a45c8

File tree

12 files changed

+36
-4
lines changed

12 files changed

+36
-4
lines changed

crates/crates-io/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub struct NewCrate {
5757
pub repository: Option<String>,
5858
pub badges: BTreeMap<String, BTreeMap<String, String>>,
5959
pub links: Option<String>,
60+
pub rust_version: Option<String>,
6061
}
6162

6263
#[derive(Serialize, Deserialize)]

src/cargo/core/manifest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub struct ManifestMetadata {
110110
pub documentation: Option<String>, // URL
111111
pub badges: BTreeMap<String, BTreeMap<String, String>>,
112112
pub links: Option<String>,
113+
pub rust_version: Option<String>,
113114
}
114115

115116
#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]

src/cargo/ops/registry.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ fn transmit(
345345
ref categories,
346346
ref badges,
347347
ref links,
348+
ref rust_version,
348349
} = *manifest.metadata();
349350
let readme_content = readme
350351
.as_ref()
@@ -398,6 +399,7 @@ fn transmit(
398399
license_file: license_file.clone(),
399400
badges: badges.clone(),
400401
links: links.clone(),
402+
rust_version: rust_version.clone(),
401403
},
402404
tarball,
403405
)

src/cargo/util/toml/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,11 @@ impl TomlManifest {
24332433
.transpose()?
24342434
.unwrap_or_default(),
24352435
links: package.links.clone(),
2436+
rust_version: package
2437+
.rust_version
2438+
.clone()
2439+
.map(|mw| mw.resolve("rust-version", || inherit()?.rust_version()))
2440+
.transpose()?,
24362441
};
24372442
package.description = metadata
24382443
.description

src/doc/src/reference/registry-index.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,8 @@ The JSON objects should not be modified after they are added except for the
224224
> * The publish API includes several other fields, such as `description` and `readme`, which don't appear in the index.
225225
> 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.
226226
> This additional information is typically added to a database on the registry server.
227-
> * `rust_version` is not included. If a registry chooses to support this
228-
> field, they must read it from the `Cargo.toml` contained in the `.crate`
229-
> file.
227+
> * Although `rust_version` is included here, [crates.io] will ignore this field
228+
> and instead read it from the `Cargo.toml` contained in the `.crate` file.
230229
>
231230
> For [`cargo metadata`], the differences are:
232231
>

src/doc/src/reference/registry-web-api.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ considered as an exhaustive list of restrictions [crates.io] imposes.
161161
},
162162
// The `links` string value from the package's manifest, or null if not
163163
// specified. This field is optional and defaults to null.
164-
"links": null
164+
"links": null,
165+
// The minimal supported Rust version (optional)
166+
// This must be a valid version requirement without an operator (e.g. no `=`)
167+
"rust_version": null
165168
}
166169
```
167170

tests/testsuite/alt_registry.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
366366
"repository": null,
367367
"homepage": null,
368368
"documentation": null,
369+
"rust_version": null,
369370
"vers": "0.0.1"
370371
}"#,
371372
"foo-0.0.1.crate",
@@ -515,6 +516,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
515516
"repository": null,
516517
"homepage": null,
517518
"documentation": null,
519+
"rust_version": null,
518520
"vers": "0.0.1"
519521
}"#,
520522
"foo-0.0.1.crate",
@@ -607,6 +609,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
607609
"repository": null,
608610
"homepage": null,
609611
"documentation": null,
612+
"rust_version": null,
610613
"vers": "0.0.1"
611614
}"#,
612615
"foo-0.0.1.crate",

tests/testsuite/artifact_dep.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,7 @@ You may press ctrl-c [..]
19561956
"readme": null,
19571957
"readme_file": null,
19581958
"repository": "foo",
1959+
"rust_version": null,
19591960
"vers": "0.1.0"
19601961
}
19611962
"#,

tests/testsuite/features_namespaced.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ You may press ctrl-c [..]
942942
"readme": null,
943943
"readme_file": null,
944944
"repository": null,
945+
"rust_version": null,
945946
"vers": "0.1.0"
946947
}
947948
"#,
@@ -1057,6 +1058,7 @@ You may press ctrl-c [..]
10571058
"readme": null,
10581059
"readme_file": null,
10591060
"repository": null,
1061+
"rust_version": null,
10601062
"vers": "0.1.0"
10611063
}
10621064
"#,

tests/testsuite/inheritable_workspace_fields.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
201201
"readme": null,
202202
"readme_file": null,
203203
"repository": "https://github.com/example/example",
204+
"rust_version": "1.60",
204205
"vers": "1.2.3"
205206
}
206207
"#,
@@ -376,6 +377,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
376377
"readme": null,
377378
"readme_file": null,
378379
"repository": null,
380+
"rust_version": null,
379381
"vers": "0.2.0"
380382
}
381383
"#,
@@ -503,6 +505,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
503505
"readme": null,
504506
"readme_file": null,
505507
"repository": null,
508+
"rust_version": null,
506509
"vers": "0.2.0"
507510
}
508511
"#,
@@ -734,6 +737,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
734737
"readme": "README.md",
735738
"readme_file": "../README.md",
736739
"repository": "https://github.com/example/example",
740+
"rust_version": "1.60",
737741
"vers": "1.2.3"
738742
}
739743
"#,
@@ -917,6 +921,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
917921
"readme": null,
918922
"readme_file": null,
919923
"repository": null,
924+
"rust_version": null,
920925
"vers": "0.2.0"
921926
}
922927
"#,

tests/testsuite/publish.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const CLEAN_FOO_JSON: &str = r#"
2525
"readme": null,
2626
"readme_file": null,
2727
"repository": "foo",
28+
"rust_version": null,
2829
"vers": "0.0.1"
2930
}
3031
"#;
@@ -49,6 +50,7 @@ fn validate_upload_foo() {
4950
"readme": null,
5051
"readme_file": null,
5152
"repository": null,
53+
"rust_version": null,
5254
"vers": "0.0.1"
5355
}
5456
"#,
@@ -77,6 +79,7 @@ fn validate_upload_li() {
7779
"readme": null,
7880
"readme_file": null,
7981
"repository": null,
82+
"rust_version": "1.69",
8083
"vers": "0.0.1"
8184
}
8285
"#,
@@ -1270,6 +1273,7 @@ You may press ctrl-c [..]
12701273
"readme": null,
12711274
"readme_file": null,
12721275
"repository": null,
1276+
"rust_version": null,
12731277
"vers": "0.0.1"
12741278
}
12751279
"#,
@@ -1469,6 +1473,7 @@ You may press ctrl-c [..]
14691473
"readme": null,
14701474
"readme_file": null,
14711475
"repository": null,
1476+
"rust_version": null,
14721477
"vers": "0.1.0"
14731478
}
14741479
"#,
@@ -1581,6 +1586,7 @@ You may press ctrl-c [..]
15811586
"readme": null,
15821587
"readme_file": null,
15831588
"repository": "foo",
1589+
"rust_version": null,
15841590
"vers": "0.1.0"
15851591
}
15861592
"#,
@@ -2049,6 +2055,7 @@ fn in_package_workspace() {
20492055
[package]
20502056
name = "li"
20512057
version = "0.0.1"
2058+
rust-version = "1.69"
20522059
description = "li"
20532060
license = "MIT"
20542061
"#,
@@ -2151,6 +2158,7 @@ fn in_package_workspace_with_members_with_features_old() {
21512158
[package]
21522159
name = "li"
21532160
version = "0.0.1"
2161+
rust-version = "1.69"
21542162
description = "li"
21552163
license = "MIT"
21562164
"#,
@@ -2246,6 +2254,7 @@ fn in_virtual_workspace_with_p() {
22462254
[package]
22472255
name = "li"
22482256
version = "0.0.1"
2257+
rust-version = "1.69"
22492258
description = "li"
22502259
license = "MIT"
22512260
"#,

tests/testsuite/weak_dep_features.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
601601
"readme": null,
602602
"readme_file": null,
603603
"repository": null,
604+
"rust_version": null,
604605
"vers": "0.1.0"
605606
}
606607
"#,

0 commit comments

Comments
 (0)