mirror of
https://github.com/rust-lang/cargo
synced 2024-08-28 03:39:31 +00:00
Add fields for bindeps on the registry
This commit is contained in:
parent
b2c162c067
commit
3d50f47197
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -588,7 +588,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "crates-io"
|
||||
version = "0.38.1"
|
||||
version = "0.39.0"
|
||||
dependencies = [
|
||||
"curl",
|
||||
"percent-encoding",
|
||||
|
|
|
@ -31,7 +31,7 @@ cargo-util = { version = "0.2.6", path = "crates/cargo-util" }
|
|||
cargo_metadata = "0.14.0"
|
||||
clap = "4.3.23"
|
||||
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"] }
|
||||
curl = "0.4.44"
|
||||
curl-sys = "0.4.65"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "crates-io"
|
||||
version = "0.38.1"
|
||||
version = "0.39.0"
|
||||
rust-version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
|
|
@ -73,6 +73,16 @@ pub struct NewCrateDependency {
|
|||
pub registry: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
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)]
|
||||
|
|
|
@ -12,7 +12,6 @@ use crate::core::compiler::{CompileKind, CompileTarget};
|
|||
use crate::core::{PackageId, SourceId, Summary};
|
||||
use crate::util::errors::CargoResult;
|
||||
use crate::util::interning::InternedString;
|
||||
use crate::util::toml::StringOrVec;
|
||||
use crate::util::OptVersionReq;
|
||||
|
||||
/// Information about a dependency requested by a Cargo manifest.
|
||||
|
@ -468,10 +467,7 @@ impl ser::Serialize for Artifact {
|
|||
SerializedArtifact {
|
||||
kinds: self.kinds(),
|
||||
lib: self.is_lib,
|
||||
target: self.target.as_ref().map(|t| match t {
|
||||
ArtifactTarget::BuildDependencyAssumeTarget => "target",
|
||||
ArtifactTarget::Force(target) => target.rustc_target().as_str(),
|
||||
}),
|
||||
target: self.target.as_ref().map(ArtifactTarget::as_str),
|
||||
}
|
||||
.serialize(s)
|
||||
}
|
||||
|
@ -479,14 +475,14 @@ impl ser::Serialize for Artifact {
|
|||
|
||||
impl Artifact {
|
||||
pub(crate) fn parse(
|
||||
artifacts: &StringOrVec,
|
||||
artifacts: &[impl AsRef<str>],
|
||||
is_lib: bool,
|
||||
target: Option<&str>,
|
||||
) -> CargoResult<Self> {
|
||||
let kinds = ArtifactKind::validate(
|
||||
artifacts
|
||||
.iter()
|
||||
.map(|s| ArtifactKind::parse(s))
|
||||
.map(|s| ArtifactKind::parse(s.as_ref()))
|
||||
.collect::<Result<Vec<_>, _>>()?,
|
||||
)?;
|
||||
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> {
|
||||
self.to_compile_target().map(CompileKind::Target)
|
||||
}
|
||||
|
@ -539,6 +542,7 @@ impl ArtifactTarget {
|
|||
ArtifactTarget::Force(target) => Some(*target),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn to_resolved_compile_kind(
|
||||
&self,
|
||||
root_unit_compile_kind: CompileKind,
|
||||
|
@ -575,20 +579,13 @@ impl ser::Serialize for ArtifactKind {
|
|||
where
|
||||
S: ser::Serializer,
|
||||
{
|
||||
let out: Cow<'_, str> = match *self {
|
||||
ArtifactKind::SelectedBinary(name) => format!("bin:{}", name.as_str()).into(),
|
||||
_ => self.crate_type().into(),
|
||||
};
|
||||
out.serialize(s)
|
||||
self.as_str().serialize(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ArtifactKind {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(match self {
|
||||
ArtifactKind::SelectedBinary(bin_name) => return write!(f, "bin:{bin_name}"),
|
||||
_ => self.crate_type(),
|
||||
})
|
||||
f.write_str(&self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
"bin" => ArtifactKind::AllBinaries,
|
||||
"cdylib" => ArtifactKind::Cdylib,
|
||||
|
|
|
@ -353,6 +353,17 @@ fn transmit(
|
|||
.to_string(),
|
||||
registry: dep_registry,
|
||||
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>>>()?;
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
//! [`RemoteRegistry`]: super::remote::RemoteRegistry
|
||||
//! [`Dependency`]: crate::core::Dependency
|
||||
|
||||
use crate::core::dependency::DepKind;
|
||||
use crate::core::dependency::{DepKind, Artifact};
|
||||
use crate::core::Dependency;
|
||||
use crate::core::{PackageId, SourceId, Summary};
|
||||
use crate::sources::registry::{LoadResponse, RegistryData};
|
||||
|
@ -178,7 +178,7 @@ struct Summaries {
|
|||
/// A lazily parsed [`IndexSummary`].
|
||||
enum MaybeIndexSummary {
|
||||
/// 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 },
|
||||
|
||||
/// An actually parsed summary.
|
||||
|
@ -356,6 +356,10 @@ struct RegistryDependency<'a> {
|
|||
///
|
||||
/// [RFC 1977]: https://rust-lang.github.io/rfcs/1977-public-private-dependencies.html
|
||||
public: Option<bool>,
|
||||
artifact: Option<Vec<Cow<'a, str>>>,
|
||||
bindep_target: Option<Cow<'a, str>>,
|
||||
#[serde(default)]
|
||||
lib: bool,
|
||||
}
|
||||
|
||||
impl<'cfg> RegistryIndex<'cfg> {
|
||||
|
@ -409,6 +413,8 @@ impl<'cfg> RegistryIndex<'cfg> {
|
|||
where
|
||||
'a: 'b,
|
||||
{
|
||||
let bindeps = self.config.cli_unstable().bindeps;
|
||||
|
||||
let source_id = self.source_id;
|
||||
|
||||
// First up parse what summaries we have available.
|
||||
|
@ -434,7 +440,9 @@ impl<'cfg> RegistryIndex<'cfg> {
|
|||
}
|
||||
})
|
||||
.filter(move |is| {
|
||||
if is.v > INDEX_V_MAX {
|
||||
if is.v == 3 && bindeps {
|
||||
true
|
||||
} else if is.v > INDEX_V_MAX {
|
||||
debug!(
|
||||
"unsupported schema version {} ({} {})",
|
||||
is.v,
|
||||
|
@ -813,7 +821,7 @@ impl<'a> SummariesCache<'a> {
|
|||
.get(..4)
|
||||
.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());
|
||||
if index_v != INDEX_V_MAX {
|
||||
if index_v != INDEX_V_MAX && index_v != 3 {
|
||||
bail!(
|
||||
"index schema version {index_v} doesn't match the version I know ({INDEX_V_MAX})",
|
||||
);
|
||||
|
@ -947,6 +955,9 @@ impl<'a> RegistryDependency<'a> {
|
|||
registry,
|
||||
package,
|
||||
public,
|
||||
artifact,
|
||||
bindep_target,
|
||||
lib,
|
||||
} = self;
|
||||
|
||||
let id = if let Some(registry) = ®istry {
|
||||
|
@ -986,6 +997,11 @@ impl<'a> RegistryDependency<'a> {
|
|||
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)
|
||||
.set_default_features(default_features)
|
||||
.set_features(features)
|
||||
|
|
|
@ -3287,7 +3287,7 @@ impl<P: ResolveToPath + Clone> DetailedTomlDependency<P> {
|
|||
self.target.as_deref(),
|
||||
) {
|
||||
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
|
||||
&& artifact.target() == Some(ArtifactTarget::BuildDependencyAssumeTarget)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue