Add proc-macro to the index.

This commit is contained in:
Eric Huss 2020-03-15 10:10:25 -07:00
parent 94093c270b
commit 5a1862cd36
10 changed files with 119 additions and 12 deletions

View File

@ -22,7 +22,7 @@ path = "src/cargo/lib.rs"
atty = "0.2" atty = "0.2"
bytesize = "1.0" bytesize = "1.0"
cargo-platform = { path = "crates/cargo-platform", version = "0.1.1" } cargo-platform = { path = "crates/cargo-platform", version = "0.1.1" }
crates-io = { path = "crates/crates-io", version = "0.31" } crates-io = { path = "crates/crates-io", version = "0.32" }
crossbeam-utils = "0.7" crossbeam-utils = "0.7"
crypto-hash = "0.3.1" crypto-hash = "0.3.1"
curl = { version = "0.4.23", features = ["http2"] } curl = { version = "0.4.23", features = ["http2"] }

View File

@ -1,6 +1,6 @@
[package] [package]
name = "crates-io" name = "crates-io"
version = "0.31.0" version = "0.32.0"
edition = "2018" edition = "2018"
authors = ["Alex Crichton <alex@alexcrichton.com>"] authors = ["Alex Crichton <alex@alexcrichton.com>"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"

View File

@ -54,8 +54,8 @@ pub struct NewCrate {
pub license_file: Option<String>, pub license_file: Option<String>,
pub repository: Option<String>, pub repository: Option<String>,
pub badges: BTreeMap<String, BTreeMap<String, String>>, pub badges: BTreeMap<String, BTreeMap<String, String>>,
#[serde(default)]
pub links: Option<String>, pub links: Option<String>,
pub proc_macro: bool,
} }
#[derive(Serialize)] #[derive(Serialize)]

View File

@ -30,6 +30,11 @@ struct Inner {
checksum: Option<String>, checksum: Option<String>,
links: Option<InternedString>, links: Option<InternedString>,
namespaced_features: bool, namespaced_features: bool,
/// Whether or not this package is a proc-macro library.
///
/// This was added in 2020. Packages published before this will always be
/// `false`.
proc_macro: bool,
} }
impl Summary { impl Summary {
@ -39,6 +44,7 @@ impl Summary {
features: &BTreeMap<K, Vec<impl AsRef<str>>>, features: &BTreeMap<K, Vec<impl AsRef<str>>>,
links: Option<impl Into<InternedString>>, links: Option<impl Into<InternedString>>,
namespaced_features: bool, namespaced_features: bool,
proc_macro: bool,
) -> CargoResult<Summary> ) -> CargoResult<Summary>
where where
K: Borrow<str> + Ord + Display, K: Borrow<str> + Ord + Display,
@ -68,6 +74,7 @@ impl Summary {
checksum: None, checksum: None,
links: links.map(|l| l.into()), links: links.map(|l| l.into()),
namespaced_features, namespaced_features,
proc_macro,
}), }),
}) })
} }

View File

@ -255,6 +255,7 @@ fn transmit(
) )
}) })
.collect::<BTreeMap<String, Vec<String>>>(); .collect::<BTreeMap<String, Vec<String>>>();
let proc_macro = pkg.targets().iter().any(|target| target.proc_macro());
let publish = registry.publish( let publish = registry.publish(
&NewCrate { &NewCrate {
@ -275,6 +276,7 @@ fn transmit(
license_file: license_file.clone(), license_file: license_file.clone(),
badges: badges.clone(), badges: badges.clone(),
links: links.clone(), links: links.clone(),
proc_macro,
}, },
tarball, tarball,
); );

View File

@ -715,6 +715,7 @@ impl IndexSummary {
features, features,
yanked, yanked,
links, links,
pm,
} = serde_json::from_slice(line)?; } = serde_json::from_slice(line)?;
log::trace!("json parsed registry {}/{}", name, vers); log::trace!("json parsed registry {}/{}", name, vers);
let pkgid = PackageId::new(name, &vers, source_id)?; let pkgid = PackageId::new(name, &vers, source_id)?;
@ -722,7 +723,15 @@ impl IndexSummary {
.into_iter() .into_iter()
.map(|dep| dep.into_dep(source_id)) .map(|dep| dep.into_dep(source_id))
.collect::<CargoResult<Vec<_>>>()?; .collect::<CargoResult<Vec<_>>>()?;
let mut summary = Summary::new(pkgid, deps, &features, links, false)?; let namespaced_features = false;
let mut summary = Summary::new(
pkgid,
deps,
&features,
links,
namespaced_features,
pm.unwrap_or(false),
)?;
summary.set_checksum(cksum); summary.set_checksum(cksum);
Ok(IndexSummary { Ok(IndexSummary {
summary, summary,

View File

@ -217,6 +217,7 @@ pub struct RegistryConfig {
pub api: Option<String>, pub api: Option<String>,
} }
/// A single line in the index representing a single version of a package.
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct RegistryPackage<'a> { pub struct RegistryPackage<'a> {
name: InternedString, name: InternedString,
@ -225,8 +226,21 @@ pub struct RegistryPackage<'a> {
deps: Vec<RegistryDependency<'a>>, deps: Vec<RegistryDependency<'a>>,
features: BTreeMap<InternedString, Vec<InternedString>>, features: BTreeMap<InternedString, Vec<InternedString>>,
cksum: String, cksum: String,
/// If `true`, Cargo will skip this version when resolving.
///
/// This was added in 2014. Everything in the crates.io index has this set
/// now, so this probably doesn't need to be an option anymore.
yanked: Option<bool>, yanked: Option<bool>,
/// Native library name this package links to.
///
/// Added early 2018 (see https://github.com/rust-lang/cargo/pull/4978),
/// can be `None` if published before then.
links: Option<InternedString>, links: Option<InternedString>,
/// Whether or not this package is a proc-macro library.
///
/// If `None`, then the status is unknown (crate was published before this
/// field was added), and generally should be treated as `false.`
pm: Option<bool>,
} }
#[test] #[test]

View File

@ -1146,19 +1146,23 @@ impl TomlManifest {
features.require(Feature::namespaced_features())?; features.require(Feature::namespaced_features())?;
} }
let summary_features = me
.features
.as_ref()
.map(|x| {
x.iter()
.map(|(k, v)| (k.as_str(), v.iter().collect()))
.collect()
})
.unwrap_or_else(BTreeMap::new);
let proc_macro = targets.iter().any(|target| target.proc_macro());
let summary = Summary::new( let summary = Summary::new(
pkgid, pkgid,
deps, deps,
&me.features &summary_features,
.as_ref()
.map(|x| {
x.iter()
.map(|(k, v)| (k.as_str(), v.iter().collect()))
.collect()
})
.unwrap_or_else(BTreeMap::new),
project.links.as_deref(), project.links.as_deref(),
project.namespaced_features.unwrap_or(false), project.namespaced_features.unwrap_or(false),
proc_macro,
)?; )?;
let metadata = ManifestMetadata { let metadata = ManifestMetadata {
description: project.description.clone(), description: project.description.clone(),

View File

@ -357,6 +357,7 @@ fn publish_with_registry_dependency() {
"license_file": null, "license_file": null,
"links": null, "links": null,
"name": "foo", "name": "foo",
"proc_macro": false,
"readme": null, "readme": null,
"readme_file": null, "readme_file": null,
"repository": null, "repository": null,
@ -456,6 +457,7 @@ fn publish_to_alt_registry() {
"license_file": null, "license_file": null,
"links": null, "links": null,
"name": "foo", "name": "foo",
"proc_macro": false,
"readme": null, "readme": null,
"readme_file": null, "readme_file": null,
"repository": null, "repository": null,
@ -519,6 +521,7 @@ fn publish_with_crates_io_dep() {
"license_file": null, "license_file": null,
"links": null, "links": null,
"name": "foo", "name": "foo",
"proc_macro": false,
"readme": null, "readme": null,
"readme_file": null, "readme_file": null,
"repository": null, "repository": null,

View File

@ -23,6 +23,7 @@ const CLEAN_FOO_JSON: &str = r#"
"license_file": null, "license_file": null,
"links": null, "links": null,
"name": "foo", "name": "foo",
"proc_macro": false,
"readme": null, "readme": null,
"readme_file": null, "readme_file": null,
"repository": "foo", "repository": "foo",
@ -47,6 +48,7 @@ fn validate_upload_foo() {
"license_file": null, "license_file": null,
"links": null, "links": null,
"name": "foo", "name": "foo",
"proc_macro": false,
"readme": null, "readme": null,
"readme_file": null, "readme_file": null,
"repository": null, "repository": null,
@ -979,6 +981,7 @@ fn publish_with_patch() {
"license_file": null, "license_file": null,
"links": null, "links": null,
"name": "foo", "name": "foo",
"proc_macro": false,
"readme": null, "readme": null,
"readme_file": null, "readme_file": null,
"repository": null, "repository": null,
@ -1148,6 +1151,7 @@ fn publish_git_with_version() {
"license_file": null, "license_file": null,
"links": null, "links": null,
"name": "foo", "name": "foo",
"proc_macro": false,
"readme": null, "readme": null,
"readme_file": null, "readme_file": null,
"repository": null, "repository": null,
@ -1235,6 +1239,7 @@ fn publish_dev_dep_no_version() {
"license_file": null, "license_file": null,
"links": null, "links": null,
"name": "foo", "name": "foo",
"proc_macro": false,
"readme": null, "readme": null,
"readme_file": null, "readme_file": null,
"repository": "foo", "repository": "foo",
@ -1295,3 +1300,66 @@ fn credentials_ambiguous_filename() {
validate_upload_foo(); validate_upload_foo();
} }
#[cargo_test]
fn publish_proc_macro() {
registry::init();
let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
edition = "2018"
homepage = "https://example.com"
[lib]
proc-macro = true
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("publish --no-verify --index")
.arg(registry_url().to_string())
.with_stderr(
"\
[UPDATING] [..]
[PACKAGING] foo v0.0.1 ([CWD])
[UPLOADING] foo v0.0.1 ([CWD])
",
)
.run();
publish::validate_upload(
r#"
{
"authors": [],
"badges": {},
"categories": [],
"deps": [],
"description": "foo",
"documentation": null,
"features": {},
"homepage": "https://example.com",
"keywords": [],
"license": "MIT",
"license_file": null,
"links": null,
"name": "foo",
"proc_macro": true,
"readme": null,
"readme_file": null,
"repository": null,
"vers": "0.0.1"
}
"#,
"foo-0.0.1.crate",
&["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
);
}