mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-05-06 10:19:33 +00:00
48 lines
1.7 KiB
Rust
48 lines
1.7 KiB
Rust
use std::path::PathBuf;
|
|
use std::process::Command;
|
|
|
|
fn main() {
|
|
let manifest = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
|
|
let nim_src = manifest.join("../nim_timer.nim");
|
|
let nim_src = nim_src.canonicalize().unwrap_or(manifest.join("../nim_timer.nim"));
|
|
|
|
// Walk up to find the nim-ffi repo root (directory containing nim_src's library)
|
|
// The repo root is where nim c should be run from (contains config.nims).
|
|
// We assume nim_src lives somewhere under repo_root.
|
|
// Derive repo_root as the ancestor that contains the .nimble file or config.nims.
|
|
let mut repo_root = nim_src.clone();
|
|
loop {
|
|
repo_root = match repo_root.parent() {
|
|
Some(p) => p.to_path_buf(),
|
|
None => break,
|
|
};
|
|
if repo_root.join("config.nims").exists() || repo_root.join("ffi.nimble").exists() {
|
|
break;
|
|
}
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
|
let lib_ext = "dylib";
|
|
#[cfg(target_os = "linux")]
|
|
let lib_ext = "so";
|
|
|
|
let out_lib = repo_root.join(format!("libnimtimer.{lib_ext}"));
|
|
|
|
let mut cmd = Command::new("nim");
|
|
cmd.arg("c")
|
|
.arg("--mm:orc")
|
|
.arg("-d:chronicles_log_level=WARN")
|
|
.arg("--app:lib")
|
|
.arg("--noMain")
|
|
.arg(format!("--nimMainPrefix:libnimtimer"))
|
|
.arg(format!("-o:{}", out_lib.display()));
|
|
cmd.arg(&nim_src).current_dir(&repo_root);
|
|
|
|
let status = cmd.status().expect("failed to run nim compiler");
|
|
assert!(status.success(), "Nim compilation failed");
|
|
|
|
println!("cargo:rustc-link-search={}", repo_root.display());
|
|
println!("cargo:rustc-link-lib=nimtimer");
|
|
println!("cargo:rerun-if-changed={}", nim_src.display());
|
|
}
|