diff --git a/build.rs b/build.rs index ac8f558..60d9cd0 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,6 @@ use std::env; use std::path::{Path, PathBuf}; +use std::process::Command; /// Used to exclude autogenerated files in the output dir from `cargo:rerun-if-changed` directives. #[derive(Debug)] @@ -163,6 +164,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() { if cfg!(all( any( @@ -178,6 +201,11 @@ fn main() { ); } + #[cfg(feature = "build")] + if !Path::new("HiGHS/highs").exists() { + update_submodules(env::var("CARGO_MANIFEST_DIR").unwrap()); + } + if !discover() && !build() { panic!("Could neither discover nor build HiGHS"); }