From 2f845f1c8f350020a91856a979bbd3b2a23aa7ca Mon Sep 17 00:00:00 2001 From: Mihai Dinculescu Date: Sun, 9 Oct 2022 22:00:59 +0100 Subject: [PATCH] Fix the loading of the lib --- simconnect-sdk/build.rs | 18 ++++++++++++++---- .../ffi/lib/SimConnect.dll | Bin 2 files changed, 14 insertions(+), 4 deletions(-) rename SimConnect.dll => simconnect-sdk/ffi/lib/SimConnect.dll (100%) diff --git a/simconnect-sdk/build.rs b/simconnect-sdk/build.rs index 5b601c3..729891c 100644 --- a/simconnect-sdk/build.rs +++ b/simconnect-sdk/build.rs @@ -2,10 +2,13 @@ use std::env; use std::path::PathBuf; fn main() { - println!("cargo:rustc-link-search=simconnect-sdk/ffi/lib"); - println!("cargo:rustc-link-lib=static=SimConnect"); println!("cargo:rerun-if-changed=simconnect-sdk/ffi/include/SimConnect.h"); println!("cargo:rerun-if-changed=simconnect-sdk/ffi/lib/SimConnect.lib"); + println!("cargo:rerun-if-changed=simconnect-sdk/ffi/lib/SimConnect.dll"); + + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + println!("cargo:rustc-link-search={}", out_path.to_string_lossy()); + println!("cargo:rustc-link-lib=static=SimConnect"); let bindings = bindgen::Builder::default() .header("ffi/include/SimConnect.h") @@ -34,8 +37,15 @@ fn main() { .generate() .expect("Unable to generate bindings"); - let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); bindings .write_to_file(out_path.join("bindings.rs")) - .expect("Failed to write the bindings!"); + .expect("Failed to write the bindings"); + + let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("Failed to find `CARGO_MANIFEST_DIR`"); + let lib_path = PathBuf::from(manifest_dir).join("ffi/lib"); + + for file in &["SimConnect.lib", "SimConnect.dll"] { + std::fs::copy(lib_path.join(file), out_path.join(file)) + .unwrap_or_else(|_| panic!("Failed to copy `{file}`")); + } } diff --git a/SimConnect.dll b/simconnect-sdk/ffi/lib/SimConnect.dll similarity index 100% rename from SimConnect.dll rename to simconnect-sdk/ffi/lib/SimConnect.dll