Skip to content

Commit fb571ec

Browse files
committed
Port the no-linkable-target message
1 parent 367fd9f commit fb571ec

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,15 +1717,16 @@ fn build_deps_args(
17171717
if let Some(dep) = deps.iter().find(|dep| {
17181718
!dep.unit.mode.is_doc() && dep.unit.target.is_lib() && !dep.unit.artifact.is_true()
17191719
}) {
1720-
bcx.gctx.shell().warn(format!(
1721-
"The package `{}` \
1722-
provides no linkable target. The compiler might raise an error while compiling \
1723-
`{}`. Consider adding 'dylib' or 'rlib' to key `crate-type` in `{}`'s \
1724-
Cargo.toml. This warning might turn into a hard error in the future.",
1725-
dep.unit.target.crate_name(),
1726-
unit.target.crate_name(),
1727-
dep.unit.target.crate_name()
1728-
))?;
1720+
let dep_name = dep.unit.target.crate_name();
1721+
let name = unit.target.crate_name();
1722+
bcx.gctx.shell().print_report(&[
1723+
Level::WARNING.secondary_title(format!("the package `{dep_name}` provides no linkable target"))
1724+
.elements([
1725+
Level::NOTE.message(format!("this might cause `{name}` to fail compilation")),
1726+
Level::NOTE.message("this warning might turn into a hard error in the future"),
1727+
Level::HELP.message(format!("consider adding 'dylib' or 'rlib' to key 'crate-type' in `{dep_name}`'s Cargo.toml"))
1728+
])
1729+
], false)?;
17291730
}
17301731
}
17311732

tests/testsuite/build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5335,7 +5335,11 @@ fn no_linkable_target() {
53355335
p.cargo("build")
53365336
.with_stderr_data(str![[r#"
53375337
[LOCKING] 1 package to latest compatible version
5338-
[WARNING] The package `the_lib` provides no linkable target. The compiler might raise an error while compiling `foo`. Consider adding 'dylib' or 'rlib' to key `crate-type` in `the_lib`'s Cargo.toml. This warning might turn into a hard error in the future.
5338+
[WARNING] the package `the_lib` provides no linkable target
5339+
|
5340+
= [NOTE] this might cause `foo` to fail compilation
5341+
= [NOTE] this warning might turn into a hard error in the future
5342+
= [HELP] consider adding 'dylib' or 'rlib' to key 'crate-type' in `the_lib`'s Cargo.toml
53395343
[COMPILING] the_lib v0.1.0 ([ROOT]/foo/the_lib)
53405344
[COMPILING] foo v0.1.0 ([ROOT]/foo)
53415345
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

0 commit comments

Comments
 (0)