Add fields for bindeps on the registry

This commit is contained in:
Deadbeef 2023-07-30 17:52:22 +00:00
parent b2c162c067
commit 3d50f47197
8 changed files with 66 additions and 25 deletions

2
Cargo.lock generated
View file

@ -588,7 +588,7 @@ dependencies = [
[[package]] [[package]]
name = "crates-io" name = "crates-io"
version = "0.38.1" version = "0.39.0"
dependencies = [ dependencies = [
"curl", "curl",
"percent-encoding", "percent-encoding",

View file

@ -31,7 +31,7 @@ cargo-util = { version = "0.2.6", path = "crates/cargo-util" }
cargo_metadata = "0.14.0" cargo_metadata = "0.14.0"
clap = "4.3.23" clap = "4.3.23"
core-foundation = { version = "0.9.3", features = ["mac_os_10_7_support"] } core-foundation = { version = "0.9.3", features = ["mac_os_10_7_support"] }
crates-io = { version = "0.38.0", path = "crates/crates-io" } crates-io = { version = "0.39.0", path = "crates/crates-io" }
criterion = { version = "0.5.1", features = ["html_reports"] } criterion = { version = "0.5.1", features = ["html_reports"] }
curl = "0.4.44" curl = "0.4.44"
curl-sys = "0.4.65" curl-sys = "0.4.65"

View file

@ -1,6 +1,6 @@
[package] [package]
name = "crates-io" name = "crates-io"
version = "0.38.1" version = "0.39.0"
rust-version.workspace = true rust-version.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View file

@ -73,6 +73,16 @@ pub struct NewCrateDependency {
pub registry: Option<String>, pub registry: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub explicit_name_in_toml: Option<String>, pub explicit_name_in_toml: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub artifact: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bindep_target: Option<String>,
#[serde(default, skip_serializing_if = "is_false")]
pub lib: bool,
}
fn is_false(x: &bool) -> bool {
*x == false
} }
#[derive(Deserialize)] #[derive(Deserialize)]

View file

@ -12,7 +12,6 @@ use crate::core::compiler::{CompileKind, CompileTarget};
use crate::core::{PackageId, SourceId, Summary}; use crate::core::{PackageId, SourceId, Summary};
use crate::util::errors::CargoResult; use crate::util::errors::CargoResult;
use crate::util::interning::InternedString; use crate::util::interning::InternedString;
use crate::util::toml::StringOrVec;
use crate::util::OptVersionReq; use crate::util::OptVersionReq;
/// Information about a dependency requested by a Cargo manifest. /// Information about a dependency requested by a Cargo manifest.
@ -468,10 +467,7 @@ impl ser::Serialize for Artifact {
SerializedArtifact { SerializedArtifact {
kinds: self.kinds(), kinds: self.kinds(),
lib: self.is_lib, lib: self.is_lib,
target: self.target.as_ref().map(|t| match t { target: self.target.as_ref().map(ArtifactTarget::as_str),
ArtifactTarget::BuildDependencyAssumeTarget => "target",
ArtifactTarget::Force(target) => target.rustc_target().as_str(),
}),
} }
.serialize(s) .serialize(s)
} }
@ -479,14 +475,14 @@ impl ser::Serialize for Artifact {
impl Artifact { impl Artifact {
pub(crate) fn parse( pub(crate) fn parse(
artifacts: &StringOrVec, artifacts: &[impl AsRef<str>],
is_lib: bool, is_lib: bool,
target: Option<&str>, target: Option<&str>,
) -> CargoResult<Self> { ) -> CargoResult<Self> {
let kinds = ArtifactKind::validate( let kinds = ArtifactKind::validate(
artifacts artifacts
.iter() .iter()
.map(|s| ArtifactKind::parse(s)) .map(|s| ArtifactKind::parse(s.as_ref()))
.collect::<Result<Vec<_>, _>>()?, .collect::<Result<Vec<_>, _>>()?,
)?; )?;
Ok(Artifact { Ok(Artifact {
@ -529,6 +525,13 @@ impl ArtifactTarget {
}) })
} }
pub fn as_str(&self) -> &str {
match self {
ArtifactTarget::BuildDependencyAssumeTarget => "target",
ArtifactTarget::Force(target) => target.rustc_target().as_str(),
}
}
pub fn to_compile_kind(&self) -> Option<CompileKind> { pub fn to_compile_kind(&self) -> Option<CompileKind> {
self.to_compile_target().map(CompileKind::Target) self.to_compile_target().map(CompileKind::Target)
} }
@ -539,6 +542,7 @@ impl ArtifactTarget {
ArtifactTarget::Force(target) => Some(*target), ArtifactTarget::Force(target) => Some(*target),
} }
} }
pub(crate) fn to_resolved_compile_kind( pub(crate) fn to_resolved_compile_kind(
&self, &self,
root_unit_compile_kind: CompileKind, root_unit_compile_kind: CompileKind,
@ -575,20 +579,13 @@ impl ser::Serialize for ArtifactKind {
where where
S: ser::Serializer, S: ser::Serializer,
{ {
let out: Cow<'_, str> = match *self { self.as_str().serialize(s)
ArtifactKind::SelectedBinary(name) => format!("bin:{}", name.as_str()).into(),
_ => self.crate_type().into(),
};
out.serialize(s)
} }
} }
impl fmt::Display for ArtifactKind { impl fmt::Display for ArtifactKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self { f.write_str(&self.as_str())
ArtifactKind::SelectedBinary(bin_name) => return write!(f, "bin:{bin_name}"),
_ => self.crate_type(),
})
} }
} }
@ -604,7 +601,14 @@ impl ArtifactKind {
} }
} }
fn parse(kind: &str) -> CargoResult<Self> { pub fn as_str(&self) -> Cow<'static, str> {
match *self {
ArtifactKind::SelectedBinary(name) => format!("bin:{}", name.as_str()).into(),
_ => self.crate_type().into(),
}
}
pub fn parse(kind: &str) -> CargoResult<Self> {
Ok(match kind { Ok(match kind {
"bin" => ArtifactKind::AllBinaries, "bin" => ArtifactKind::AllBinaries,
"cdylib" => ArtifactKind::Cdylib, "cdylib" => ArtifactKind::Cdylib,

View file

@ -353,6 +353,17 @@ fn transmit(
.to_string(), .to_string(),
registry: dep_registry, registry: dep_registry,
explicit_name_in_toml: dep.explicit_name_in_toml().map(|s| s.to_string()), explicit_name_in_toml: dep.explicit_name_in_toml().map(|s| s.to_string()),
artifact: dep.artifact().map(|artifact| {
artifact
.kinds()
.iter()
.map(|x| x.as_str().into_owned())
.collect()
}),
bindep_target: dep.artifact().and_then(|artifact| {
artifact.target().map(|target| target.as_str().to_owned())
}),
lib: dep.artifact().map_or(false, |artifact| artifact.is_lib()),
}) })
}) })
.collect::<CargoResult<Vec<NewCrateDependency>>>()?; .collect::<CargoResult<Vec<NewCrateDependency>>>()?;

View file

@ -85,7 +85,7 @@
//! [`RemoteRegistry`]: super::remote::RemoteRegistry //! [`RemoteRegistry`]: super::remote::RemoteRegistry
//! [`Dependency`]: crate::core::Dependency //! [`Dependency`]: crate::core::Dependency
use crate::core::dependency::DepKind; use crate::core::dependency::{DepKind, Artifact};
use crate::core::Dependency; use crate::core::Dependency;
use crate::core::{PackageId, SourceId, Summary}; use crate::core::{PackageId, SourceId, Summary};
use crate::sources::registry::{LoadResponse, RegistryData}; use crate::sources::registry::{LoadResponse, RegistryData};
@ -178,7 +178,7 @@ struct Summaries {
/// A lazily parsed [`IndexSummary`]. /// A lazily parsed [`IndexSummary`].
enum MaybeIndexSummary { enum MaybeIndexSummary {
/// A summary which has not been parsed, The `start` and `end` are pointers /// A summary which has not been parsed, The `start` and `end` are pointers
/// into [`Summaries::raw_data`] which this is an entry of. /// into [`Summaries::raw_data`] which this isRegistryDependency an entry of.
Unparsed { start: usize, end: usize }, Unparsed { start: usize, end: usize },
/// An actually parsed summary. /// An actually parsed summary.
@ -356,6 +356,10 @@ struct RegistryDependency<'a> {
/// ///
/// [RFC 1977]: https://rust-lang.github.io/rfcs/1977-public-private-dependencies.html /// [RFC 1977]: https://rust-lang.github.io/rfcs/1977-public-private-dependencies.html
public: Option<bool>, public: Option<bool>,
artifact: Option<Vec<Cow<'a, str>>>,
bindep_target: Option<Cow<'a, str>>,
#[serde(default)]
lib: bool,
} }
impl<'cfg> RegistryIndex<'cfg> { impl<'cfg> RegistryIndex<'cfg> {
@ -409,6 +413,8 @@ impl<'cfg> RegistryIndex<'cfg> {
where where
'a: 'b, 'a: 'b,
{ {
let bindeps = self.config.cli_unstable().bindeps;
let source_id = self.source_id; let source_id = self.source_id;
// First up parse what summaries we have available. // First up parse what summaries we have available.
@ -434,7 +440,9 @@ impl<'cfg> RegistryIndex<'cfg> {
} }
}) })
.filter(move |is| { .filter(move |is| {
if is.v > INDEX_V_MAX { if is.v == 3 && bindeps {
true
} else if is.v > INDEX_V_MAX {
debug!( debug!(
"unsupported schema version {} ({} {})", "unsupported schema version {} ({} {})",
is.v, is.v,
@ -813,7 +821,7 @@ impl<'a> SummariesCache<'a> {
.get(..4) .get(..4)
.ok_or_else(|| anyhow::anyhow!("cache expected 4 bytes for index schema version"))?; .ok_or_else(|| anyhow::anyhow!("cache expected 4 bytes for index schema version"))?;
let index_v = u32::from_le_bytes(index_v_bytes.try_into().unwrap()); let index_v = u32::from_le_bytes(index_v_bytes.try_into().unwrap());
if index_v != INDEX_V_MAX { if index_v != INDEX_V_MAX && index_v != 3 {
bail!( bail!(
"index schema version {index_v} doesn't match the version I know ({INDEX_V_MAX})", "index schema version {index_v} doesn't match the version I know ({INDEX_V_MAX})",
); );
@ -947,6 +955,9 @@ impl<'a> RegistryDependency<'a> {
registry, registry,
package, package,
public, public,
artifact,
bindep_target,
lib,
} = self; } = self;
let id = if let Some(registry) = &registry { let id = if let Some(registry) = &registry {
@ -986,6 +997,11 @@ impl<'a> RegistryDependency<'a> {
dep.set_registry_id(id); dep.set_registry_id(id);
} }
if let Some(artifacts) = artifact {
let artifact = Artifact::parse(&artifacts, lib, bindep_target.as_deref())?;
dep.set_artifact(artifact);
}
dep.set_optional(optional) dep.set_optional(optional)
.set_default_features(default_features) .set_default_features(default_features)
.set_features(features) .set_features(features)

View file

@ -3287,7 +3287,7 @@ impl<P: ResolveToPath + Clone> DetailedTomlDependency<P> {
self.target.as_deref(), self.target.as_deref(),
) { ) {
if cx.config.cli_unstable().bindeps { if cx.config.cli_unstable().bindeps {
let artifact = Artifact::parse(artifact, is_lib, target)?; let artifact = Artifact::parse(&artifact.0, is_lib, target)?;
if dep.kind() != DepKind::Build if dep.kind() != DepKind::Build
&& artifact.target() == Some(ArtifactTarget::BuildDependencyAssumeTarget) && artifact.target() == Some(ArtifactTarget::BuildDependencyAssumeTarget)
{ {