summaryrefslogtreecommitdiff
path: root/hidapi-sys/build.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2017-03-26 17:07:48 -0700
committerDaniel Mueller <deso@posteo.net>2017-03-26 17:07:48 -0700
commit654b2e5fa1566f0479b09adf2d73f783196ad032 (patch)
treee7805428a5db957d94e414deaa66b6555a0f6003 /hidapi-sys/build.rs
parentcb39828ecd7ea5d2eac3076ad3dd1b6ef05e10d3 (diff)
downloadnitrocli-654b2e5fa1566f0479b09adf2d73f783196ad032.tar.gz
nitrocli-654b2e5fa1566f0479b09adf2d73f783196ad032.tar.bz2
Import subrepo hidapi-sys/:hidapi-sys at ec441b2751dcbbcd053800b6901672c999651584
Diffstat (limited to 'hidapi-sys/build.rs')
-rw-r--r--hidapi-sys/build.rs81
1 files changed, 81 insertions, 0 deletions
diff --git a/hidapi-sys/build.rs b/hidapi-sys/build.rs
new file mode 100644
index 0000000..6ad9197
--- /dev/null
+++ b/hidapi-sys/build.rs
@@ -0,0 +1,81 @@
+extern crate gcc;
+extern crate pkg_config;
+
+use std::env;
+use std::io;
+use std::path::PathBuf;
+use std::process::Command;
+
+fn main() {
+ if env::var("CARGO_FEATURE_BUILD").is_err() {
+ return;
+ }
+
+ fetch().unwrap();
+ build().unwrap();
+
+ println!("cargo:rustc-link-search=native={}", output().to_string_lossy());
+}
+
+fn output() -> PathBuf {
+ PathBuf::from(env::var("OUT_DIR").unwrap())
+}
+
+fn source() -> PathBuf {
+ output().join("hidapi")
+}
+
+fn fetch() -> io::Result<()> {
+ Command::new("git")
+ .current_dir(&output())
+ .arg("clone")
+ .arg("https://github.com/signal11/hidapi.git")
+ .arg("hidapi")
+ .status()?;
+
+ Ok(())
+}
+
+#[cfg(target_os = "linux")]
+fn build() -> io::Result<()> {
+ let mut config = gcc::Config::new();
+
+ config.file(source().join("libusb/hid.c"));
+ config.include(source().join("hidapi"));
+
+ for path in pkg_config::find_library("libusb-1.0").unwrap().include_paths {
+ config.include(path.to_str().unwrap());
+ }
+
+ config.compile("libhidapi-libusb.a");
+
+ Ok(())
+}
+
+#[cfg(target_os = "macos")]
+fn build() -> io::Result<()> {
+ let mut config = gcc::Config::new();
+
+ config.file(source().join("libusb/hid.c"));
+ config.include(source().join("hidapi"));
+
+ for path in pkg_config::find_library("libusb-1.0").unwrap().include_paths {
+ config.include(path.to_str().unwrap());
+ }
+
+ config.compile("libhidapi.a");
+
+ Ok(())
+}
+
+#[cfg(target_os = "windows")]
+fn build() -> io::Result<()> {
+ let mut config = gcc::Config::new();
+
+ config.file(source().join("windows/hid.c"));
+ config.include(source().join("hidapi"));
+
+ config.compile("libhidapi.a");
+
+ Ok(())
+}