#![allow(clippy::expect_used, clippy::panic, clippy::unwrap_used, clippy::print_stdout)]
use std::path::PathBuf;
use std::time::Instant;
use lean_rs::LeanRuntime;
use lean_rs::module::LeanLibrary;
fn fixture_dylib_path() -> PathBuf {
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let workspace = manifest_dir
.parent()
.and_then(std::path::Path::parent)
.expect("crates/<name>/ lives two directories beneath the workspace root");
let dylib_extension = if cfg!(target_os = "macos") { "dylib" } else { "so" };
let lib_dir = workspace
.join("fixtures")
.join("lean")
.join(".lake")
.join("build")
.join("lib");
let new_style = lib_dir.join(format!("liblean__rs__fixture_LeanRsFixture.{dylib_extension}"));
let old_style = lib_dir.join(format!("libLeanRsFixture.{dylib_extension}"));
if old_style.is_file() && !new_style.is_file() {
old_style
} else {
new_style
}
}
fn report(name: &str, elapsed_us: u128) {
println!("name={name} elapsed_us={elapsed_us}");
}
fn main() {
let path = fixture_dylib_path();
assert!(
path.exists(),
"fixture dylib not found at {} — run `cd fixtures/lean && lake build`",
path.display(),
);
let t = Instant::now();
let runtime = LeanRuntime::init().expect("Lean runtime initialises");
report("runtime_init_cold", t.elapsed().as_micros());
let t = Instant::now();
let library = LeanLibrary::open(runtime, &path).expect("fixture dylib opens");
report("library_open_cold", t.elapsed().as_micros());
let t = Instant::now();
let _module = library
.initialize_module("lean_rs_fixture", "LeanRsFixture")
.expect("module initialiser succeeds");
report("module_initialize_cold", t.elapsed().as_micros());
}