Skip to content

Commit 0ca6e2a

Browse files
committed
fix(rust): correct library search logic in build.rs for static linking
1 parent 5be0f06 commit 0ca6e2a

1 file changed

Lines changed: 25 additions & 14 deletions

File tree

bindings/rust/build.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,47 @@
77
//! Zig FFI layer (which delegates to Idris 2 compiled code).
88
99
fn main() {
10-
// Development build path: relative to bindings/rust/ within the repo
11-
println!("cargo:rustc-link-search=native=../../ffi/zig/zig-out/lib");
12-
13-
// System-wide installation paths
14-
println!("cargo:rustc-link-search=native=/usr/local/lib");
15-
println!("cargo:rustc-link-search=native=/usr/lib");
10+
// 1. Determine library search paths
11+
let mut search_paths = vec![
12+
"../../ffi/zig/zig-out/lib".to_string(),
13+
"/usr/local/lib".to_string(),
14+
"/usr/lib".to_string(),
15+
];
1616

1717
// Allow override via PROVEN_LIB_DIR environment variable
18-
if let Ok(lib_dir) = std::env::var("PROVEN_LIB_DIR") {
19-
println!("cargo:rustc-link-search=native={}", lib_dir);
18+
if let Ok(env_path) = std::env::var("PROVEN_LIB_DIR") {
19+
search_paths.insert(0, env_path);
20+
}
21+
22+
for path in &search_paths {
23+
println!("cargo:rustc-link-search=native={}", path);
2024
}
2125

22-
// Link against libproven (the compiled Zig/Idris2 library).
26+
// 2. Link against libproven (the compiled Zig/Idris2 library).
2327
// Prefer static linking if libproven.a is found (required for ClusterFuzzLite).
24-
let is_static = std::path::Path::new(&lib_dir_path).join("libproven.a").exists();
28+
let mut is_static = false;
29+
for path in &search_paths {
30+
if std::path::Path::new(path).join("libproven.a").exists() {
31+
is_static = true;
32+
break;
33+
}
34+
}
35+
2536
if is_static {
2637
println!("cargo:rustc-link-lib=static=proven");
2738
} else {
2839
println!("cargo:rustc-link-lib=dylib=proven");
2940
}
3041

31-
// Add RPATH so binaries can find libproven.so relative to themselves (e.g. in ./lib/ or ./)
32-
// This is required for ClusterFuzzLite and standalone distributions.
42+
// 3. Add RPATH so binaries can find libproven.so relative to themselves (e.g. in ./lib/ or ./)
43+
// This is required for standalone distributions using dynamic linking.
3344
if std::env::var("CARGO_CFG_TARGET_OS").ok() == Some("linux".to_string()) {
3445
println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN/lib");
3546
println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN");
3647
}
3748

38-
// Re-run build script if the library changes
49+
// Re-run build script if relevant files change
3950
println!("cargo:rerun-if-env-changed=PROVEN_LIB_DIR");
4051
println!("cargo:rerun-if-changed=../../ffi/zig/zig-out/lib/libproven.so");
41-
println!("cargo:rerun-if-changed=../../ffi/zig/zig-out/lib/libproven.dylib");
52+
println!("cargo:rerun-if-changed=../../ffi/zig/zig-out/lib/libproven.a");
4253
}

0 commit comments

Comments
 (0)