From e48632e30aed87b96bc0a131d6c5c9112e6d7fea Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Mon, 21 Aug 2023 19:40:54 -0300 Subject: [PATCH] Don't ignore transitive imports when probing a static library Suppressing cargo_metadata silences libraries with full paths, in turn causing linking against static libraries to fail utterly on Windows. --- src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4b87acd..924cefc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1008,10 +1008,19 @@ impl Library { }; let is_static_available = |name: &String| -> bool { - let libname = format!("lib{}.a", name); + let libnames = { + let mut names = vec![format!("lib{}.a", name)]; + + if cfg!(target_os = "windows") { + names.push(format!("{}.lib", name)); + } + + names + }; l.link_paths.iter().any(|dir| { - !system_roots.iter().any(|sys| dir.starts_with(sys)) && dir.join(&libname).exists() + let library_exists = libnames.iter().any(|libname| dir.join(&libname).exists()); + library_exists && !system_roots.iter().any(|sys| dir.starts_with(sys)) }) };