Skip to content

Commit 3e30921

Browse files
committed
Add artifact dependency fields to structures
1 parent 393ce5b commit 3e30921

File tree

8 files changed

+54
-22
lines changed

8 files changed

+54
-22
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bytesize = "1.0"
3434
cargo-platform = { path = "crates/cargo-platform", version = "0.1.3" }
3535
cargo-util = { path = "crates/cargo-util", version = "0.2.4" }
3636
clap = { version = "4.2.0", features = ["wrap_help"] }
37-
crates-io = { path = "crates/crates-io", version = "0.36.1" }
37+
crates-io = { path = "crates/crates-io", version = "0.37.0" }
3838
curl = { version = "0.4.44", features = ["http2"] }
3939
curl-sys = "0.4.61"
4040
env_logger = "0.10.0"

crates/crates-io/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "crates-io"
3-
version = "0.36.1"
3+
version = "0.37.0"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
repository = "https://github.com/rust-lang/cargo"

crates/crates-io/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ pub struct NewCrateDependency {
7373
pub registry: Option<String>,
7474
#[serde(skip_serializing_if = "Option::is_none")]
7575
pub explicit_name_in_toml: Option<String>,
76+
#[serde(skip_serializing_if = "Option::is_none")]
77+
pub artifact: Option<Vec<String>>,
78+
#[serde(skip_serializing_if = "Option::is_none")]
79+
pub bindep_target: Option<String>,
80+
#[serde(default)]
81+
pub lib: bool,
7682
}
7783

7884
#[derive(Deserialize)]

src/cargo/core/dependency.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::core::compiler::{CompileKind, CompileTarget};
1212
use crate::core::{PackageId, SourceId, Summary};
1313
use crate::util::errors::CargoResult;
1414
use crate::util::interning::InternedString;
15-
use crate::util::toml::StringOrVec;
1615
use crate::util::OptVersionReq;
1716

1817
/// Information about a dependency requested by a Cargo manifest.
@@ -468,25 +467,22 @@ impl ser::Serialize for Artifact {
468467
SerializedArtifact {
469468
kinds: self.kinds(),
470469
lib: self.is_lib,
471-
target: self.target.as_ref().map(|t| match t {
472-
ArtifactTarget::BuildDependencyAssumeTarget => "target",
473-
ArtifactTarget::Force(target) => target.rustc_target().as_str(),
474-
}),
470+
target: self.target.as_ref().map(ArtifactTarget::as_str),
475471
}
476472
.serialize(s)
477473
}
478474
}
479475

480476
impl Artifact {
481477
pub(crate) fn parse(
482-
artifacts: &StringOrVec,
478+
artifacts: &[impl AsRef<str>],
483479
is_lib: bool,
484480
target: Option<&str>,
485481
) -> CargoResult<Self> {
486482
let kinds = ArtifactKind::validate(
487483
artifacts
488484
.iter()
489-
.map(|s| ArtifactKind::parse(s))
485+
.map(|s| ArtifactKind::parse(s.as_ref()))
490486
.collect::<Result<Vec<_>, _>>()?,
491487
)?;
492488
Ok(Artifact {
@@ -529,6 +525,13 @@ impl ArtifactTarget {
529525
})
530526
}
531527

528+
pub fn as_str(&self) -> &str {
529+
match self {
530+
ArtifactTarget::BuildDependencyAssumeTarget => "target",
531+
ArtifactTarget::Force(target) => target.rustc_target().as_str(),
532+
}
533+
}
534+
532535
pub fn to_compile_kind(&self) -> Option<CompileKind> {
533536
self.to_compile_target().map(CompileKind::Target)
534537
}
@@ -539,6 +542,7 @@ impl ArtifactTarget {
539542
ArtifactTarget::Force(target) => Some(*target),
540543
}
541544
}
545+
542546
pub(crate) fn to_resolved_compile_kind(
543547
&self,
544548
root_unit_compile_kind: CompileKind,
@@ -575,20 +579,13 @@ impl ser::Serialize for ArtifactKind {
575579
where
576580
S: ser::Serializer,
577581
{
578-
let out: Cow<'_, str> = match *self {
579-
ArtifactKind::SelectedBinary(name) => format!("bin:{}", name.as_str()).into(),
580-
_ => self.crate_type().into(),
581-
};
582-
out.serialize(s)
582+
self.as_str().serialize(s)
583583
}
584584
}
585585

586586
impl fmt::Display for ArtifactKind {
587587
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
588-
f.write_str(match self {
589-
ArtifactKind::SelectedBinary(bin_name) => return write!(f, "bin:{bin_name}"),
590-
_ => self.crate_type(),
591-
})
588+
f.write_str(&self.as_str())
592589
}
593590
}
594591

@@ -604,7 +601,14 @@ impl ArtifactKind {
604601
}
605602
}
606603

607-
fn parse(kind: &str) -> CargoResult<Self> {
604+
pub fn as_str(&self) -> Cow<'static, str> {
605+
match *self {
606+
ArtifactKind::SelectedBinary(name) => format!("bin:{}", name.as_str()).into(),
607+
_ => self.crate_type().into(),
608+
}
609+
}
610+
611+
pub fn parse(kind: &str) -> CargoResult<Self> {
608612
Ok(match kind {
609613
"bin" => ArtifactKind::AllBinaries,
610614
"cdylib" => ArtifactKind::Cdylib,

src/cargo/ops/registry.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,17 @@ fn transmit(
328328
.to_string(),
329329
registry: dep_registry,
330330
explicit_name_in_toml: dep.explicit_name_in_toml().map(|s| s.to_string()),
331+
artifact: dep.artifact().map(|artifact| {
332+
artifact
333+
.kinds()
334+
.iter()
335+
.map(|x| x.as_str().into_owned())
336+
.collect()
337+
}),
338+
bindep_target: dep.artifact().and_then(|artifact| {
339+
artifact.target().map(|target| target.as_str().to_owned())
340+
}),
341+
lib: dep.artifact().map_or(false, |artifact| artifact.is_lib()),
331342
})
332343
})
333344
.collect::<CargoResult<Vec<NewCrateDependency>>>()?;

src/cargo/sources/registry/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ use semver::Version;
174174
use serde::Deserialize;
175175
use tar::Archive;
176176

177-
use crate::core::dependency::{DepKind, Dependency};
177+
use crate::core::dependency::{Artifact, DepKind, Dependency};
178178
use crate::core::source::MaybePackage;
179179
use crate::core::{Package, PackageId, QueryKind, Source, SourceId, Summary};
180180
use crate::sources::PathSource;
@@ -363,6 +363,9 @@ struct RegistryDependency<'a> {
363363
registry: Option<Cow<'a, str>>,
364364
package: Option<InternedString>,
365365
public: Option<bool>,
366+
artifact: Option<Vec<Cow<'a, str>>>,
367+
bindep_target: Option<Cow<'a, str>>,
368+
lib: bool,
366369
}
367370

368371
impl<'a> RegistryDependency<'a> {
@@ -379,6 +382,9 @@ impl<'a> RegistryDependency<'a> {
379382
registry,
380383
package,
381384
public,
385+
artifact,
386+
bindep_target,
387+
lib,
382388
} = self;
383389

384390
let id = if let Some(registry) = &registry {
@@ -418,6 +424,11 @@ impl<'a> RegistryDependency<'a> {
418424
dep.set_registry_id(id);
419425
}
420426

427+
if let Some(artifacts) = artifact {
428+
let artifact = Artifact::parse(&artifacts, lib, bindep_target.as_deref())?;
429+
dep.set_artifact(artifact);
430+
}
431+
421432
dep.set_optional(optional)
422433
.set_default_features(default_features)
423434
.set_features(features)

src/cargo/util/toml/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3206,7 +3206,7 @@ impl<P: ResolveToPath + Clone> DetailedTomlDependency<P> {
32063206
self.target.as_deref(),
32073207
) {
32083208
if cx.config.cli_unstable().bindeps {
3209-
let artifact = Artifact::parse(artifact, is_lib, target)?;
3209+
let artifact = Artifact::parse(&artifact.0, is_lib, target)?;
32103210
if dep.kind() != DepKind::Build
32113211
&& artifact.target() == Some(ArtifactTarget::BuildDependencyAssumeTarget)
32123212
{

0 commit comments

Comments
 (0)