Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/cargo-test-support/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ pub(crate) fn create_index_line(
links: Option<String>,
rust_version: Option<&str>,
v: Option<u32>,
proc_macro: Option<bool>,
) -> String {
// This emulates what crates.io does to retain backwards compatibility.
let (features, features2) = split_index_features(features.clone());
Expand All @@ -240,6 +241,7 @@ pub(crate) fn create_index_line(
"features": features,
"yanked": yanked,
"links": links,
"proc_macro": proc_macro,
});
if let Some(f2) = &features2 {
json["features2"] = serde_json::json!(f2);
Expand Down
8 changes: 8 additions & 0 deletions crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,7 @@ fn save_new_crate(
new_crate.links,
new_crate.rust_version.as_deref(),
None,
None,
);

write_to_index(registry_path, &new_crate.name, line, false);
Expand Down Expand Up @@ -1527,6 +1528,12 @@ impl Package {
} else {
serde_json::json!(self.name)
};
// simulate alternative registries not having proc_macro in the index
let proc_macro = if self.alternative {
None
} else {
Some(self.proc_macro)
};
create_index_line(
name,
&self.vers,
Expand All @@ -1537,6 +1544,7 @@ impl Package {
self.links.clone(),
self.rust_version.as_deref(),
self.v,
proc_macro,
)
};

Expand Down
6 changes: 6 additions & 0 deletions crates/cargo-util-schemas/index.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@
],
"format": "uint32",
"minimum": 0
},
"proc_macro": {
"type": [
"boolean",
"null"
]
}
},
"required": [
Expand Down
1 change: 1 addition & 0 deletions crates/cargo-util-schemas/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub struct IndexPackage<'a> {
/// workaround is to downgrade any packages that are incompatible with the
/// `--precise` flag of `cargo update`.
pub v: Option<u32>,
pub proc_macro: Option<bool>,
}

/// A dependency as encoded in the [`IndexPackage`] index JSON.
Expand Down
1 change: 1 addition & 0 deletions crates/crates-io/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct NewCrate {
pub badges: BTreeMap<String, BTreeMap<String, String>>,
pub links: Option<String>,
pub rust_version: Option<String>,
pub proc_macro: Option<bool>,
}

#[derive(Serialize, Deserialize)]
Expand Down
25 changes: 21 additions & 4 deletions crates/resolver-tests/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn pkg_dep<T: ToPkgId>(name: T, dep: Vec<Dependency>) -> Summary {
} else {
None
};
Summary::new(name.to_pkgid(), dep, &BTreeMap::new(), link, None).unwrap()
Summary::new(name.to_pkgid(), dep, &BTreeMap::new(), link, None, None).unwrap()
}

pub fn pkg_dep_with<T: ToPkgId>(
Expand All @@ -137,11 +137,19 @@ pub fn pkg_dep_with<T: ToPkgId>(
.into_iter()
.map(|&(name, values)| (name.into(), values.into_iter().map(|&v| v.into()).collect()))
.collect();
Summary::new(name.to_pkgid(), dep, &features, link, None).unwrap()
Summary::new(name.to_pkgid(), dep, &features, link, None, None).unwrap()
}

pub fn pkg_dep_link<T: ToPkgId>(name: T, link: &str, dep: Vec<Dependency>) -> Summary {
Summary::new(name.to_pkgid(), dep, &BTreeMap::new(), Some(link), None).unwrap()
Summary::new(
name.to_pkgid(),
dep,
&BTreeMap::new(),
Some(link),
None,
None,
)
.unwrap()
}

pub fn pkg_id(name: &str) -> PackageId {
Expand Down Expand Up @@ -177,6 +185,7 @@ pub fn pkg_loc(name: &str, loc: &str) -> Summary {
&BTreeMap::new(),
link,
None,
None,
)
.unwrap()
}
Expand All @@ -185,7 +194,15 @@ pub fn remove_dep(sum: &Summary, ind: usize) -> Summary {
let mut deps = sum.dependencies().to_vec();
deps.remove(ind);
// note: more things will need to be copied over in the future, but it works for now.
Summary::new(sum.package_id(), deps, &BTreeMap::new(), sum.links(), None).unwrap()
Summary::new(
sum.package_id(),
deps,
&BTreeMap::new(),
sum.links(),
None,
None,
)
.unwrap()
}

pub fn dep(name: &str) -> Dependency {
Expand Down
11 changes: 9 additions & 2 deletions crates/resolver-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,15 @@ pub fn resolve_with_global_context_raw(
used: HashSet::new(),
};

let root_summary =
Summary::new(root_pkg_id, deps, &BTreeMap::new(), None::<&String>, None).unwrap();
let root_summary = Summary::new(
root_pkg_id,
deps,
&BTreeMap::new(),
None::<&String>,
None,
None,
)
.unwrap();

let opts = ResolveOpts::everything();

Expand Down
12 changes: 8 additions & 4 deletions src/cargo/core/resolver/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,11 @@ impl<'a, 'gctx> FeatureResolver<'a, 'gctx> {
self.resolve
.deps(pkg_id)
.map(|(dep_id, deps)| {
let proc_macro = self
.resolve
.summary(dep_id)
.proc_macro()
.unwrap_or_else(|| self.has_proc_macro_lib(dep_id));
let deps = deps
.iter()
.filter(|dep| {
Expand Down Expand Up @@ -907,10 +912,9 @@ impl<'a, 'gctx> FeatureResolver<'a, 'gctx> {
// for various targets which are either specified in the manifest
// or on the cargo command-line.
let lib_fk = if fk == FeaturesFor::default() {
(self.track_for_host
&& (dep.is_build() || self.has_proc_macro_lib(dep_id)))
.then(|| FeaturesFor::HostDep)
.unwrap_or_default()
(self.track_for_host && (dep.is_build() || proc_macro))
.then(|| FeaturesFor::HostDep)
.unwrap_or_default()
} else {
fk
};
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/resolver/version_prefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ mod test {
&features,
None::<&String>,
msrv.map(|m| m.parse().unwrap()),
None,
)
.unwrap()
}
Expand Down
6 changes: 6 additions & 0 deletions src/cargo/core/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct Inner {
checksum: Option<String>,
links: Option<InternedString>,
rust_version: Option<RustVersion>,
proc_macro: Option<bool>,
}

/// Indicates the dependency inferred from the `dep` syntax that should exist,
Expand Down Expand Up @@ -68,6 +69,7 @@ impl Summary {
features: &BTreeMap<InternedString, Vec<InternedString>>,
links: Option<impl Into<InternedString>>,
rust_version: Option<RustVersion>,
proc_macro: Option<bool>,
) -> CargoResult<Summary> {
// ****CAUTION**** If you change anything here that may raise a new
// error, be sure to coordinate that change with either the index
Expand All @@ -90,6 +92,7 @@ impl Summary {
checksum: None,
links: links.map(|l| l.into()),
rust_version,
proc_macro,
}),
})
}
Expand All @@ -112,6 +115,9 @@ impl Summary {
pub fn features(&self) -> &FeatureMap {
&self.inner.features
}
pub fn proc_macro(&self) -> &Option<bool> {
&self.inner.proc_macro
}

pub fn checksum(&self) -> Option<&str> {
self.inner.checksum.as_deref()
Expand Down
1 change: 1 addition & 0 deletions src/cargo/ops/cargo_package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ impl<'a> TmpRegistry<'a> {
yanked: None,
links: new_crate.links.map(|x| x.into()),
rust_version: None,
proc_macro: Some(package.proc_macro()),
v: Some(2),
})?;

Expand Down
8 changes: 8 additions & 0 deletions src/cargo/ops/registry/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,13 @@ pub(crate) fn prepare_transmit(
None => BTreeMap::new(),
};

let proc_macro = manifest
.normalized_toml()
.lib
.as_ref()
.and_then(|lib| lib.proc_macro())
.unwrap_or_default();

Ok(NewCrate {
name: publish_pkg.name().to_string(),
vers: publish_pkg.version().to_string(),
Expand All @@ -653,6 +660,7 @@ pub(crate) fn prepare_transmit(
badges: badges.clone(),
links: links.clone(),
rust_version,
proc_macro: Some(proc_macro),
})
}

Expand Down
10 changes: 9 additions & 1 deletion src/cargo/sources/registry/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,14 @@ fn index_package_to_summary(pkg: &IndexPackage<'_>, source_id: SourceId) -> Carg
.map(|(name, values)| (name.into(), values.into_iter().map(|v| v.into()).collect()))
.collect::<BTreeMap<_, _>>();
let links: Option<InternedString> = pkg.links.as_ref().map(|l| l.as_ref().into());
let mut summary = Summary::new(pkgid, deps, &features, links, pkg.rust_version.clone())?;
let mut summary = Summary::new(
pkgid,
deps,
&features,
links,
pkg.rust_version.clone(),
pkg.proc_macro,
)?;
summary.set_checksum(pkg.cksum.clone());
Ok(summary)
}
Expand Down Expand Up @@ -674,6 +681,7 @@ impl IndexSummary {
cksum: Default::default(),
yanked: Default::default(),
links: Default::default(),
proc_macro: Default::default(),
};
let summary = index_package_to_summary(&index, source_id)?;
(index, summary, false)
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 @@ -1725,6 +1725,10 @@ pub fn to_real_manifest(
.unwrap_or_else(|| semver::Version::new(0, 0, 0)),
source_id,
);
let proc_macro = normalized_toml
.lib
.as_ref()
.and_then(|lib| lib.proc_macro());
let summary = {
let summary = Summary::new(
pkgid,
Expand All @@ -1743,6 +1747,7 @@ pub fn to_real_manifest(
.collect(),
normalized_package.links.as_deref(),
rust_version.clone(),
proc_macro,
);
// edition2024 stops exposing implicit features, which will strip weak optional dependencies from `dependencies`,
// need to check whether `dep_name` is stripped as unused dependency
Expand Down
Loading
Loading