Skip to content

Feat(): Support static compliation on Linux MUSL #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ keywords = ["linear-programming", "optimization", "math", "solver"]
[dependencies]

[build-dependencies]
bindgen = "0.57"
bindgen = "0.59.1"
cmake = "0.1"
33 changes: 24 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@ use std::path::PathBuf;
use cmake::Config;

fn main() {
let dst = Config::new("HiGHS")
.define("FAST_BUILD", "ON")
// Targets
let target = env::var("TARGET").unwrap();
let apple = target.contains("apple");
let windows = target.contains("windows");
let linux = target.contains("linux");
let musl = target.contains("musl");

let mut dst = Config::new("HiGHS");
dst.define("FAST_BUILD", "ON")
.define("SHARED", "OFF")
.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreadedDLL")
.build();
.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreadedDLL");

if musl {
dst.define(
"CMAKE_CXX_STANDARD_LIBRARIES",
"-static-libgcc -static-libstdc++",
);
};

let dst = dst.build();
let include_path = dst.join("include");
let src_path = PathBuf::from("HiGHS").join("src");

Expand Down Expand Up @@ -45,18 +59,19 @@ fn main() {

println!("cargo:rustc-link-search=native={}/lib", dst.display());
println!("cargo:rustc-link-lib=static=highs");
let target = env::var("TARGET").unwrap();
let apple = target.contains("apple");
let windows = target.contains("windows");
let linux = target.contains("linux");

if apple {
println!("cargo:rustc-link-lib=dylib=c++");
} else if musl {
println!("cargo:rustc-link-lib=static=stdc++");
} else if linux {
println!("cargo:rustc-link-lib=dylib=stdc++");
}

if apple {
println!("cargo:rustc-link-lib=dylib=omp");
} else if !windows { // No openmp 3 on windows
} else if !windows {
// No openmp 3 on windows
println!("cargo:rustc-link-lib=dylib=gomp");
}
println!("cargo:rerun-if-changed=HiGHS/src/interfaces/highs_c_api.h");
Expand Down
9 changes: 5 additions & 4 deletions tests/test_highs_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ fn highs_functions() {
}
}


#[test]
fn highs_functions_multithread() {
let threads: Vec<_> = (0..1000).map(|_| std::thread::spawn(highs_functions)).collect();
for t in threads{
let threads: Vec<_> = (0..1000)
.map(|_| std::thread::spawn(highs_functions))
.collect();
for t in threads {
t.join().expect("Thread should not panic");
}
}
}