-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
50 lines (44 loc) · 1.6 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
use std::env;
use std::path::Path;
/// Links both libfreefare & libnfc
///
/// Allow custom paths at LIBFREEFARE_PATH and LIBNFC_PATH if preferred
/// Assume default Homebrew installation location on Mac OS; can be overriden as mentioned above
/// Verify paths exist before linking
///
fn main() {
let libfreefare_path = env::var("LIBFREEFARE_PATH").unwrap_or_else(|_| {
if cfg!(target_os = "macos") {
"/opt/homebrew/opt/libfreefare/lib".to_string()
} else if cfg!(target_os = "linux") {
"/usr/lib".to_string()
} else {
panic!("Unsupported platform. Please set LIBFREEFARE_PATH.");
}
});
if !Path::new(&libfreefare_path).exists() {
panic!(
"Could not find libfreefare at '{}'. Please install libfreefare or set LIBFREEFARE_PATH.",
libfreefare_path
);
}
println!("cargo:rustc-link-search=native={}", libfreefare_path);
println!("cargo:rustc-link-lib=freefare");
let libnfc_path = env::var("LIBNFC_PATH").unwrap_or_else(|_| {
if cfg!(target_os = "macos") {
"/opt/homebrew/opt/libnfc/lib".to_string()
} else if cfg!(target_os = "linux") {
"/usr/lib".to_string()
} else {
panic!("Unsupported platform. Please set LIBNFC_PATH.");
}
});
if !Path::new(&libnfc_path).exists() {
panic!(
"Could not find libnfc at '{}'. Please install libnfc or set LIBNFC_PATH.",
libnfc_path
);
}
println!("cargo:rustc-link-search=native={}", libnfc_path);
println!("cargo:rustc-link-lib=nfc");
}