Use proper paths to handle dylib search path

I don't trust the paths with '/' to hold up on Windows.
This commit is contained in:
Hanno Braun 2022-10-17 15:22:41 +02:00
parent 257d6b0a74
commit 09481147b1

View File

@ -1,17 +1,18 @@
use std::env;
use std::{env, path::PathBuf};
fn main() -> anyhow::Result<()> {
let manifest_dir = env::var("CARGO_MANIFEST_DIR")?;
let libs_dir_relative = "lib3mf/libs";
let libs_dir = format!("{manifest_dir}/{libs_dir_relative}");
let mut libs_dir = PathBuf::from(manifest_dir);
libs_dir.push("lib3mf");
libs_dir.push("libs");
// This is necessary to link against the dynamic library.
println!("cargo:rustc-link-search=native={libs_dir}");
println!("cargo:rustc-link-search=native={}", libs_dir.display());
println!("cargo:rustc-link-lib=dylib=3mf");
// And this is necessary, so the linked library is found at runtime.
println!("cargo:rustc-link-arg=-Wl,-rpath,{libs_dir}");
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", libs_dir.display());
Ok(())
}