-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
58 lines (49 loc) · 1.48 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#[cfg(not(target_env = "msvc"))]
fn main() {
println!("cargo:rerun-if-changed=src/SiUSBXp.c");
let mut config = pkg_config::Config::new();
config.print_system_libs(false);
let mut gcc = cc::Build::new();
match config.find("libusb") {
Ok(lib) => lib.include_paths.iter().for_each(|include| {
gcc.include(include);
}),
Err(e) => {
panic!("run pkg_config fail: {:?}", e);
}
};
// nowadays libusb of most OS use libusb-1.0 as backend
match config.find("libusb-1.0") {
Ok(lib) => lib.include_paths.iter().for_each(|include| {
gcc.include(include);
}),
Err(_e) => {}
};
gcc.file("src/SiUSBXp.c")
.flag("-Wno-unused-parameter")
.pic(true)
.compile("SiUSBXp");
}
#[cfg(target_env = "msvc")]
fn main() {
println!("cargo:rerun-if-changed=src/SiUSBXp.c");
if std::env::var_os("VCPKGRS_DYNAMIC").is_none() {
std::env::set_var("VCPKGRS_DYNAMIC", "1");
}
let lib = vcpkg::Config::new()
.emit_includes(true)
.find_package("libusb-win32");
if let Err(e) = lib {
panic!("note: vcpkg did not find libusb-win32: {}", e);
}
let lib = lib.unwrap();
let mut msvc = cc::Build::new();
for include in lib.include_paths.iter() {
msvc.include(include);
}
msvc.file("src/SiUSBXp.c")
// ignore unused parameter
.flag("/wd4512")
.pic(true)
.compile("SiUSBXp");
}