Skip to content

Commit 5a1862c

Browse files
committed
Add proc-macro to the index.
1 parent 94093c2 commit 5a1862c

File tree

10 files changed

+119
-12
lines changed

10 files changed

+119
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ path = "src/cargo/lib.rs"
2222
atty = "0.2"
2323
bytesize = "1.0"
2424
cargo-platform = { path = "crates/cargo-platform", version = "0.1.1" }
25-
crates-io = { path = "crates/crates-io", version = "0.31" }
25+
crates-io = { path = "crates/crates-io", version = "0.32" }
2626
crossbeam-utils = "0.7"
2727
crypto-hash = "0.3.1"
2828
curl = { version = "0.4.23", features = ["http2"] }

crates/crates-io/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "crates-io"
3-
version = "0.31.0"
3+
version = "0.32.0"
44
edition = "2018"
55
authors = ["Alex Crichton <alex@alexcrichton.com>"]
66
license = "MIT OR Apache-2.0"

crates/crates-io/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pub struct NewCrate {
5454
pub license_file: Option<String>,
5555
pub repository: Option<String>,
5656
pub badges: BTreeMap<String, BTreeMap<String, String>>,
57-
#[serde(default)]
5857
pub links: Option<String>,
58+
pub proc_macro: bool,
5959
}
6060

6161
#[derive(Serialize)]

src/cargo/core/summary.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ struct Inner {
3030
checksum: Option<String>,
3131
links: Option<InternedString>,
3232
namespaced_features: bool,
33+
/// Whether or not this package is a proc-macro library.
34+
///
35+
/// This was added in 2020. Packages published before this will always be
36+
/// `false`.
37+
proc_macro: bool,
3338
}
3439

3540
impl Summary {
@@ -39,6 +44,7 @@ impl Summary {
3944
features: &BTreeMap<K, Vec<impl AsRef<str>>>,
4045
links: Option<impl Into<InternedString>>,
4146
namespaced_features: bool,
47+
proc_macro: bool,
4248
) -> CargoResult<Summary>
4349
where
4450
K: Borrow<str> + Ord + Display,
@@ -68,6 +74,7 @@ impl Summary {
6874
checksum: None,
6975
links: links.map(|l| l.into()),
7076
namespaced_features,
77+
proc_macro,
7178
}),
7279
})
7380
}

src/cargo/ops/registry.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ fn transmit(
255255
)
256256
})
257257
.collect::<BTreeMap<String, Vec<String>>>();
258+
let proc_macro = pkg.targets().iter().any(|target| target.proc_macro());
258259

259260
let publish = registry.publish(
260261
&NewCrate {
@@ -275,6 +276,7 @@ fn transmit(
275276
license_file: license_file.clone(),
276277
badges: badges.clone(),
277278
links: links.clone(),
279+
proc_macro,
278280
},
279281
tarball,
280282
);

src/cargo/sources/registry/index.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,14 +715,23 @@ impl IndexSummary {
715715
features,
716716
yanked,
717717
links,
718+
pm,
718719
} = serde_json::from_slice(line)?;
719720
log::trace!("json parsed registry {}/{}", name, vers);
720721
let pkgid = PackageId::new(name, &vers, source_id)?;
721722
let deps = deps
722723
.into_iter()
723724
.map(|dep| dep.into_dep(source_id))
724725
.collect::<CargoResult<Vec<_>>>()?;
725-
let mut summary = Summary::new(pkgid, deps, &features, links, false)?;
726+
let namespaced_features = false;
727+
let mut summary = Summary::new(
728+
pkgid,
729+
deps,
730+
&features,
731+
links,
732+
namespaced_features,
733+
pm.unwrap_or(false),
734+
)?;
726735
summary.set_checksum(cksum);
727736
Ok(IndexSummary {
728737
summary,

src/cargo/sources/registry/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ pub struct RegistryConfig {
217217
pub api: Option<String>,
218218
}
219219

220+
/// A single line in the index representing a single version of a package.
220221
#[derive(Deserialize)]
221222
pub struct RegistryPackage<'a> {
222223
name: InternedString,
@@ -225,8 +226,21 @@ pub struct RegistryPackage<'a> {
225226
deps: Vec<RegistryDependency<'a>>,
226227
features: BTreeMap<InternedString, Vec<InternedString>>,
227228
cksum: String,
229+
/// If `true`, Cargo will skip this version when resolving.
230+
///
231+
/// This was added in 2014. Everything in the crates.io index has this set
232+
/// now, so this probably doesn't need to be an option anymore.
228233
yanked: Option<bool>,
234+
/// Native library name this package links to.
235+
///
236+
/// Added early 2018 (see https://github.com/rust-lang/cargo/pull/4978),
237+
/// can be `None` if published before then.
229238
links: Option<InternedString>,
239+
/// Whether or not this package is a proc-macro library.
240+
///
241+
/// If `None`, then the status is unknown (crate was published before this
242+
/// field was added), and generally should be treated as `false.`
243+
pm: Option<bool>,
230244
}
231245

232246
#[test]

src/cargo/util/toml/mod.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,19 +1146,23 @@ impl TomlManifest {
11461146
features.require(Feature::namespaced_features())?;
11471147
}
11481148

1149+
let summary_features = me
1150+
.features
1151+
.as_ref()
1152+
.map(|x| {
1153+
x.iter()
1154+
.map(|(k, v)| (k.as_str(), v.iter().collect()))
1155+
.collect()
1156+
})
1157+
.unwrap_or_else(BTreeMap::new);
1158+
let proc_macro = targets.iter().any(|target| target.proc_macro());
11491159
let summary = Summary::new(
11501160
pkgid,
11511161
deps,
1152-
&me.features
1153-
.as_ref()
1154-
.map(|x| {
1155-
x.iter()
1156-
.map(|(k, v)| (k.as_str(), v.iter().collect()))
1157-
.collect()
1158-
})
1159-
.unwrap_or_else(BTreeMap::new),
1162+
&summary_features,
11601163
project.links.as_deref(),
11611164
project.namespaced_features.unwrap_or(false),
1165+
proc_macro,
11621166
)?;
11631167
let metadata = ManifestMetadata {
11641168
description: project.description.clone(),

tests/testsuite/alt_registry.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ fn publish_with_registry_dependency() {
357357
"license_file": null,
358358
"links": null,
359359
"name": "foo",
360+
"proc_macro": false,
360361
"readme": null,
361362
"readme_file": null,
362363
"repository": null,
@@ -456,6 +457,7 @@ fn publish_to_alt_registry() {
456457
"license_file": null,
457458
"links": null,
458459
"name": "foo",
460+
"proc_macro": false,
459461
"readme": null,
460462
"readme_file": null,
461463
"repository": null,
@@ -519,6 +521,7 @@ fn publish_with_crates_io_dep() {
519521
"license_file": null,
520522
"links": null,
521523
"name": "foo",
524+
"proc_macro": false,
522525
"readme": null,
523526
"readme_file": null,
524527
"repository": null,

tests/testsuite/publish.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const CLEAN_FOO_JSON: &str = r#"
2323
"license_file": null,
2424
"links": null,
2525
"name": "foo",
26+
"proc_macro": false,
2627
"readme": null,
2728
"readme_file": null,
2829
"repository": "foo",
@@ -47,6 +48,7 @@ fn validate_upload_foo() {
4748
"license_file": null,
4849
"links": null,
4950
"name": "foo",
51+
"proc_macro": false,
5052
"readme": null,
5153
"readme_file": null,
5254
"repository": null,
@@ -979,6 +981,7 @@ fn publish_with_patch() {
979981
"license_file": null,
980982
"links": null,
981983
"name": "foo",
984+
"proc_macro": false,
982985
"readme": null,
983986
"readme_file": null,
984987
"repository": null,
@@ -1148,6 +1151,7 @@ fn publish_git_with_version() {
11481151
"license_file": null,
11491152
"links": null,
11501153
"name": "foo",
1154+
"proc_macro": false,
11511155
"readme": null,
11521156
"readme_file": null,
11531157
"repository": null,
@@ -1235,6 +1239,7 @@ fn publish_dev_dep_no_version() {
12351239
"license_file": null,
12361240
"links": null,
12371241
"name": "foo",
1242+
"proc_macro": false,
12381243
"readme": null,
12391244
"readme_file": null,
12401245
"repository": "foo",
@@ -1295,3 +1300,66 @@ fn credentials_ambiguous_filename() {
12951300

12961301
validate_upload_foo();
12971302
}
1303+
1304+
#[cargo_test]
1305+
fn publish_proc_macro() {
1306+
registry::init();
1307+
1308+
let p = project()
1309+
.file(
1310+
"Cargo.toml",
1311+
r#"
1312+
[project]
1313+
name = "foo"
1314+
version = "0.0.1"
1315+
authors = []
1316+
license = "MIT"
1317+
description = "foo"
1318+
edition = "2018"
1319+
homepage = "https://example.com"
1320+
1321+
[lib]
1322+
proc-macro = true
1323+
"#,
1324+
)
1325+
.file("src/lib.rs", "")
1326+
.build();
1327+
1328+
p.cargo("publish --no-verify --index")
1329+
.arg(registry_url().to_string())
1330+
.with_stderr(
1331+
"\
1332+
[UPDATING] [..]
1333+
[PACKAGING] foo v0.0.1 ([CWD])
1334+
[UPLOADING] foo v0.0.1 ([CWD])
1335+
",
1336+
)
1337+
.run();
1338+
1339+
publish::validate_upload(
1340+
r#"
1341+
{
1342+
"authors": [],
1343+
"badges": {},
1344+
"categories": [],
1345+
"deps": [],
1346+
"description": "foo",
1347+
"documentation": null,
1348+
"features": {},
1349+
"homepage": "https://example.com",
1350+
"keywords": [],
1351+
"license": "MIT",
1352+
"license_file": null,
1353+
"links": null,
1354+
"name": "foo",
1355+
"proc_macro": true,
1356+
"readme": null,
1357+
"readme_file": null,
1358+
"repository": null,
1359+
"vers": "0.0.1"
1360+
}
1361+
"#,
1362+
"foo-0.0.1.crate",
1363+
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
1364+
);
1365+
}

0 commit comments

Comments
 (0)