34 lines
959 B
Rust
34 lines
959 B
Rust
use std::env;
|
|
use std::fs;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
fn main() {
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
for lib_dir in tdlib_lib_dirs() {
|
|
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", lib_dir.display());
|
|
}
|
|
}
|
|
|
|
fn tdlib_lib_dirs() -> Vec<PathBuf> {
|
|
let manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
|
|
let profile = env::var("PROFILE").unwrap_or_else(|_| "debug".to_string());
|
|
let build_dir = manifest_dir.join("target").join(profile).join("build");
|
|
|
|
let Ok(entries) = fs::read_dir(build_dir) else {
|
|
return Vec::new();
|
|
};
|
|
|
|
entries
|
|
.flatten()
|
|
.map(|entry| entry.path().join("out").join("tdlib").join("lib"))
|
|
.filter(|path| has_tdjson(path))
|
|
.collect()
|
|
}
|
|
|
|
fn has_tdjson(path: &Path) -> bool {
|
|
path.join("libtdjson.1.8.29.dylib").exists()
|
|
|| path.join("libtdjson.dylib").exists()
|
|
|| path.join("libtdjson.so").exists()
|
|
}
|