diff --git a/build.rs b/build.rs index a88f3f2..698441d 100644 --- a/build.rs +++ b/build.rs @@ -37,9 +37,14 @@ fn run() -> Result<(), Box> { println!("cargo:rerun-if-changed=wrapper.h"); println!("cargo:rerun-if-changed=cc"); println!("cargo:rustc-link-search={}", llvm_config("--libdir")?); + println!("cargo:rustc-link-lib=static=LLVMCore"); + println!("cargo:rustc-link-lib=static=LLVMSupport"); + println!("cargo:rustc-link-lib=static=LLVMTableGen"); for name in llvm_config("--libnames")?.trim().split(' ') { - println!("cargo:rustc-link-lib={}", parse_library_name(name)?); + if let Some(name) = trim_library_name(name) { + println!("cargo:rustc-link-lib={}", name); + } } for flag in llvm_config("--system-libs")?.trim().split(' ') { @@ -55,7 +60,14 @@ fn run() -> Result<(), Box> { ); println!( "cargo:rustc-link-lib={}", - parse_library_name(path.file_name().unwrap().to_str().unwrap())? + path.file_name() + .unwrap() + .to_str() + .unwrap() + .split_once('.') + .unwrap() + .0 + .trim_start_matches("lib") ); } else { println!("cargo:rustc-link-lib={}", flag); @@ -66,6 +78,8 @@ fn run() -> Result<(), Box> { println!("cargo:rustc-link-lib={}", name); } + std::env::set_var("CXXFLAGS", llvm_config("--cxxflags")?); + std::env::set_var("CFLAGS", llvm_config("--cflags")?); println!("cargo:rustc-link-search={}", &env::var("OUT_DIR")?); cc::Build::new() @@ -130,8 +144,10 @@ fn llvm_config(argument: &str) -> Result> { .to_string()) } -fn parse_library_name(name: &str) -> Result<&str, String> { - name.strip_prefix("lib") - .and_then(|name| name.split('.').next()) - .ok_or_else(|| format!("failed to parse library name: {}", name)) +fn trim_library_name(name: &str) -> Option<&str> { + if let Some(name) = name.strip_prefix("lib") { + name.strip_suffix(".a") + } else { + None + } }