2024-07-23 14:15:06 +02:00
|
|
|
extern crate dotenv;
|
|
|
|
|
|
|
|
use std::env;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Load the .env.build file for build-time environment variables
|
|
|
|
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
2024-07-27 00:31:01 +02:00
|
|
|
let manifest_path = PathBuf::from(manifest_dir);
|
|
|
|
dotenv::from_path(manifest_path.join(".env.build")).ok();
|
2024-07-27 16:04:05 +02:00
|
|
|
|
2024-07-27 00:31:01 +02:00
|
|
|
println!("cargo::rerun-if-env-changed=SESAM_FSV_LIB_PATH");
|
|
|
|
println!("cargo::rerun-if-env-changed=SESAM_FSV_SSVLIB");
|
|
|
|
println!("cargo::rerun-if-changed=.env.build");
|
|
|
|
println!("cargo::rerun-if-changed=build.rs");
|
2024-07-23 14:15:06 +02:00
|
|
|
|
|
|
|
// Add local lib directory to the linker search path (for def files and static libs)
|
2024-07-27 00:31:01 +02:00
|
|
|
let static_lib_path = manifest_path.join("lib");
|
2024-07-23 14:15:06 +02:00
|
|
|
println!("cargo::rustc-link-search=native={}", static_lib_path.display());
|
|
|
|
|
|
|
|
// Add the SESAM_FSV_LIB_PATH to the linker search path
|
|
|
|
let fsv_lib_path = PathBuf::from(env::var("SESAM_FSV_LIB_PATH").unwrap());
|
|
|
|
println!("cargo::rustc-link-search=native={}", fsv_lib_path.display());
|
|
|
|
|
|
|
|
// Add the SESAM_FSV_LIB_PATH to the PATH environment variable
|
|
|
|
if cfg!(target_os = "windows") {
|
|
|
|
let path = env::var("PATH").unwrap_or(String::new());
|
|
|
|
println!("cargo:rustc-env=PATH={};{}", fsv_lib_path.display(), path);
|
|
|
|
} else if cfg!(target_os = "linux") {
|
|
|
|
println!("cargo:rustc-env=LD_LIBRARY_PATH={}", fsv_lib_path.display());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Link the SESAM_FSV_SSVLIB dynamic library
|
|
|
|
println!("cargo::rustc-link-lib=dylib={}", env::var("SESAM_FSV_SSVLIB").unwrap());
|
2024-07-27 16:04:05 +02:00
|
|
|
// TODO : try `raw-dylib` instead of `dylib` on Windows to avoid the need of the `lib` headers compiled from the `def`
|
2024-07-23 14:15:06 +02:00
|
|
|
}
|