Skip to content
Merged
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
28 changes: 28 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;
use std::path::{Path, PathBuf};
use std::process::Command;

fn target_has_feature(feature: &str) -> bool {
env::var("CARGO_CFG_TARGET_FEATURE")
Expand Down Expand Up @@ -178,6 +179,28 @@ fn discover() -> bool {
false
}

fn update_submodules<P: AsRef<Path>>(work_dir: P) {
let program = "git";
let args = ["submodule", "update", "--init"];
println!(
"Running command: \"{} {}\" in dir: {}",
program,
args.join(" "),
work_dir.as_ref().display()
);
let ret = Command::new(program)
.current_dir(work_dir.as_ref())
.args(args)
.status();

match ret.map(|status| (status.success(), status.code())) {
Ok((true, _)) => (),
Ok((false, Some(c))) => panic!("Command failed with error code {}", c),
Ok((false, None)) => panic!("Command got killed"),
Err(e) => panic!("Command failed with error: {}", e),
}
}

fn main() {
println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_FEATURE");

Expand All @@ -198,6 +221,11 @@ fn main() {
);
}

#[cfg(feature = "build")]
if !Path::new("HiGHS/highs").exists() {
update_submodules(env::var("CARGO_MANIFEST_DIR").unwrap());
}

if cfg!(feature = "discover") && crt_static {
println!(
"cargo::warning=You have enabled Rust's 'crt-static' target feature, but also enabled the 'discover' feature. Discovering a system-installed HiGHS bypasses the bundled build, so highs-sys cannot ensure that HiGHS uses the same MSVC runtime. Please disable 'discover' when using '-C target-feature=+crt-static'."
Expand Down