From ca626c5915cd76f855ae9d91e6526cfc4e701a76 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 6 Jan 2023 16:42:15 +0000 Subject: [PATCH 1/5] refactor: reuse crate type strings in `ArtifactKind` --- src/cargo/core/dependency.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/cargo/core/dependency.rs b/src/cargo/core/dependency.rs index b86d2e93194..db4fdd07393 100644 --- a/src/cargo/core/dependency.rs +++ b/src/cargo/core/dependency.rs @@ -566,10 +566,8 @@ impl ser::Serialize for ArtifactKind { S: ser::Serializer, { let out: Cow<'_, str> = match *self { - ArtifactKind::AllBinaries => "bin".into(), - ArtifactKind::Staticlib => "staticlib".into(), - ArtifactKind::Cdylib => "cdylib".into(), ArtifactKind::SelectedBinary(name) => format!("bin:{}", name.as_str()).into(), + _ => self.crate_type().into(), }; out.serialize(s) } @@ -578,15 +576,24 @@ impl ser::Serialize for ArtifactKind { impl fmt::Display for ArtifactKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(match self { - ArtifactKind::Cdylib => "cdylib", - ArtifactKind::Staticlib => "staticlib", - ArtifactKind::AllBinaries => "bin", - ArtifactKind::SelectedBinary(bin_name) => return write!(f, "bin:{}", bin_name), + ArtifactKind::SelectedBinary(bin_name) => return write!(f, "bin:{bin_name}"), + _ => self.crate_type(), }) } } impl ArtifactKind { + /// Returns a string of crate type of the artifact being built. + /// + /// Note that the name of `SelectedBinary` would be dropped and displayed as `bin`. + pub fn crate_type(&self) -> &'static str { + match self { + ArtifactKind::AllBinaries | ArtifactKind::SelectedBinary(_) => "bin", + ArtifactKind::Cdylib => "cdylib", + ArtifactKind::Staticlib => "staticlib", + } + } + fn parse(kind: &str) -> CargoResult { Ok(match kind { "bin" => ArtifactKind::AllBinaries, From e5ec492b6ffe88939d59abe5f751950478b434da Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 6 Jan 2023 17:00:55 +0000 Subject: [PATCH 2/5] cargo-metadata: support -Zbindeps info --- src/cargo/ops/cargo_output_metadata.rs | 136 ++++++++++++++++++++----- tests/testsuite/git.rs | 1 + tests/testsuite/metadata.rs | 98 ++++++++++++++++++ tests/testsuite/update.rs | 1 + 4 files changed, 213 insertions(+), 23 deletions(-) diff --git a/src/cargo/ops/cargo_output_metadata.rs b/src/cargo/ops/cargo_output_metadata.rs index d8a86eae778..e1c970a2315 100644 --- a/src/cargo/ops/cargo_output_metadata.rs +++ b/src/cargo/ops/cargo_output_metadata.rs @@ -1,8 +1,8 @@ use crate::core::compiler::{CompileKind, RustcTargetData}; -use crate::core::dependency::DepKind; +use crate::core::dependency::{ArtifactKind, DepKind}; use crate::core::package::SerializedPackage; use crate::core::resolver::{features::CliFeatures, HasDevUnits, Resolve}; -use crate::core::{Dependency, Package, PackageId, Workspace}; +use crate::core::{Package, PackageId, Target, Workspace}; use crate::ops::{self, Packages}; use crate::util::interning::InternedString; use crate::util::CargoResult; @@ -90,15 +90,26 @@ struct Dep { struct DepKindInfo { kind: DepKind, target: Option, -} -impl From<&Dependency> for DepKindInfo { - fn from(dep: &Dependency) -> DepKindInfo { - DepKindInfo { - kind: dep.kind(), - target: dep.platform().cloned(), - } - } + // vvvvv The fields below are introduced for `-Z bindeps`. + /// Artifact's crate type, e.g. staticlib, cdylib, bin... + #[serde(skip_serializing_if = "Option::is_none")] + artifact: Option<&'static str>, + /// What the manifest calls the crate. + /// + /// A renamed dependency will show the rename instead of original name. + #[serde(skip_serializing_if = "Option::is_none")] + extern_name: Option, + /// Equivalent to `{ target = "…" }` in an artifact dependency requirement. + /// + /// * If the target points to a custom target JSON file, the path will be absolute. + /// * If the target is a build assumed target `{ target = "target" }`, it will show as ``. + #[serde(skip_serializing_if = "Option::is_none")] + compile_target: Option, + /// Executable name for an artifact binary dependency. + #[serde(skip_serializing_if = "Option::is_none")] + bin_name: Option, + // ^^^^^ The fields above are introduced for `-Z bindeps`. } /// Builds the resolve graph as it will be displayed to the user. @@ -206,22 +217,101 @@ fn build_resolve_graph_r( } }) .filter_map(|(dep_id, deps)| { - let mut dep_kinds: Vec<_> = deps.iter().map(DepKindInfo::from).collect(); + let mut dep_kinds = Vec::new(); + + let targets = package_map[&dep_id].targets(); + + // Try to get the extern name for lib, or crate name for bins. + let extern_name = |target| { + resolve + .extern_crate_name_and_dep_name(pkg_id, dep_id, target) + .map(|(ext_crate_name, _)| ext_crate_name) + .ok() + }; + + let lib_target_name = targets.iter().find(|t| t.is_lib()).map(extern_name); + + for dep in deps.iter() { + let mut include_lib = || { + dep_kinds.push(DepKindInfo { + kind: dep.kind(), + target: dep.platform().cloned(), + artifact: None, + extern_name: lib_target_name, + compile_target: None, + bin_name: None, + }); + }; + + // When we do have a library target, include them in deps if... + match (dep.artifact(), lib_target_name) { + // it is also an artifact dep with `{ …, lib = true }` + (Some(a), Some(_)) if a.is_lib() => include_lib(), + // it is not an artifact dep at all + (None, Some(_)) => include_lib(), + _ => {} + } + + // No need to proceed if there is no artifact dependency. + let Some(artifact_requirements) = dep.artifact() else { + continue; + }; + + let compile_target = match artifact_requirements.target() { + Some(t) => t + .to_compile_target() + .map(|t| t.rustc_target()) + // Given that Cargo doesn't know which target it should resolve to, + // when an artifact dep is specified with { target = "target" }, + // keep it with a special "" string, + .or_else(|| Some(InternedString::new(""))), + None => None, + }; + + let mut extend = |kind: &ArtifactKind, filter: &dyn Fn(&&Target) -> bool| { + let iter = targets.iter().filter(filter).map(|target| DepKindInfo { + kind: dep.kind(), + target: dep.platform().cloned(), + artifact: Some(kind.crate_type()), + extern_name: extern_name(target), + compile_target, + bin_name: target.is_bin().then(|| target.name().to_string()), + }); + dep_kinds.extend(iter); + }; + + for kind in artifact_requirements.kinds() { + match kind { + ArtifactKind::Cdylib => extend(kind, &|t| t.is_cdylib()), + ArtifactKind::Staticlib => extend(kind, &|t| t.is_staticlib()), + ArtifactKind::AllBinaries => extend(kind, &|t| t.is_bin()), + ArtifactKind::SelectedBinary(bin_name) => { + extend(kind, &|t| t.is_bin() && t.name() == bin_name.as_str()) + } + }; + } + } + dep_kinds.sort(); - package_map - .get(&dep_id) - .and_then(|pkg| pkg.targets().iter().find(|t| t.is_lib())) - .and_then(|lib_target| { - resolve - .extern_crate_name_and_dep_name(pkg_id, dep_id, lib_target) - .map(|(ext_crate_name, _)| ext_crate_name) - .ok() - }) - .map(|name| Dep { + + let pkg = normalize_id(dep_id); + + match (lib_target_name, dep_kinds.len()) { + (Some(name), _) => Some(Dep { name, - pkg: normalize_id(dep_id), + pkg, dep_kinds, - }) + }), + // No lib target exists but contains artifact deps. + (None, 1..) => Some(Dep { + name: InternedString::new(""), + pkg, + dep_kinds, + }), + // No lib or artifact dep exists. + // Ususally this mean parent depending on non-lib bin crate. + (None, _) => None, + } }) .collect(); let dumb_deps: Vec = deps.iter().map(|dep| normalize_id(dep.pkg)).collect(); diff --git a/tests/testsuite/git.rs b/tests/testsuite/git.rs index 35152e34822..daac773a506 100644 --- a/tests/testsuite/git.rs +++ b/tests/testsuite/git.rs @@ -3393,6 +3393,7 @@ fn metadata_master_consistency() { "pkg": "bar 1.0.0 (__BAR_SOURCE__#__BAR_HASH__)", "dep_kinds": [ { + "extern_name": "bar", "kind": null, "target": null } diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 92e63b5f15e..db2678e13cb 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -526,6 +526,7 @@ fn cargo_metadata_with_deps_and_version() { { "dep_kinds": [ { + "extern_name": "baz", "kind": null, "target": null } @@ -552,6 +553,7 @@ fn cargo_metadata_with_deps_and_version() { { "dep_kinds": [ { + "extern_name": "bar", "kind": null, "target": null } @@ -562,6 +564,7 @@ fn cargo_metadata_with_deps_and_version() { { "dep_kinds": [ { + "extern_name": "foobar", "kind": "dev", "target": null } @@ -1617,20 +1620,57 @@ fn workspace_metadata_with_dependencies_and_resolve() { { "dependencies": [ "artifact 0.5.0 (path+file://[..]/foo/artifact)", + "bin-only-artifact 0.5.0 (path+file://[..]/foo/bin-only-artifact)", "non-artifact 0.5.0 (path+file://[..]/foo/non-artifact)" ], "deps": [ { "dep_kinds": [ { + "extern_name": "artifact", "kind": null, "target": null }, { + "artifact": "bin", + "bin_name": "baz-name", + "compile_target": "wasm32-unknown-unknown", + "extern_name": "baz_name", + "kind": null, + "target": null + }, + { + "artifact": "cdylib", + "compile_target": "wasm32-unknown-unknown", + "extern_name": "artifact", + "kind": null, + "target": null + }, + { + "artifact": "staticlib", + "compile_target": "wasm32-unknown-unknown", + "extern_name": "artifact", + "kind": null, + "target": null + }, + { + "extern_name": "artifact", "kind": "dev", "target": null }, { + "artifact": "bin", + "bin_name": "bar-name", + "compile_target": "", + "extern_name": "bar_name", + "kind": "build", + "target": null + }, + { + "artifact": "bin", + "bin_name": "baz-name", + "compile_target": "", + "extern_name": "baz_name", "kind": "build", "target": null } @@ -1641,14 +1681,53 @@ fn workspace_metadata_with_dependencies_and_resolve() { { "dep_kinds": [ { + "artifact": "bin", + "bin_name": "a-name", + "extern_name": "a_name", + "kind": null, + "target": null + }, + { + "artifact": "bin", + "bin_name": "b-name", + "extern_name": "b_name", + "kind": "dev", + "target": null + }, + { + "artifact": "bin", + "bin_name": "a-name", + "compile_target": "wasm32-unknown-unknown", + "extern_name": "a_name", + "kind": "build", + "target": null + }, + { + "artifact": "bin", + "bin_name": "b-name", + "compile_target": "wasm32-unknown-unknown", + "extern_name": "b_name", + "kind": "build", + "target": null + } + ], + "name": "", + "pkg": "bin-only-artifact 0.5.0 (path+file://[..]/foo/bin-only-artifact)" + }, + { + "dep_kinds": [ + { + "extern_name": "non_artifact", "kind": null, "target": null }, { + "extern_name": "non_artifact", "kind": "dev", "target": null }, { + "extern_name": "non_artifact", "kind": "build", "target": null } @@ -2625,6 +2704,7 @@ fn rename_dependency() { { "dep_kinds": [ { + "extern_name": "bar", "kind": null, "target": null } @@ -2635,6 +2715,7 @@ fn rename_dependency() { { "dep_kinds": [ { + "extern_name": "baz", "kind": null, "target": null } @@ -3251,6 +3332,7 @@ fn filter_platform() { "pkg": "alt-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { + "extern_name": "alt_dep", "kind": null, "target": "$ALT_TRIPLE" } @@ -3261,6 +3343,7 @@ fn filter_platform() { "pkg": "cfg-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { + "extern_name": "cfg_dep", "kind": null, "target": "cfg(foobar)" } @@ -3271,6 +3354,7 @@ fn filter_platform() { "pkg": "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { + "extern_name": "host_dep", "kind": null, "target": "$HOST_TRIPLE" } @@ -3281,6 +3365,7 @@ fn filter_platform() { "pkg": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { + "extern_name": "normal_dep", "kind": null, "target": null } @@ -3362,6 +3447,7 @@ fn filter_platform() { "pkg": "alt-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { + "extern_name": "alt_dep", "kind": null, "target": "$ALT_TRIPLE" } @@ -3372,6 +3458,7 @@ fn filter_platform() { "pkg": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { + "extern_name": "normal_dep", "kind": null, "target": null } @@ -3437,6 +3524,7 @@ fn filter_platform() { "pkg": "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { + "extern_name": "host_dep", "kind": null, "target": "$HOST_TRIPLE" } @@ -3447,6 +3535,7 @@ fn filter_platform() { "pkg": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { + "extern_name": "normal_dep", "kind": null, "target": null } @@ -3528,6 +3617,7 @@ fn filter_platform() { "pkg": "cfg-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { + "extern_name": "cfg_dep", "kind": null, "target": "cfg(foobar)" } @@ -3538,6 +3628,7 @@ fn filter_platform() { "pkg": "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { + "extern_name": "host_dep", "kind": null, "target": "$HOST_TRIPLE" } @@ -3548,6 +3639,7 @@ fn filter_platform() { "pkg": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { + "extern_name": "normal_dep", "kind": null, "target": null } @@ -3645,14 +3737,17 @@ fn dep_kinds() { "pkg": "bar 0.1.0 [..]", "dep_kinds": [ { + "extern_name": "bar", "kind": null, "target": null }, { + "extern_name": "bar", "kind": "dev", "target": null }, { + "extern_name": "bar", "kind": "build", "target": null } @@ -3663,6 +3758,7 @@ fn dep_kinds() { "pkg": "winapi 0.1.0 [..]", "dep_kinds": [ { + "extern_name": "winapi", "kind": null, "target": "cfg(windows)" } @@ -3753,6 +3849,7 @@ fn dep_kinds_workspace() { "pkg": "foo 0.1.0 (path+file://[..]/foo)", "dep_kinds": [ { + "extern_name": "foo", "kind": null, "target": null } @@ -3778,6 +3875,7 @@ fn dep_kinds_workspace() { "pkg": "dep 0.5.0 (path+file://[..]/foo/dep)", "dep_kinds": [ { + "extern_name": "dep", "kind": null, "target": null } diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index 1eef64ea3d4..eebfe413959 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -608,6 +608,7 @@ fn update_precise_first_run() { { "dep_kinds": [ { + "extern_name": "serde", "kind": null, "target": null } From 272193aa299c8597578224ca93781c5c26b78edd Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 6 Jan 2023 21:56:49 +0000 Subject: [PATCH 3/5] cargo-metadata: error out when encountering invalid artifact kind syntax This refactor reuse the logic of `core::compiler::unit_dependencies::match_artifacts_kind_with_targets` to emit error if there is any syntax error in `ArtifactKind`. It also put `match_artifacts_kind_with_targets` to a better place `core::compiler::artifact`. --- src/cargo/core/compiler/artifact.rs | 45 ++++++- src/cargo/core/compiler/unit_dependencies.rs | 130 +++++++------------ src/cargo/ops/cargo_output_metadata.rs | 61 +++++---- tests/testsuite/metadata.rs | 30 +++++ 4 files changed, 153 insertions(+), 113 deletions(-) diff --git a/src/cargo/core/compiler/artifact.rs b/src/cargo/core/compiler/artifact.rs index 148b0feb109..7ca2529a4d1 100644 --- a/src/cargo/core/compiler/artifact.rs +++ b/src/cargo/core/compiler/artifact.rs @@ -1,7 +1,8 @@ /// Generate artifact information from unit dependencies for configuring the compiler environment. use crate::core::compiler::unit_graph::UnitDep; use crate::core::compiler::{Context, CrateType, FileFlavor, Unit}; -use crate::core::TargetKind; +use crate::core::dependency::ArtifactKind; +use crate::core::{Dependency, Target, TargetKind}; use crate::CargoResult; use std::collections::HashMap; use std::ffi::OsString; @@ -55,3 +56,45 @@ fn unit_artifact_type_name_upper(unit: &Unit) -> &'static str { invalid => unreachable!("BUG: artifacts cannot be of type {:?}", invalid), } } + +/// Given a dependency with an artifact `artifact_dep` and a set of available `targets` +/// of its package, find a target for each kind of artifacts that are to be built. +/// +/// Failure to match any target results in an error mentioning the parent manifests +/// `parent_package` name. +pub(crate) fn match_artifacts_kind_with_targets<'a, F>( + artifact_dep: &Dependency, + targets: &'a [Target], + parent_package: &str, + mut callback: F, +) -> CargoResult<()> +where + F: FnMut(&ArtifactKind, &mut dyn Iterator), +{ + let artifact_requirements = artifact_dep.artifact().expect("artifact present"); + for artifact_kind in artifact_requirements.kinds() { + let mut extend = |kind: &ArtifactKind, filter: &dyn Fn(&&Target) -> bool| { + let mut iter = targets.iter().filter(filter).peekable(); + let found = iter.peek().is_some(); + callback(kind, &mut iter); + found + }; + let found = match artifact_kind { + ArtifactKind::Cdylib => extend(artifact_kind, &|t| t.is_cdylib()), + ArtifactKind::Staticlib => extend(artifact_kind, &|t| t.is_staticlib()), + ArtifactKind::AllBinaries => extend(artifact_kind, &|t| t.is_bin()), + ArtifactKind::SelectedBinary(bin_name) => extend(artifact_kind, &|t| { + t.is_bin() && t.name() == bin_name.as_str() + }), + }; + if !found { + anyhow::bail!( + "dependency `{}` in package `{}` requires a `{}` artifact to be present.", + artifact_dep.name_in_toml(), + parent_package, + artifact_kind + ); + } + } + Ok(()) +} diff --git a/src/cargo/core/compiler/unit_dependencies.rs b/src/cargo/core/compiler/unit_dependencies.rs index 64356d47b4b..8603c7e7711 100644 --- a/src/cargo/core/compiler/unit_dependencies.rs +++ b/src/cargo/core/compiler/unit_dependencies.rs @@ -19,11 +19,12 @@ use std::collections::{HashMap, HashSet}; use log::trace; +use crate::core::compiler::artifact::match_artifacts_kind_with_targets; use crate::core::compiler::unit_graph::{UnitDep, UnitGraph}; use crate::core::compiler::{ CompileKind, CompileMode, CrateType, RustcTargetData, Unit, UnitInterner, }; -use crate::core::dependency::{Artifact, ArtifactKind, ArtifactTarget, DepKind}; +use crate::core::dependency::{Artifact, ArtifactTarget, DepKind}; use crate::core::profiles::{Profile, Profiles, UnitFor}; use crate::core::resolver::features::{FeaturesFor, ResolvedFeatures}; use crate::core::resolver::Resolve; @@ -554,87 +555,54 @@ fn artifact_targets_to_unit_deps( artifact_pkg: &Package, dep: &Dependency, ) -> CargoResult> { - let ret = - match_artifacts_kind_with_targets(dep, artifact_pkg.targets(), parent.pkg.name().as_str())? - .into_iter() - .flat_map(|target| { - // We split target libraries into individual units, even though rustc is able - // to produce multiple kinds in an single invocation for the sole reason that - // each artifact kind has its own output directory, something we can't easily - // teach rustc for now. - match target.kind() { - TargetKind::Lib(kinds) => Box::new( - kinds - .iter() - .filter(|tk| matches!(tk, CrateType::Cdylib | CrateType::Staticlib)) - .map(|target_kind| { - new_unit_dep( - state, - parent, - artifact_pkg, - target - .clone() - .set_kind(TargetKind::Lib(vec![target_kind.clone()])), - parent_unit_for, - compile_kind, - CompileMode::Build, - dep.artifact(), - ) - }), - ) as Box>, - _ => Box::new(std::iter::once(new_unit_dep( - state, - parent, - artifact_pkg, - target, - parent_unit_for, - compile_kind, - CompileMode::Build, - dep.artifact(), - ))), - } - }) - .collect::, _>>()?; - Ok(ret) -} - -/// Given a dependency with an artifact `artifact_dep` and a set of available `targets` -/// of its package, find a target for each kind of artifacts that are to be built. -/// -/// Failure to match any target results in an error mentioning the parent manifests -/// `parent_package` name. -fn match_artifacts_kind_with_targets<'a>( - artifact_dep: &Dependency, - targets: &'a [Target], - parent_package: &str, -) -> CargoResult> { - let mut out = HashSet::new(); - let artifact_requirements = artifact_dep.artifact().expect("artifact present"); - for artifact_kind in artifact_requirements.kinds() { - let mut extend = |filter: &dyn Fn(&&Target) -> bool| { - let mut iter = targets.iter().filter(filter).peekable(); - let found = iter.peek().is_some(); - out.extend(iter); - found - }; - let found = match artifact_kind { - ArtifactKind::Cdylib => extend(&|t| t.is_cdylib()), - ArtifactKind::Staticlib => extend(&|t| t.is_staticlib()), - ArtifactKind::AllBinaries => extend(&|t| t.is_bin()), - ArtifactKind::SelectedBinary(bin_name) => { - extend(&|t| t.is_bin() && t.name() == bin_name.as_str()) + let mut targets = HashSet::new(); + match_artifacts_kind_with_targets( + dep, + artifact_pkg.targets(), + parent.pkg.name().as_str(), + |_, iter| targets.extend(iter), + )?; + let ret = targets + .into_iter() + .flat_map(|target| { + // We split target libraries into individual units, even though rustc is able + // to produce multiple kinds in an single invocation for the sole reason that + // each artifact kind has its own output directory, something we can't easily + // teach rustc for now. + match target.kind() { + TargetKind::Lib(kinds) => Box::new( + kinds + .iter() + .filter(|tk| matches!(tk, CrateType::Cdylib | CrateType::Staticlib)) + .map(|target_kind| { + new_unit_dep( + state, + parent, + artifact_pkg, + target + .clone() + .set_kind(TargetKind::Lib(vec![target_kind.clone()])), + parent_unit_for, + compile_kind, + CompileMode::Build, + dep.artifact(), + ) + }), + ) as Box>, + _ => Box::new(std::iter::once(new_unit_dep( + state, + parent, + artifact_pkg, + target, + parent_unit_for, + compile_kind, + CompileMode::Build, + dep.artifact(), + ))), } - }; - if !found { - anyhow::bail!( - "dependency `{}` in package `{}` requires a `{}` artifact to be present.", - artifact_dep.name_in_toml(), - parent_package, - artifact_kind - ); - } - } - Ok(out) + }) + .collect::, _>>()?; + Ok(ret) } /// Returns the dependencies necessary to document a package. diff --git a/src/cargo/ops/cargo_output_metadata.rs b/src/cargo/ops/cargo_output_metadata.rs index e1c970a2315..4b8c04256d8 100644 --- a/src/cargo/ops/cargo_output_metadata.rs +++ b/src/cargo/ops/cargo_output_metadata.rs @@ -1,8 +1,9 @@ +use crate::core::compiler::artifact::match_artifacts_kind_with_targets; use crate::core::compiler::{CompileKind, RustcTargetData}; -use crate::core::dependency::{ArtifactKind, DepKind}; +use crate::core::dependency::DepKind; use crate::core::package::SerializedPackage; use crate::core::resolver::{features::CliFeatures, HasDevUnits, Resolve}; -use crate::core::{Package, PackageId, Target, Workspace}; +use crate::core::{Package, PackageId, Workspace}; use crate::ops::{self, Packages}; use crate::util::interning::InternedString; use crate::util::CargoResult; @@ -160,7 +161,7 @@ fn build_resolve_graph( &package_map, &target_data, &requested_kinds, - ); + )?; } // Get a Vec of Packages. let actual_packages = package_map @@ -183,9 +184,9 @@ fn build_resolve_graph_r( package_map: &BTreeMap, target_data: &RustcTargetData<'_>, requested_kinds: &[CompileKind], -) { +) -> CargoResult<()> { if node_map.contains_key(&pkg_id) { - return; + return Ok(()); } // This normalizes the IDs so that they are consistent between the // `packages` array and the `resolve` map. This is a bit of a hack to @@ -268,27 +269,22 @@ fn build_resolve_graph_r( None => None, }; - let mut extend = |kind: &ArtifactKind, filter: &dyn Fn(&&Target) -> bool| { - let iter = targets.iter().filter(filter).map(|target| DepKindInfo { - kind: dep.kind(), - target: dep.platform().cloned(), - artifact: Some(kind.crate_type()), - extern_name: extern_name(target), - compile_target, - bin_name: target.is_bin().then(|| target.name().to_string()), - }); - dep_kinds.extend(iter); - }; - - for kind in artifact_requirements.kinds() { - match kind { - ArtifactKind::Cdylib => extend(kind, &|t| t.is_cdylib()), - ArtifactKind::Staticlib => extend(kind, &|t| t.is_staticlib()), - ArtifactKind::AllBinaries => extend(kind, &|t| t.is_bin()), - ArtifactKind::SelectedBinary(bin_name) => { - extend(kind, &|t| t.is_bin() && t.name() == bin_name.as_str()) - } - }; + if let Err(e) = match_artifacts_kind_with_targets( + dep, + targets, + pkg_id.name().as_str(), + |kind, targets| { + dep_kinds.extend(targets.map(|target| DepKindInfo { + kind: dep.kind(), + target: dep.platform().cloned(), + artifact: Some(kind.crate_type()), + extern_name: extern_name(target), + compile_target, + bin_name: target.is_bin().then(|| target.name().to_string()), + })) + }, + ) { + return Some(Err(e)); } } @@ -296,7 +292,7 @@ fn build_resolve_graph_r( let pkg = normalize_id(dep_id); - match (lib_target_name, dep_kinds.len()) { + let dep = match (lib_target_name, dep_kinds.len()) { (Some(name), _) => Some(Dep { name, pkg, @@ -311,10 +307,11 @@ fn build_resolve_graph_r( // No lib or artifact dep exists. // Ususally this mean parent depending on non-lib bin crate. (None, _) => None, - } + }; + dep.map(Ok) }) - .collect(); - let dumb_deps: Vec = deps.iter().map(|dep| normalize_id(dep.pkg)).collect(); + .collect::>()?; + let dumb_deps: Vec = deps.iter().map(|dep| dep.pkg).collect(); let to_visit = dumb_deps.clone(); let node = MetadataResolveNode { id: normalize_id(pkg_id), @@ -331,6 +328,8 @@ fn build_resolve_graph_r( package_map, target_data, requested_kinds, - ); + )?; } + + Ok(()) } diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index db2678e13cb..15e64e79e43 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -1857,6 +1857,36 @@ Caused by: .run(); } +#[cargo_test] +fn cargo_metadata_with_invalid_artifact_deps() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.5.0" + + [dependencies] + artifact = { path = "artifact", artifact = "bin:notfound" } + "#, + ) + .file("src/lib.rs", "") + .file("artifact/Cargo.toml", &basic_bin_manifest("artifact")) + .file("artifact/src/main.rs", "fn main() {}") + .build(); + + p.cargo("metadata -Z bindeps") + .masquerade_as_nightly_cargo(&["bindeps"]) + .with_status(101) + .with_stderr( + "\ +[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems +[ERROR] dependency `artifact` in package `foo` requires a `bin:notfound` artifact to be present.", + ) + .run(); +} + const MANIFEST_OUTPUT: &str = r#" { "packages": [{ From 690e6a41284fcb078de20eec008c0b9c488f96a1 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 10 Jan 2023 01:02:09 +0000 Subject: [PATCH 4/5] cargo-metadata: error out if same dep with differnt names Previous, `cargo metadata` allows a dependency with different renamed co-exist. However, its `resolve.nodes.deps` will miss that dependency, which is wrong. After this commit, `cargo metadata starts erroring out for that situation. --- src/cargo/core/compiler/artifact.rs | 21 ++-- src/cargo/core/compiler/unit_dependencies.rs | 89 +++++++-------- src/cargo/ops/cargo_output_metadata.rs | 110 +++++++++---------- tests/testsuite/metadata.rs | 42 ++++++- 4 files changed, 141 insertions(+), 121 deletions(-) diff --git a/src/cargo/core/compiler/artifact.rs b/src/cargo/core/compiler/artifact.rs index 7ca2529a4d1..b1391eccdb0 100644 --- a/src/cargo/core/compiler/artifact.rs +++ b/src/cargo/core/compiler/artifact.rs @@ -4,7 +4,7 @@ use crate::core::compiler::{Context, CrateType, FileFlavor, Unit}; use crate::core::dependency::ArtifactKind; use crate::core::{Dependency, Target, TargetKind}; use crate::CargoResult; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::ffi::OsString; /// Return all environment variables for the given unit-dependencies @@ -62,21 +62,18 @@ fn unit_artifact_type_name_upper(unit: &Unit) -> &'static str { /// /// Failure to match any target results in an error mentioning the parent manifests /// `parent_package` name. -pub(crate) fn match_artifacts_kind_with_targets<'a, F>( - artifact_dep: &Dependency, - targets: &'a [Target], +pub(crate) fn match_artifacts_kind_with_targets<'t, 'd>( + artifact_dep: &'d Dependency, + targets: &'t [Target], parent_package: &str, - mut callback: F, -) -> CargoResult<()> -where - F: FnMut(&ArtifactKind, &mut dyn Iterator), -{ +) -> CargoResult> { + let mut out = HashSet::new(); let artifact_requirements = artifact_dep.artifact().expect("artifact present"); for artifact_kind in artifact_requirements.kinds() { - let mut extend = |kind: &ArtifactKind, filter: &dyn Fn(&&Target) -> bool| { + let mut extend = |kind, filter: &dyn Fn(&&Target) -> bool| { let mut iter = targets.iter().filter(filter).peekable(); let found = iter.peek().is_some(); - callback(kind, &mut iter); + out.extend(std::iter::repeat(kind).zip(iter)); found }; let found = match artifact_kind { @@ -96,5 +93,5 @@ where ); } } - Ok(()) + Ok(out) } diff --git a/src/cargo/core/compiler/unit_dependencies.rs b/src/cargo/core/compiler/unit_dependencies.rs index 8603c7e7711..68fc1e5196d 100644 --- a/src/cargo/core/compiler/unit_dependencies.rs +++ b/src/cargo/core/compiler/unit_dependencies.rs @@ -555,53 +555,48 @@ fn artifact_targets_to_unit_deps( artifact_pkg: &Package, dep: &Dependency, ) -> CargoResult> { - let mut targets = HashSet::new(); - match_artifacts_kind_with_targets( - dep, - artifact_pkg.targets(), - parent.pkg.name().as_str(), - |_, iter| targets.extend(iter), - )?; - let ret = targets - .into_iter() - .flat_map(|target| { - // We split target libraries into individual units, even though rustc is able - // to produce multiple kinds in an single invocation for the sole reason that - // each artifact kind has its own output directory, something we can't easily - // teach rustc for now. - match target.kind() { - TargetKind::Lib(kinds) => Box::new( - kinds - .iter() - .filter(|tk| matches!(tk, CrateType::Cdylib | CrateType::Staticlib)) - .map(|target_kind| { - new_unit_dep( - state, - parent, - artifact_pkg, - target - .clone() - .set_kind(TargetKind::Lib(vec![target_kind.clone()])), - parent_unit_for, - compile_kind, - CompileMode::Build, - dep.artifact(), - ) - }), - ) as Box>, - _ => Box::new(std::iter::once(new_unit_dep( - state, - parent, - artifact_pkg, - target, - parent_unit_for, - compile_kind, - CompileMode::Build, - dep.artifact(), - ))), - } - }) - .collect::, _>>()?; + let ret = + match_artifacts_kind_with_targets(dep, artifact_pkg.targets(), parent.pkg.name().as_str())? + .into_iter() + .map(|(_artifact_kind, target)| target) + .flat_map(|target| { + // We split target libraries into individual units, even though rustc is able + // to produce multiple kinds in an single invocation for the sole reason that + // each artifact kind has its own output directory, something we can't easily + // teach rustc for now. + match target.kind() { + TargetKind::Lib(kinds) => Box::new( + kinds + .iter() + .filter(|tk| matches!(tk, CrateType::Cdylib | CrateType::Staticlib)) + .map(|target_kind| { + new_unit_dep( + state, + parent, + artifact_pkg, + target + .clone() + .set_kind(TargetKind::Lib(vec![target_kind.clone()])), + parent_unit_for, + compile_kind, + CompileMode::Build, + dep.artifact(), + ) + }), + ) as Box>, + _ => Box::new(std::iter::once(new_unit_dep( + state, + parent, + artifact_pkg, + target, + parent_unit_for, + compile_kind, + CompileMode::Build, + dep.artifact(), + ))), + } + }) + .collect::, _>>()?; Ok(ret) } diff --git a/src/cargo/ops/cargo_output_metadata.rs b/src/cargo/ops/cargo_output_metadata.rs index 4b8c04256d8..e9713e4826b 100644 --- a/src/cargo/ops/cargo_output_metadata.rs +++ b/src/cargo/ops/cargo_output_metadata.rs @@ -91,16 +91,15 @@ struct Dep { struct DepKindInfo { kind: DepKind, target: Option, + /// What the manifest calls the crate. + /// + /// A renamed dependency will show the rename instead of original name. + extern_name: InternedString, // vvvvv The fields below are introduced for `-Z bindeps`. /// Artifact's crate type, e.g. staticlib, cdylib, bin... #[serde(skip_serializing_if = "Option::is_none")] artifact: Option<&'static str>, - /// What the manifest calls the crate. - /// - /// A renamed dependency will show the rename instead of original name. - #[serde(skip_serializing_if = "Option::is_none")] - extern_name: Option, /// Equivalent to `{ target = "…" }` in an artifact dependency requirement. /// /// * If the target points to a custom target JSON file, the path will be absolute. @@ -205,9 +204,9 @@ fn build_resolve_graph_r( let normalize_id = |id| -> PackageId { *package_map.get_key_value(&id).unwrap().0 }; let features = resolve.features(pkg_id).to_vec(); - let deps: Vec = resolve - .deps(pkg_id) - .filter(|(_dep_id, deps)| { + let deps = { + let mut dep_metadatas = Vec::new(); + let iter = resolve.deps(pkg_id).filter(|(_dep_id, deps)| { if requested_kinds == [CompileKind::Host] { true } else { @@ -216,8 +215,8 @@ fn build_resolve_graph_r( .any(|dep| target_data.dep_platform_activated(dep, *kind)) }) } - }) - .filter_map(|(dep_id, deps)| { + }); + for (dep_id, deps) in iter { let mut dep_kinds = Vec::new(); let targets = package_map[&dep_id].targets(); @@ -227,30 +226,30 @@ fn build_resolve_graph_r( resolve .extern_crate_name_and_dep_name(pkg_id, dep_id, target) .map(|(ext_crate_name, _)| ext_crate_name) - .ok() }; - let lib_target_name = targets.iter().find(|t| t.is_lib()).map(extern_name); + let lib_target = targets.iter().find(|t| t.is_lib()); for dep in deps.iter() { - let mut include_lib = || { - dep_kinds.push(DepKindInfo { - kind: dep.kind(), - target: dep.platform().cloned(), - artifact: None, - extern_name: lib_target_name, - compile_target: None, - bin_name: None, - }); - }; - - // When we do have a library target, include them in deps if... - match (dep.artifact(), lib_target_name) { - // it is also an artifact dep with `{ …, lib = true }` - (Some(a), Some(_)) if a.is_lib() => include_lib(), - // it is not an artifact dep at all - (None, Some(_)) => include_lib(), - _ => {} + if let Some(target) = lib_target { + // When we do have a library target, include them in deps if... + let included = match dep.artifact() { + // it is not an artifact dep at all + None => true, + // it is also an artifact dep with `{ …, lib = true }` + Some(a) if a.is_lib() => true, + _ => false, + }; + if included { + dep_kinds.push(DepKindInfo { + kind: dep.kind(), + target: dep.platform().cloned(), + extern_name: extern_name(target)?, + artifact: None, + compile_target: None, + bin_name: None, + }); + } } // No need to proceed if there is no artifact dependency. @@ -269,22 +268,18 @@ fn build_resolve_graph_r( None => None, }; - if let Err(e) = match_artifacts_kind_with_targets( - dep, - targets, - pkg_id.name().as_str(), - |kind, targets| { - dep_kinds.extend(targets.map(|target| DepKindInfo { - kind: dep.kind(), - target: dep.platform().cloned(), - artifact: Some(kind.crate_type()), - extern_name: extern_name(target), - compile_target, - bin_name: target.is_bin().then(|| target.name().to_string()), - })) - }, - ) { - return Some(Err(e)); + let target_set = + match_artifacts_kind_with_targets(dep, targets, pkg_id.name().as_str())?; + dep_kinds.reserve(target_set.len()); + for (kind, target) in target_set.into_iter() { + dep_kinds.push(DepKindInfo { + kind: dep.kind(), + target: dep.platform().cloned(), + extern_name: extern_name(target)?, + artifact: Some(kind.crate_type()), + compile_target, + bin_name: target.is_bin().then(|| target.name().to_string()), + }) } } @@ -292,25 +287,28 @@ fn build_resolve_graph_r( let pkg = normalize_id(dep_id); - let dep = match (lib_target_name, dep_kinds.len()) { - (Some(name), _) => Some(Dep { - name, + let dep = match (lib_target, dep_kinds.len()) { + (Some(target), _) => Dep { + name: extern_name(target)?, pkg, dep_kinds, - }), + }, // No lib target exists but contains artifact deps. - (None, 1..) => Some(Dep { + (None, 1..) => Dep { name: InternedString::new(""), pkg, dep_kinds, - }), + }, // No lib or artifact dep exists. // Ususally this mean parent depending on non-lib bin crate. - (None, _) => None, + (None, _) => continue, }; - dep.map(Ok) - }) - .collect::>()?; + + dep_metadatas.push(dep) + } + dep_metadatas + }; + let dumb_deps: Vec = deps.iter().map(|dep| dep.pkg).collect(); let to_visit = dumb_deps.clone(); let node = MetadataResolveNode { diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 15e64e79e43..897470f01e3 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -1632,24 +1632,24 @@ fn workspace_metadata_with_dependencies_and_resolve() { "target": null }, { - "artifact": "bin", - "bin_name": "baz-name", + "artifact": "cdylib", "compile_target": "wasm32-unknown-unknown", - "extern_name": "baz_name", + "extern_name": "artifact", "kind": null, "target": null }, { - "artifact": "cdylib", + "artifact": "staticlib", "compile_target": "wasm32-unknown-unknown", "extern_name": "artifact", "kind": null, "target": null }, { - "artifact": "staticlib", + "artifact": "bin", + "bin_name": "baz-name", "compile_target": "wasm32-unknown-unknown", - "extern_name": "artifact", + "extern_name": "baz_name", "kind": null, "target": null }, @@ -1887,6 +1887,36 @@ fn cargo_metadata_with_invalid_artifact_deps() { .run(); } +#[cargo_test] +fn cargo_metadata_with_invalid_duplicate_renamed_deps() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.5.0" + + [dependencies] + bar = { path = "bar" } + baz = { path = "bar", package = "bar" } + "#, + ) + .file("src/lib.rs", "") + .file("bar/Cargo.toml", &basic_lib_manifest("bar")) + .file("bar/src/lib.rs", "") + .build(); + + p.cargo("metadata") + .with_status(101) + .with_stderr( + "\ +[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems +[ERROR] the crate `foo v0.5.0 ([..])` depends on crate `bar v0.5.0 ([..])` multiple times with different names", + ) + .run(); +} + const MANIFEST_OUTPUT: &str = r#" { "packages": [{ From d02e36cea10f703c7c39761f1484511304554910 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Mon, 16 Jan 2023 13:27:19 +0000 Subject: [PATCH 5/5] Only output field `extern_name` when using -Zbindeps --- src/cargo/ops/cargo_output_metadata.rs | 22 ++++++++++++++---- tests/testsuite/git.rs | 1 - tests/testsuite/metadata.rs | 32 +++----------------------- tests/testsuite/update.rs | 1 - 4 files changed, 20 insertions(+), 36 deletions(-) diff --git a/src/cargo/ops/cargo_output_metadata.rs b/src/cargo/ops/cargo_output_metadata.rs index e9713e4826b..c71cfaa1e2e 100644 --- a/src/cargo/ops/cargo_output_metadata.rs +++ b/src/cargo/ops/cargo_output_metadata.rs @@ -82,6 +82,8 @@ struct MetadataResolveNode { #[derive(Serialize)] struct Dep { + // TODO(bindeps): after -Zbindeps gets stabilized, + // mark this field as deprecated in the help manual of cargo-metadata name: InternedString, pkg: PackageId, dep_kinds: Vec, @@ -91,12 +93,14 @@ struct Dep { struct DepKindInfo { kind: DepKind, target: Option, + + // vvvvv The fields below are introduced for `-Z bindeps`. /// What the manifest calls the crate. /// /// A renamed dependency will show the rename instead of original name. - extern_name: InternedString, - - // vvvvv The fields below are introduced for `-Z bindeps`. + // TODO(bindeps): Remove `Option` after -Zbindeps get stabilized. + #[serde(skip_serializing_if = "Option::is_none")] + extern_name: Option, /// Artifact's crate type, e.g. staticlib, cdylib, bin... #[serde(skip_serializing_if = "Option::is_none")] artifact: Option<&'static str>, @@ -240,11 +244,19 @@ fn build_resolve_graph_r( Some(a) if a.is_lib() => true, _ => false, }; + // TODO(bindeps): Cargo shouldn't have `extern_name` field + // if the user is not using -Zbindeps. + // Remove this condition ` after -Zbindeps gets stabilized. + let extern_name = if dep.artifact().is_some() { + Some(extern_name(target)?) + } else { + None + }; if included { dep_kinds.push(DepKindInfo { kind: dep.kind(), target: dep.platform().cloned(), - extern_name: extern_name(target)?, + extern_name, artifact: None, compile_target: None, bin_name: None, @@ -275,7 +287,7 @@ fn build_resolve_graph_r( dep_kinds.push(DepKindInfo { kind: dep.kind(), target: dep.platform().cloned(), - extern_name: extern_name(target)?, + extern_name: extern_name(target).ok(), artifact: Some(kind.crate_type()), compile_target, bin_name: target.is_bin().then(|| target.name().to_string()), diff --git a/tests/testsuite/git.rs b/tests/testsuite/git.rs index daac773a506..35152e34822 100644 --- a/tests/testsuite/git.rs +++ b/tests/testsuite/git.rs @@ -3393,7 +3393,6 @@ fn metadata_master_consistency() { "pkg": "bar 1.0.0 (__BAR_SOURCE__#__BAR_HASH__)", "dep_kinds": [ { - "extern_name": "bar", "kind": null, "target": null } diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 897470f01e3..441630bec43 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -526,7 +526,6 @@ fn cargo_metadata_with_deps_and_version() { { "dep_kinds": [ { - "extern_name": "baz", "kind": null, "target": null } @@ -553,7 +552,6 @@ fn cargo_metadata_with_deps_and_version() { { "dep_kinds": [ { - "extern_name": "bar", "kind": null, "target": null } @@ -564,7 +562,6 @@ fn cargo_metadata_with_deps_and_version() { { "dep_kinds": [ { - "extern_name": "foobar", "kind": "dev", "target": null } @@ -1155,17 +1152,17 @@ fn workspace_metadata_with_dependencies_and_resolve() { name = "bar" version = "0.5.0" authors = [] - + [build-dependencies] artifact = { path = "../artifact/", artifact = "bin", target = "target" } bin-only-artifact = { path = "../bin-only-artifact/", artifact = "bin", target = "$ALT_TARGET" } non-artifact = { path = "../non-artifact" } - + [dependencies] artifact = { path = "../artifact/", artifact = ["cdylib", "staticlib", "bin:baz-name"], lib = true, target = "$ALT_TARGET" } bin-only-artifact = { path = "../bin-only-artifact/", artifact = "bin:a-name" } non-artifact = { path = "../non-artifact" } - + [dev-dependencies] artifact = { path = "../artifact/" } non-artifact = { path = "../non-artifact" } @@ -1654,7 +1651,6 @@ fn workspace_metadata_with_dependencies_and_resolve() { "target": null }, { - "extern_name": "artifact", "kind": "dev", "target": null }, @@ -1717,17 +1713,14 @@ fn workspace_metadata_with_dependencies_and_resolve() { { "dep_kinds": [ { - "extern_name": "non_artifact", "kind": null, "target": null }, { - "extern_name": "non_artifact", "kind": "dev", "target": null }, { - "extern_name": "non_artifact", "kind": "build", "target": null } @@ -2764,7 +2757,6 @@ fn rename_dependency() { { "dep_kinds": [ { - "extern_name": "bar", "kind": null, "target": null } @@ -2775,7 +2767,6 @@ fn rename_dependency() { { "dep_kinds": [ { - "extern_name": "baz", "kind": null, "target": null } @@ -3392,7 +3383,6 @@ fn filter_platform() { "pkg": "alt-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { - "extern_name": "alt_dep", "kind": null, "target": "$ALT_TRIPLE" } @@ -3403,7 +3393,6 @@ fn filter_platform() { "pkg": "cfg-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { - "extern_name": "cfg_dep", "kind": null, "target": "cfg(foobar)" } @@ -3414,7 +3403,6 @@ fn filter_platform() { "pkg": "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { - "extern_name": "host_dep", "kind": null, "target": "$HOST_TRIPLE" } @@ -3425,7 +3413,6 @@ fn filter_platform() { "pkg": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { - "extern_name": "normal_dep", "kind": null, "target": null } @@ -3507,7 +3494,6 @@ fn filter_platform() { "pkg": "alt-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { - "extern_name": "alt_dep", "kind": null, "target": "$ALT_TRIPLE" } @@ -3518,7 +3504,6 @@ fn filter_platform() { "pkg": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { - "extern_name": "normal_dep", "kind": null, "target": null } @@ -3584,7 +3569,6 @@ fn filter_platform() { "pkg": "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { - "extern_name": "host_dep", "kind": null, "target": "$HOST_TRIPLE" } @@ -3595,7 +3579,6 @@ fn filter_platform() { "pkg": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { - "extern_name": "normal_dep", "kind": null, "target": null } @@ -3677,7 +3660,6 @@ fn filter_platform() { "pkg": "cfg-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { - "extern_name": "cfg_dep", "kind": null, "target": "cfg(foobar)" } @@ -3688,7 +3670,6 @@ fn filter_platform() { "pkg": "host-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { - "extern_name": "host_dep", "kind": null, "target": "$HOST_TRIPLE" } @@ -3699,7 +3680,6 @@ fn filter_platform() { "pkg": "normal-dep 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dep_kinds": [ { - "extern_name": "normal_dep", "kind": null, "target": null } @@ -3797,17 +3777,14 @@ fn dep_kinds() { "pkg": "bar 0.1.0 [..]", "dep_kinds": [ { - "extern_name": "bar", "kind": null, "target": null }, { - "extern_name": "bar", "kind": "dev", "target": null }, { - "extern_name": "bar", "kind": "build", "target": null } @@ -3818,7 +3795,6 @@ fn dep_kinds() { "pkg": "winapi 0.1.0 [..]", "dep_kinds": [ { - "extern_name": "winapi", "kind": null, "target": "cfg(windows)" } @@ -3909,7 +3885,6 @@ fn dep_kinds_workspace() { "pkg": "foo 0.1.0 (path+file://[..]/foo)", "dep_kinds": [ { - "extern_name": "foo", "kind": null, "target": null } @@ -3935,7 +3910,6 @@ fn dep_kinds_workspace() { "pkg": "dep 0.5.0 (path+file://[..]/foo/dep)", "dep_kinds": [ { - "extern_name": "dep", "kind": null, "target": null } diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index eebfe413959..1eef64ea3d4 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -608,7 +608,6 @@ fn update_precise_first_run() { { "dep_kinds": [ { - "extern_name": "serde", "kind": null, "target": null }