Skip to content

Commit 91d9fe5

Browse files
committed
- fix linux linking issues, and add stable sbml packages to the build
1 parent ac7e58b commit 91d9fe5

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

build.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fn build_and_link_libsbml(dep_build: &str) -> miette::Result<String> {
9696
.static_crt(true)
9797
.profile("Release")
9898
.define("WITH_STATIC_RUNTIME", "ON")
99+
.define("WITH_STABLE_PACKAGES", "ON") // add support for all stable packages
99100
.define("WITH_LIBXML", WITH_LIBXML)
100101
.define("WITH_EXPAT", WITH_EXPAT)
101102
//
@@ -125,6 +126,7 @@ fn build_and_link_libsbml(dep_build: &str) -> miette::Result<String> {
125126
cmake::Config::new(LIBSBML_PATH)
126127
.profile("Release")
127128
.define("WITH_STATIC_RUNTIME", "OFF")
129+
.define("WITH_STABLE_PACKAGES", "ON") // add support for all stable packages
128130
.define("WITH_LIBXML", WITH_LIBXML)
129131
.define("WITH_EXPAT", WITH_EXPAT)
130132
.build()
@@ -138,8 +140,21 @@ fn build_and_link_libsbml(dep_build: &str) -> miette::Result<String> {
138140
// static library is named "libsbml-static" and not "libsbml".
139141
// which seems to confuse the rustc linker.
140142
println!("cargo:rustc-link-lib=libsbml-static");
143+
} else if cfg!(target_os = "linux") {
144+
// On Linux, we need to link against the static libraries
145+
// if you thought windows had it rough, on linux
146+
// it should just have been rustc-link-lib=sbml,
147+
// but that didnt work, so lets bypass what cargo is doing
148+
// and sneak the static library and dependencies into the link line
149+
println!("cargo:rustc-link-arg=-Wl,{}/lib/libsbml-static.a", dst.display());
150+
println!("cargo:rustc-link-arg=-Wl,-lz");
151+
println!("cargo:rustc-link-arg=-Wl,-lexpat");
152+
println!("cargo:rustc-link-arg=-Wl,-lbz2");
153+
println!("cargo:rustc-link-arg=-Wl,-lstdc++");
154+
println!("cargo:rustc-link-arg=-Wl,-lc");
155+
println!("cargo:rustc-link-arg=-Wl,-lm");
141156
} else {
142-
// On MacOS and Linux, we can just link against the dynamic library
157+
// On MacOS, we can just link against the dynamic library
143158
println!("cargo:rustc-link-lib=dylib={}", LIBSBML_NAME);
144159
}
145160

@@ -198,7 +213,7 @@ fn print_dir_contents(path: &str) -> miette::Result<()> {
198213
if path.is_file() {
199214
if let Some(ext) = path.extension() {
200215
let ext_str = ext.to_string_lossy().to_lowercase();
201-
if ["a", "dylib", "lib"].contains(&ext_str.as_str()) {
216+
if ["a", "dylib", "lib", "so"].contains(&ext_str.as_str()) {
202217
println!("cargo:info={}", path.display());
203218
}
204219
}

0 commit comments

Comments
 (0)