mirror of
https://github.com/rust-lang/cargo
synced 2024-08-28 11:50:23 +00:00
Add proc-macro to the index.
This commit is contained in:
parent
94093c270b
commit
5a1862cd36
|
@ -22,7 +22,7 @@ path = "src/cargo/lib.rs"
|
|||
atty = "0.2"
|
||||
bytesize = "1.0"
|
||||
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"
|
||||
crypto-hash = "0.3.1"
|
||||
curl = { version = "0.4.23", features = ["http2"] }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "crates-io"
|
||||
version = "0.31.0"
|
||||
version = "0.32.0"
|
||||
edition = "2018"
|
||||
authors = ["Alex Crichton <alex@alexcrichton.com>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
|
|
@ -54,8 +54,8 @@ pub struct NewCrate {
|
|||
pub license_file: Option<String>,
|
||||
pub repository: Option<String>,
|
||||
pub badges: BTreeMap<String, BTreeMap<String, String>>,
|
||||
#[serde(default)]
|
||||
pub links: Option<String>,
|
||||
pub proc_macro: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
|
|
@ -30,6 +30,11 @@ struct Inner {
|
|||
checksum: Option<String>,
|
||||
links: Option<InternedString>,
|
||||
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 {
|
||||
|
@ -39,6 +44,7 @@ impl Summary {
|
|||
features: &BTreeMap<K, Vec<impl AsRef<str>>>,
|
||||
links: Option<impl Into<InternedString>>,
|
||||
namespaced_features: bool,
|
||||
proc_macro: bool,
|
||||
) -> CargoResult<Summary>
|
||||
where
|
||||
K: Borrow<str> + Ord + Display,
|
||||
|
@ -68,6 +74,7 @@ impl Summary {
|
|||
checksum: None,
|
||||
links: links.map(|l| l.into()),
|
||||
namespaced_features,
|
||||
proc_macro,
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -255,6 +255,7 @@ fn transmit(
|
|||
)
|
||||
})
|
||||
.collect::<BTreeMap<String, Vec<String>>>();
|
||||
let proc_macro = pkg.targets().iter().any(|target| target.proc_macro());
|
||||
|
||||
let publish = registry.publish(
|
||||
&NewCrate {
|
||||
|
@ -275,6 +276,7 @@ fn transmit(
|
|||
license_file: license_file.clone(),
|
||||
badges: badges.clone(),
|
||||
links: links.clone(),
|
||||
proc_macro,
|
||||
},
|
||||
tarball,
|
||||
);
|
||||
|
|
|
@ -715,6 +715,7 @@ impl IndexSummary {
|
|||
features,
|
||||
yanked,
|
||||
links,
|
||||
pm,
|
||||
} = serde_json::from_slice(line)?;
|
||||
log::trace!("json parsed registry {}/{}", name, vers);
|
||||
let pkgid = PackageId::new(name, &vers, source_id)?;
|
||||
|
@ -722,7 +723,15 @@ impl IndexSummary {
|
|||
.into_iter()
|
||||
.map(|dep| dep.into_dep(source_id))
|
||||
.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);
|
||||
Ok(IndexSummary {
|
||||
summary,
|
||||
|
|
|
@ -217,6 +217,7 @@ pub struct RegistryConfig {
|
|||
pub api: Option<String>,
|
||||
}
|
||||
|
||||
/// A single line in the index representing a single version of a package.
|
||||
#[derive(Deserialize)]
|
||||
pub struct RegistryPackage<'a> {
|
||||
name: InternedString,
|
||||
|
@ -225,8 +226,21 @@ pub struct RegistryPackage<'a> {
|
|||
deps: Vec<RegistryDependency<'a>>,
|
||||
features: BTreeMap<InternedString, Vec<InternedString>>,
|
||||
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>,
|
||||
/// 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>,
|
||||
/// 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]
|
||||
|
|
|
@ -1146,19 +1146,23 @@ impl TomlManifest {
|
|||
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(
|
||||
pkgid,
|
||||
deps,
|
||||
&me.features
|
||||
.as_ref()
|
||||
.map(|x| {
|
||||
x.iter()
|
||||
.map(|(k, v)| (k.as_str(), v.iter().collect()))
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_else(BTreeMap::new),
|
||||
&summary_features,
|
||||
project.links.as_deref(),
|
||||
project.namespaced_features.unwrap_or(false),
|
||||
proc_macro,
|
||||
)?;
|
||||
let metadata = ManifestMetadata {
|
||||
description: project.description.clone(),
|
||||
|
|
|
@ -357,6 +357,7 @@ fn publish_with_registry_dependency() {
|
|||
"license_file": null,
|
||||
"links": null,
|
||||
"name": "foo",
|
||||
"proc_macro": false,
|
||||
"readme": null,
|
||||
"readme_file": null,
|
||||
"repository": null,
|
||||
|
@ -456,6 +457,7 @@ fn publish_to_alt_registry() {
|
|||
"license_file": null,
|
||||
"links": null,
|
||||
"name": "foo",
|
||||
"proc_macro": false,
|
||||
"readme": null,
|
||||
"readme_file": null,
|
||||
"repository": null,
|
||||
|
@ -519,6 +521,7 @@ fn publish_with_crates_io_dep() {
|
|||
"license_file": null,
|
||||
"links": null,
|
||||
"name": "foo",
|
||||
"proc_macro": false,
|
||||
"readme": null,
|
||||
"readme_file": null,
|
||||
"repository": null,
|
||||
|
|
|
@ -23,6 +23,7 @@ const CLEAN_FOO_JSON: &str = r#"
|
|||
"license_file": null,
|
||||
"links": null,
|
||||
"name": "foo",
|
||||
"proc_macro": false,
|
||||
"readme": null,
|
||||
"readme_file": null,
|
||||
"repository": "foo",
|
||||
|
@ -47,6 +48,7 @@ fn validate_upload_foo() {
|
|||
"license_file": null,
|
||||
"links": null,
|
||||
"name": "foo",
|
||||
"proc_macro": false,
|
||||
"readme": null,
|
||||
"readme_file": null,
|
||||
"repository": null,
|
||||
|
@ -979,6 +981,7 @@ fn publish_with_patch() {
|
|||
"license_file": null,
|
||||
"links": null,
|
||||
"name": "foo",
|
||||
"proc_macro": false,
|
||||
"readme": null,
|
||||
"readme_file": null,
|
||||
"repository": null,
|
||||
|
@ -1148,6 +1151,7 @@ fn publish_git_with_version() {
|
|||
"license_file": null,
|
||||
"links": null,
|
||||
"name": "foo",
|
||||
"proc_macro": false,
|
||||
"readme": null,
|
||||
"readme_file": null,
|
||||
"repository": null,
|
||||
|
@ -1235,6 +1239,7 @@ fn publish_dev_dep_no_version() {
|
|||
"license_file": null,
|
||||
"links": null,
|
||||
"name": "foo",
|
||||
"proc_macro": false,
|
||||
"readme": null,
|
||||
"readme_file": null,
|
||||
"repository": "foo",
|
||||
|
@ -1295,3 +1300,66 @@ fn credentials_ambiguous_filename() {
|
|||
|
||||
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"],
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue