diff --git a/build.rs b/build.rs index e7fcb1a..952c776 100644 --- a/build.rs +++ b/build.rs @@ -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") @@ -178,6 +179,28 @@ fn discover() -> bool { false } +fn update_submodules>(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"); @@ -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'."