Skip to content

Commit 296177f

Browse files
committed
fall back to hard coded if not found
1 parent 0ccaca3 commit 296177f

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

build.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const WITH_EXPAT: &str = "ON";
3232

3333
/// Linux targets
3434
const LINUX_INCLUDE_PATHS: &[&str] = &["/usr/include/sbml", "/usr/include/libxml2"];
35-
const LINUX_LINK_PATHS: &[&str] = &["/usr/lib"];
35+
const LINUX_LINK_PATHS: &[&str] = &["/usr/lib", "/usr/lib/x86_64-linux-gnu"];
3636
const LINUX_LINK_LIBS: &[&str] = &["sbml", "xml2"];
3737

3838
/// Main build script function that orchestrates the build process
@@ -89,13 +89,25 @@ fn link_to_libraries() -> miette::Result<Vec<PathBuf>> {
8989
let link_libs = libsbml_vcpkg.found_names;
9090
(include_paths, link_paths, link_libs)
9191
} else if cfg!(target_os = "linux") {
92-
let link_paths = LINUX_LINK_PATHS.iter().map(|p| PathBuf::from(p)).collect();
93-
let include_paths = LINUX_INCLUDE_PATHS
94-
.iter()
95-
.map(|p| PathBuf::from(p))
96-
.collect();
97-
let link_libs = LINUX_LINK_LIBS.iter().map(|l| l.to_string()).collect();
98-
(include_paths, link_paths, link_libs)
92+
// Try using pkg-config first as it's more reliable
93+
match pkg_config::Config::new().probe("libsbml") {
94+
Ok(libsbml_pkg_config) => {
95+
let link_paths = libsbml_pkg_config.link_paths;
96+
let include_paths = libsbml_pkg_config.include_paths;
97+
let link_libs = libsbml_pkg_config.libs;
98+
(include_paths, link_paths, link_libs)
99+
}
100+
// Fall back to hardcoded paths if pkg-config fails
101+
Err(_) => {
102+
let link_paths = LINUX_LINK_PATHS.iter().map(|p| PathBuf::from(p)).collect();
103+
let include_paths = LINUX_INCLUDE_PATHS
104+
.iter()
105+
.map(|p| PathBuf::from(p))
106+
.collect();
107+
let link_libs = LINUX_LINK_LIBS.iter().map(|l| l.to_string()).collect();
108+
(include_paths, link_paths, link_libs)
109+
}
110+
}
99111
} else if cfg!(target_os = "macos") {
100112
let libsbml_pkg_config = pkg_config::Config::new()
101113
.probe("libsbml")

0 commit comments

Comments
 (0)