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

WIP Add bin/cdylib/staticlib suffix for artifact deps #14658

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
10 changes: 9 additions & 1 deletion src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use serde::Serialize;
use tracing::debug;

use crate::core::compiler::{CompileKind, RustcTargetData};
use crate::core::dependency::DepKind;
use crate::core::dependency::{ArtifactKind, DepKind};
use crate::core::resolver::features::ForceAllTargets;
use crate::core::resolver::{HasDevUnits, Resolve};
use crate::core::{
Expand Down Expand Up @@ -167,6 +167,14 @@ impl Package {
pub fn proc_macro(&self) -> bool {
self.targets().iter().any(|target| target.proc_macro())
}
// TODO fix this. For now, just wanted it to return a plausible value. Must figure out why .kinds() returns a Vec.
/// Gets crate-type in { .., artifact = <crate-type> } of this package
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This returns ArtifactKind of a package's dependencies, not the ArtifactKind of the package itself. This is why (bin/cdylib/staticlib) suffixes currently print on the wrong line.

- expected
+ actual
- foo v0.0.0 ([ROOT]/foo)
-└── bindep v0.0.0 (bin) ([ROOT]/foo/bindep)
+ foo v0.0.0 (bin) ([ROOT]/foo)
+ └── bindep v0.0.0 ([ROOT]/foo/bindep)

pub fn artifact_kind(&self) -> Option<&ArtifactKind> {
let found = self.dependencies().iter().find_map(|dep| dep.artifact());

// TODO for now just returns the first ArtifactKind in the Vec<ArtifactKind>
found?.kinds().iter().next()
}
/// Gets the package's minimum Rust version.
pub fn rust_version(&self) -> Option<&RustVersion> {
self.manifest().rust_version()
Expand Down
13 changes: 11 additions & 2 deletions src/cargo/ops/tree/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,21 @@ impl<'a> fmt::Display for Display<'a> {
} else {
""
};
// TODO this is probably NOT the right way to get the ArtifactKind
//
let artifact_suffix =
if let Some(artifact_kind) = package.artifact_kind() {
format!(" ({})", artifact_kind.crate_type())
} else {
"".to_string()
};
write!(
fmt,
"{} v{}{}",
"{} v{}{}{}",
package.name(),
package.version(),
proc_macro_suffix
proc_macro_suffix,
artifact_suffix,
)?;

let source_id = package.package_id().source_id();
Expand Down
14 changes: 7 additions & 7 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ fn dependencies_of_dependencies_work_in_artifacts() {
.with_stdout_data(str![[r#"
foo v0.0.0 ([ROOT]/foo)
[build-dependencies]
└── bar v0.5.0 ([ROOT]/foo/bar)
└── bar v0.5.0 (bin) ([ROOT]/foo/bar)
└── baz v1.0.0

"#]])
Expand Down Expand Up @@ -1571,12 +1571,12 @@ fn artifact_dep_target_specified() {
// 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_stdout_data("")
.with_stderr_data(r#"...
[..]did not find features for (PackageId { name: "bindep", version: "0.0.0", source: "[..]" }, NormalOrDev) within activated_features:[..]
...
"#)
.with_status(101)
.with_stdout_data(str![[r#"
foo v0.0.0 ([ROOT]/foo)
└── bindep v0.0.0 (bin) ([ROOT]/foo/bindep)

"#]])
.with_status(0)
.run();
}

Expand Down
Loading