Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download targeted transitive deps of with artifact deps' target platform #14723

Merged
merged 3 commits into from
Oct 30, 2024
Merged
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
53 changes: 39 additions & 14 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,18 @@ impl<'gctx> PackageSet<'gctx> {
force_all_targets: ForceAllTargets,
) -> CargoResult<()> {
fn collect_used_deps(
used: &mut BTreeSet<PackageId>,
used: &mut BTreeSet<(PackageId, CompileKind)>,
resolve: &Resolve,
pkg_id: PackageId,
has_dev_units: HasDevUnits,
requested_kinds: &[CompileKind],
requested_kind: CompileKind,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems mostly correct to me. Cargo allows only one target platform per artifact deps. Thanks folks. 👍🏾

With this RFC the approach here might still have some issues but it is not even landed yet so no need to worry
https://rust-lang.github.io/rfcs/3176-cargo-multi-dep-artifacts.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we would do in that situation is just call collect_used_deps for each target. This errs on the side of walking the tree multiple times, once for each target, rather than trying to keep state so that we only walk once.

target_data: &RustcTargetData<'_>,
force_all_targets: ForceAllTargets,
) -> CargoResult<()> {
if !used.insert(pkg_id) {
if !used.insert((pkg_id, requested_kind)) {
return Ok(());
}
let requested_kinds = &[requested_kind];
let filtered_deps = PackageSet::filter_deps(
pkg_id,
resolve,
Expand All @@ -518,16 +519,34 @@ impl<'gctx> PackageSet<'gctx> {
target_data,
force_all_targets,
);
for (pkg_id, _dep) in filtered_deps {
for (pkg_id, deps) in filtered_deps {
collect_used_deps(
used,
resolve,
pkg_id,
has_dev_units,
requested_kinds,
requested_kind,
target_data,
force_all_targets,
)?;
let artifact_kinds = deps.iter().filter_map(|dep| {
epage marked this conversation as resolved.
Show resolved Hide resolved
Some(
dep.artifact()?
.target()?
.to_resolved_compile_kind(*requested_kinds.iter().next().unwrap()),
)
});
for artifact_kind in artifact_kinds {
collect_used_deps(
used,
resolve,
pkg_id,
has_dev_units,
artifact_kind,
target_data,
force_all_targets,
)?;
}
}
Ok(())
}
Expand All @@ -538,16 +557,22 @@ impl<'gctx> PackageSet<'gctx> {
let mut to_download = BTreeSet::new();

for id in root_ids {
collect_used_deps(
&mut to_download,
resolve,
*id,
has_dev_units,
requested_kinds,
target_data,
force_all_targets,
)?;
for requested_kind in requested_kinds {
collect_used_deps(
&mut to_download,
resolve,
*id,
has_dev_units,
*requested_kind,
target_data,
force_all_targets,
)?;
}
}
let to_download = to_download
.into_iter()
.map(|(p, _)| p)
.collect::<BTreeSet<_>>();
self.get_many(to_download.into_iter())?;
Ok(())
}
Expand Down
25 changes: 17 additions & 8 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1646,16 +1646,16 @@ fn dep_of_artifact_dep_same_target_specified() {
.with_status(0)
.run();

// TODO This command currently fails due to a bug in cargo but it should be fixed so that it succeeds in the future.
p.cargo("tree -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_data(
.with_stdout_data(
r#"...
no entry found for key
...
foo v0.1.0 ([ROOT]/foo)
└── bar v0.1.0 ([ROOT]/foo/bar)
└── baz v0.1.0 ([ROOT]/foo/baz)
"#,
)
.with_status(101)
.with_status(0)
.run();
}

Expand Down Expand Up @@ -1777,9 +1777,7 @@ perhaps a crate was updated and forgotten to be re-vendored?
.run();
}

// FIXME: `download_accessible` should work properly for artifact dependencies
#[cargo_test]
#[ignore = "broken, needs download_accessible fix"]
fn proc_macro_in_artifact_dep() {
// Forcing FeatureResolver to check a proc-macro for a dependency behind a
// target dependency.
Expand Down Expand Up @@ -1829,7 +1827,18 @@ fn proc_macro_in_artifact_dep() {

p.cargo("check -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_data(str![[r#""#]])
.with_stderr_data(
r#"...
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[ERROR] failed to download from `[ROOTURL]/dl/pm/1.0.0/download`

Caused by:
[37] Could[..]t read a file:// file (Couldn't open file [ROOT]/dl/pm/1.0.0/download)
"#,
)
.with_status(101)
.run();
}

Expand Down