Skip to content
This repository was archived by the owner on Feb 26, 2020. It is now read-only.

Commit 450f7fd

Browse files
authored
Merge pull request #2 from tomaka/fix-cross-compile
Fix the build script when cross-compiling
2 parents e77ea09 + 02dd41f commit 450f7fd

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

build.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,30 @@
1919

2020
extern crate cc;
2121

22+
use std::env;
23+
2224
fn main() {
23-
compile();
24-
}
25+
let target = env::var("TARGET").unwrap();
2526

26-
#[cfg(target_os = "linux")]
27-
fn compile() {
28-
let mut config = cc::Build::new();
29-
config.file("etc/hidapi/linux/hid.c").include("etc/hidapi/hidapi");
30-
config.compile("libhidapi.a");
31-
println!("cargo:rustc-link-lib=udev");
32-
}
27+
if target.contains("windows") {
28+
cc::Build::new()
29+
.file("etc/hidapi/windows/hid.c")
30+
.include("etc/hidapi/hidapi")
31+
.compile("libhidapi.a");
32+
println!("cargo:rustc-link-lib=setupapi");
3333

34-
#[cfg(target_os = "windows")]
35-
fn compile() {
36-
cc::Build::new()
37-
.file("etc/hidapi/windows/hid.c")
38-
.include("etc/hidapi/hidapi")
39-
.compile("libhidapi.a");
40-
println!("cargo:rustc-link-lib=setupapi");
41-
}
34+
} else if target.contains("macos") {
35+
cc::Build::new()
36+
.file("etc/hidapi/mac/hid.c")
37+
.include("etc/hidapi/hidapi")
38+
.compile("libhidapi.a");
39+
println!("cargo:rustc-link-lib=framework=IOKit");
40+
println!("cargo:rustc-link-lib=framework=CoreFoundation");
4241

43-
#[cfg(target_os = "macos")]
44-
fn compile() {
45-
cc::Build::new()
46-
.file("etc/hidapi/mac/hid.c")
47-
.include("etc/hidapi/hidapi")
48-
.compile("libhidapi.a");
49-
println!("cargo:rustc-link-lib=framework=IOKit");
50-
println!("cargo:rustc-link-lib=framework=CoreFoundation");
42+
} else if target.contains("linux") {
43+
let mut config = cc::Build::new();
44+
config.file("etc/hidapi/linux/hid.c").include("etc/hidapi/hidapi");
45+
config.compile("libhidapi.a");
46+
println!("cargo:rustc-link-lib=udev");
47+
}
5148
}

0 commit comments

Comments
 (0)