From 7ec86a118c4eccc5577df531ccfd421253f81f14 Mon Sep 17 00:00:00 2001 From: elchc Date: Wed, 30 Oct 2024 14:07:54 -0400 Subject: [PATCH 1/3] un-ignore test: proc_macro_in_artifact_dep with a network error --- tests/testsuite/artifact_dep.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/testsuite/artifact_dep.rs b/tests/testsuite/artifact_dep.rs index 7360992459b..6d8c309c9a4 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -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. @@ -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(str![[r#" +[UPDATING] `dummy-registry` index +[LOCKING] 2 packages to latest compatible versions +[DOWNLOADING] crates ... +[DOWNLOADED] bin-uses-pm v1.0.0 (registry `dummy-registry`) +[DOWNLOADING] crates ... +thread 'main' panicked at src/cargo/core/compiler/unit_dependencies.rs:1035:33: +expected pm v1.0.0 to be downloaded +[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace + +"#]]) + .with_status(101) .run(); } From 24738d86902b23239f5d2cff9a3709cf8c3c85c0 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 30 Oct 2024 10:48:05 -0500 Subject: [PATCH 2/3] refactor download_accessible in package.rs --- src/cargo/core/package.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index ac1bcdc5cb7..262290ba493 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -499,17 +499,18 @@ impl<'gctx> PackageSet<'gctx> { force_all_targets: ForceAllTargets, ) -> CargoResult<()> { fn collect_used_deps( - used: &mut BTreeSet, + used: &mut BTreeSet<(PackageId, CompileKind)>, resolve: &Resolve, pkg_id: PackageId, has_dev_units: HasDevUnits, - requested_kinds: &[CompileKind], + requested_kind: CompileKind, 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, @@ -524,7 +525,7 @@ impl<'gctx> PackageSet<'gctx> { resolve, pkg_id, has_dev_units, - requested_kinds, + requested_kind, target_data, force_all_targets, )?; @@ -538,16 +539,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::>(); self.get_many(to_download.into_iter())?; Ok(()) } From d1252625450616d7172bdac98a50010d3eb4c29f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 30 Oct 2024 10:55:58 -0500 Subject: [PATCH 3/3] download transitive deps of artifact deps on target platform --- src/cargo/core/package.rs | 20 +++++++++++++++++++- tests/testsuite/artifact_dep.rs | 24 ++++++++++++------------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 262290ba493..d4315197bbe 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -519,7 +519,7 @@ 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, @@ -529,6 +529,24 @@ impl<'gctx> PackageSet<'gctx> { target_data, force_all_targets, )?; + let artifact_kinds = deps.iter().filter_map(|dep| { + 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(()) } diff --git a/tests/testsuite/artifact_dep.rs b/tests/testsuite/artifact_dep.rs index 6d8c309c9a4..7b438d31054 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -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(); } @@ -1827,17 +1827,17 @@ 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 ... -[DOWNLOADED] bin-uses-pm v1.0.0 (registry `dummy-registry`) -[DOWNLOADING] crates ... -thread 'main' panicked at src/cargo/core/compiler/unit_dependencies.rs:1035:33: -expected pm v1.0.0 to be downloaded -[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace +[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(); }