|
19 | 19 |
|
20 | 20 | extern crate cc;
|
21 | 21 |
|
| 22 | +use std::env; |
| 23 | + |
22 | 24 | fn main() {
|
23 |
| - compile(); |
24 |
| -} |
| 25 | + let target = env::var("TARGET").unwrap(); |
25 | 26 |
|
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"); |
33 | 33 |
|
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"); |
42 | 41 |
|
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 | + } |
51 | 48 | }
|
0 commit comments