use std::env;
use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
if cfg!(target_os = "macos") {
configure_macos_lldb();
} else if cfg!(target_os = "linux") {
configure_linux_lldb();
} else if cfg!(target_os = "windows") {
configure_windows_lldb();
}
}
fn configure_macos_lldb() {
let lldb_lib_path = "/opt/homebrew/Cellar/llvm/20.1.7/lib";
println!("cargo:rustc-link-search=native={}", lldb_lib_path);
println!("cargo:rustc-link-lib=dylib=lldb");
println!("cargo:rustc-env=LLDB_LIB_PATH={}", lldb_lib_path);
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", lldb_lib_path);
println!("cargo:rustc-link-lib=framework=Foundation");
println!("cargo:rustc-link-lib=framework=CoreFoundation");
println!("cargo:rustc-env=LLDB_INCLUDE_PATH=/opt/homebrew/Cellar/llvm/20.1.7/include");
}
fn configure_linux_lldb() {
let linux_paths = [
"/usr/lib/x86_64-linux-gnu",
"/usr/lib64",
"/usr/local/lib",
"/opt/llvm/lib",
];
for path in &linux_paths {
let lib_path = PathBuf::from(path);
if lib_path.join("liblldb.so").exists() {
println!("cargo:rustc-link-search=native={}", path);
println!("cargo:rustc-link-lib=dylib=lldb");
break;
}
}
println!("cargo:rustc-link-lib=dylib=lldb");
}
fn configure_windows_lldb() {
if let Ok(llvm_sys_path) = env::var("LLVM_SYS_190_PREFIX") {
let lib_path = PathBuf::from(llvm_sys_path).join("lib");
println!("cargo:rustc-link-search=native={}", lib_path.display());
}
let windows_paths = [
"C:\\Program Files\\LLVM\\lib",
"C:\\Program Files (x86)\\LLVM\\lib",
"C:\\llvm\\lib",
];
for path in &windows_paths {
let lib_path = PathBuf::from(path);
if lib_path.join("lldb.lib").exists() {
println!("cargo:rustc-link-search=native={}", path);
break;
}
}
println!("cargo:rustc-link-lib=static=lldb");
}