From ffe015e9db9a95ce9e3f9616466ecedaa457ba7a Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Fri, 20 Sep 2019 00:14:40 -0400 Subject: [PATCH] Add support for Windows lib lookup directory --- aeron_driver-sys/build.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/aeron_driver-sys/build.rs b/aeron_driver-sys/build.rs index 50858a6..184d0a4 100644 --- a/aeron_driver-sys/build.rs +++ b/aeron_driver-sys/build.rs @@ -46,12 +46,17 @@ pub fn main() { link_type.link_lib(), link_type.target_name() ); - let lib_dir = Config::new(&aeron_path) + let cmake_output = Config::new(&aeron_path) .build_target(link_type.target_name()) .build(); + + // Trying to figure out the final path is a bit weird; + // For Linux/OSX, it's just build/lib + // For Windows, it's build/lib/{profile} + let lib_dir = lib_output_dir(&cmake_output); println!( "cargo:rustc-link-search=native={}", - lib_dir.join("build/lib").display() + lib_dir.display() ); println!("cargo:include={}", header_path.display()); @@ -65,3 +70,15 @@ pub fn main() { .write_to_file(out_path.join("bindings.rs")) .expect("Couldn't write bindings!"); } + +fn lib_output_dir(cmake_dir: &PathBuf) -> PathBuf { + if cfg!(target_os = "windows") { + if cmake_dir.join("build/lib/Debug").exists() { + cmake_dir.join("build/lib/Debug") + } else { + cmake_dir.join("build/lib/Release") + } + } else { + cmake_dir.join("build/lib") + } +} \ No newline at end of file