Skip to content
Open
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;

/// Used to exclude autogenerated files in the output dir from `cargo:rerun-if-changed` directives.
#[derive(Debug)]
Expand Down Expand Up @@ -163,6 +164,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() {
if cfg!(all(
any(
Expand All @@ -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");
}
Expand Down