Skip to content

Commit cc891a0

Browse files
committed
Warning for no lib dependencies
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
1 parent 33edacd commit cc891a0

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/cargo/ops/resolve.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@ pub fn resolve_ws_with_opts<'cfg>(
171171
feature_opts,
172172
)?;
173173

174+
// Check if there are any dependency packages that do not have any libs.
175+
if let Some(r) = resolve.as_ref() {
176+
for id in member_ids.iter() {
177+
for (package_id, _) in r.deps(*id) {
178+
if let Ok(dep_pkg) = pkg_set.get_one(package_id) {
179+
if !dep_pkg.targets().iter().any(|t| t.is_lib()) {
180+
ws.config().shell().warn(format!(
181+
"No library were found in package `{}`",
182+
dep_pkg.name()
183+
))?
184+
}
185+
}
186+
}
187+
}
188+
}
189+
174190
Ok(WorkspaceResolve {
175191
pkg_set,
176192
workspace_resolve: resolve,

tests/testsuite/run.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,48 @@ fn run_dylib_dep() {
723723
p.cargo("run hello world").run();
724724
}
725725

726+
#[cargo_test]
727+
fn run_with_bin_dep() {
728+
let p = project()
729+
.file(
730+
"Cargo.toml",
731+
r#"
732+
[package]
733+
name = "foo"
734+
version = "0.0.1"
735+
736+
[dependencies.bar]
737+
path = "bar"
738+
"#,
739+
)
740+
.file("src/main.rs", r#"fn main() { println!("hello"); }"#)
741+
.file(
742+
"bar/Cargo.toml",
743+
r#"
744+
[package]
745+
name = "bar"
746+
version = "0.0.1"
747+
authors = []
748+
749+
[[bin]]
750+
name = "bar"
751+
"#,
752+
)
753+
.file("bar/src/main.rs", r#"fn main() { println!("bar"); }"#)
754+
.build();
755+
756+
p.cargo("run")
757+
.with_stderr(
758+
"\
759+
[WARNING] No library were found in package `bar`
760+
[COMPILING] foo v0.0.1 ([CWD])
761+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
762+
[RUNNING] `target/debug/foo[EXE]`",
763+
)
764+
.with_stdout("hello")
765+
.run();
766+
}
767+
726768
#[cargo_test]
727769
fn release_works() {
728770
let p = project()

0 commit comments

Comments
 (0)