Skip to content

Commit

Permalink
Revert "Refactor build.rs"
Browse files Browse the repository at this point in the history
This reverts commit 69421cc.
  • Loading branch information
raviqqe committed Sep 24, 2024
1 parent 69421cc commit 7d56656
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ fn run() -> Result<(), Box<dyn Error>> {
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(' ') {
Expand All @@ -55,7 +60,14 @@ fn run() -> Result<(), Box<dyn Error>> {
);
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);
Expand All @@ -66,6 +78,8 @@ fn run() -> Result<(), Box<dyn Error>> {
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()
Expand Down Expand Up @@ -130,8 +144,10 @@ fn llvm_config(argument: &str) -> Result<String, Box<dyn Error>> {
.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
}
}

0 comments on commit 7d56656

Please sign in to comment.