Skip to content

Commit

Permalink
Reapply "Refactor build.rs"
Browse files Browse the repository at this point in the history
This reverts commit 7d56656.
  • Loading branch information
raviqqe committed Sep 24, 2024
1 parent 7d56656 commit 2280070
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,9 @@ 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(' ') {
if let Some(name) = trim_library_name(name) {
println!("cargo:rustc-link-lib={}", name);
}
println!("cargo:rustc-link-lib={}", parse_library_name(name)?);
}

for flag in llvm_config("--system-libs")?.trim().split(' ') {
Expand All @@ -60,14 +55,7 @@ fn run() -> Result<(), Box<dyn Error>> {
);
println!(
"cargo:rustc-link-lib={}",
path.file_name()
.unwrap()
.to_str()
.unwrap()
.split_once('.')
.unwrap()
.0
.trim_start_matches("lib")
parse_library_name(path.file_name().unwrap().to_str().unwrap())?
);
} else {
println!("cargo:rustc-link-lib={}", flag);
Expand Down Expand Up @@ -144,10 +132,8 @@ fn llvm_config(argument: &str) -> Result<String, Box<dyn Error>> {
.to_string())
}

fn trim_library_name(name: &str) -> Option<&str> {
if let Some(name) = name.strip_prefix("lib") {
name.strip_suffix(".a")
} else {
None
}
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))
}

0 comments on commit 2280070

Please sign in to comment.