Skip to content

Commit d520413

Browse files
committed
build.rs: add paths from ld —verbose on Linux
1 parent 9f39907 commit d520413

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

libhdf5-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ libc = "0.2"
1717
bindgen = "0.47"
1818
lazy_static = "1.2"
1919
libloading = "0.5"
20+
regex = "1.1"
2021

2122
[target.'cfg(all(unix, not(target_os = "macos")))'.build-dependencies]
2223
pkg-config = "0.3"

libhdf5-sys/build.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::sync::Mutex;
1212
use bindgen::callbacks::IntKind;
1313
use bindgen::callbacks::ParseCallbacks;
1414
use lazy_static::lazy_static;
15+
use regex::Regex;
1516

1617
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
1718
pub struct Version {
@@ -109,8 +110,23 @@ fn get_runtime_version_single<P: AsRef<Path>>(path: P) -> io::Result<Version> {
109110
}
110111

111112
fn validate_runtime_version(config: &Config) {
113+
println!("Looking for HDF5 library binary...");
112114
let libfiles = &["libhdf5.dylib", "libhdf5.so", "hdf5.dll"];
113-
for link_path in &config.link_paths {
115+
let mut link_paths = config.link_paths.clone();
116+
if cfg!(all(unix, not(target_os = "macos"))) {
117+
if let Some(ldv) = run_command("ld", &["--verbose"]) {
118+
let re = Regex::new(r#"SEARCH_DIR\("=(?P<path>[^"]+)"\)"#).unwrap();
119+
println!("Adding extra link paths (ld)...");
120+
for caps in re.captures_iter(&ldv) {
121+
let path = &caps["path"];
122+
println!(" {}", path);
123+
link_paths.push(path.into());
124+
}
125+
} else {
126+
println!("Unable to add extra link paths (ld).");
127+
}
128+
}
129+
for link_path in &link_paths {
114130
if let Ok(paths) = fs::read_dir(link_path) {
115131
for path in paths {
116132
if let Ok(path) = path {
@@ -141,7 +157,7 @@ fn validate_runtime_version(config: &Config) {
141157
}
142158
}
143159
}
144-
panic!("Unable to infer HDF5 library runtime version.");
160+
panic!("Unable to infer HDF5 library runtime version (can't find the binary).");
145161
}
146162

147163
#[derive(Clone, Copy, Debug, Default)]

0 commit comments

Comments
 (0)