Packages

An Erlang wrapper for h3 hextrees/hexsets.

Current section

Files

Jump to
hextree native build.rs
Raw

native/build.rs

use std::{
env,
fs::File,
io::Write,
path::{Path, PathBuf},
};
fn main() {
// Directory containing Cargo.toml
let repo = env::var("CARGO_MANIFEST_DIR").unwrap();
// Host triple (arch of machine doing to build, not necessarily the arch we're building for)
let host_triple = env::var("HOST").unwrap();
// Target triple (arch we're building for, not necessarily the arch we're building on)
let target_triple = env::var("TARGET").unwrap();
// debug or release
let profile = env::var("PROFILE").unwrap();
// We use target OS to determine if extension is `.so`, `.dll`, or `.dylib`
let file_name = match env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() {
"windows" => "libhextree_nif.dll",
"macos" | "ios" => "libhextree_nif.dylib",
_ => "libhextree_nif.so",
};
// Location of libhextree
let mut so_path: PathBuf = [&repo, "_build", "hextree"].iter().collect();
if host_triple != target_triple {
so_path.push(&target_triple);
}
so_path.push(&profile);
so_path.push(&file_name);
// Create file in `repo` and write the path to the directory of
// where to find libhextree
let so_path_file_path = Path::new(&repo).join("so-path");
println!("cargo:rerun-if-changed={}", so_path_file_path.display());
let mut so_path_file = File::create(so_path_file_path).unwrap();
write!(so_path_file, "{}", so_path.to_str().unwrap()).unwrap();
}