summaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..e66329c
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,53 @@
+use std::env;
+use std::path::PathBuf;
+use std::process::Command;
+use bindgen;
+
+fn run_command(cmd: &str, args: &[&str]) -> Option<()> {
+ let status = Command::new(cmd).args(args).status().expect("Failed to execute process");
+ if status.success() {
+ Some(())
+ } else {
+ None
+ }
+}
+
+fn check_output(cmd: &str, args: &[&str]) -> Option<String> {
+ let output = Command::new(cmd).args(args).output().expect("Failed to execute process");
+ if output.status.success() {
+ Some(String::from_utf8(output.stdout).unwrap())
+ } else {
+ None
+ }
+}
+
+fn main() {
+ let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
+ run_command("git", &["-C", out_dir.to_str().unwrap(), "submodule", "update", "--init", "--recursive"])
+ .expect("Failed to clone git submodules");
+
+ let status_output =
+ check_output("git", &["-C", out_dir.to_str().unwrap(), "submodule", "status"])
+ .expect("Failed to check git submodule status");
+
+ let sub_repo =
+ out_dir.join(PathBuf::from(status_output.split_whitespace().skip(1).next().unwrap()));
+
+ run_command("make", &["-C", sub_repo.to_str().unwrap()])
+ .expect("Failed to build termio library");
+
+ let bindings = bindgen::Builder::default()
+ .header(sub_repo.join("termio.h").to_str().unwrap())
+ .blacklist_item("true_")
+ .blacklist_item("false_")
+ .blacklist_item("__bool_true_false_are_defined")
+ .generate()
+ .expect("Error generating bindings using bindgen");
+
+ bindings
+ .write_to_file(out_dir.join("bindings.rs"))
+ .expect("Error writing bindings to file");
+
+ println!("cargo:rustc-link-lib=static=termio");
+ println!("cargo:rustc-link-search={}", sub_repo.to_str().unwrap());
+}