Files

62 lines
2.0 KiB
Rust

use std::{env, path::PathBuf, process::Command};
fn main() {
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
.parent()
.unwrap()
.to_owned();
// Lake output dir containing libYourLeanLib.so
let lake_lib_dir = root.join(".lake").join("build").join("lib");
// Replace this with the actual basename:
// libmylean.so -> "mylean"
// libmy_pkg_MyLib.so -> "my_pkg_MyLib"
let lean_lib_name = "ffiexperiment";
println!("cargo::rustc-link-search=native={}", lake_lib_dir.display());
println!("cargo::rustc-link-lib=dylib={lean_lib_name}");
// Useful so `cargo run` can find the .so at runtime without LD_LIBRARY_PATH.
println!(
"cargo::rustc-link-arg=-Wl,-rpath,{}",
lake_lib_dir.display()
);
// Re-run if the Lean shared library changes.
println!(
"cargo::rerun-if-changed={}",
lake_lib_dir
.join(format!("lib{lean_lib_name}.so"))
.display()
);
// Lean runtime shared libraries.
//
// This is needed if your Rust executable directly references Lean runtime
// functions like lean_initialize_runtime_module.
let lean_prefix = Command::new("lean")
.arg("--print-prefix")
.output()
.expect("failed to run `lean --print-prefix`");
assert!(lean_prefix.status.success(), "`lean --print-prefix` failed");
let lean_prefix = String::from_utf8(lean_prefix.stdout).unwrap();
let lean_prefix = lean_prefix.trim();
let lean_lib_dir = PathBuf::from(lean_prefix).join("lib").join("lean");
println!("cargo::rustc-link-search=native={}", lean_lib_dir.display());
println!(
"cargo::rustc-link-arg=-Wl,-rpath,{}",
lean_lib_dir.display()
);
// Lean runtime/core shared libraries
println!("cargo::rustc-link-lib=dylib=Init_shared");
println!("cargo::rustc-link-lib=dylib=leanshared_2");
println!("cargo::rustc-link-lib=dylib=leanshared_1");
println!("cargo::rustc-link-lib=dylib=leanshared");
}