forked from dcuddeback/libudev-sys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
53 lines (43 loc) · 1.46 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
extern crate pkg_config;
use std::env;
use std::fs::File;
use std::path::Path;
use std::process::Command;
use std::io::prelude::*;
fn check_func(function_name: &str) -> bool {
let out_dir = env::var_os("OUT_DIR").unwrap();
let test_file_name = Path::new(&out_dir).join(format!("check_{}.rs", function_name));
{
let mut test_file = File::create(&test_file_name).unwrap();
writeln!(&mut test_file, "extern \"C\" {{").unwrap();
writeln!(&mut test_file, " fn {}();", function_name).unwrap();
writeln!(&mut test_file, "}}").unwrap();
writeln!(&mut test_file, "").unwrap();
writeln!(&mut test_file, "fn main() {{").unwrap();
writeln!(&mut test_file, " unsafe {{").unwrap();
writeln!(&mut test_file, " {}();", function_name).unwrap();
writeln!(&mut test_file, " }}").unwrap();
writeln!(&mut test_file, "}}").unwrap();
}
let output = Command::new("rustc")
.arg(&test_file_name)
.arg("--out-dir")
.arg(&out_dir)
.arg("-l")
.arg("udev")
.output()
.unwrap();
output.status.success()
}
fn main() {
if std::env::var("CARGO_CFG_TARGET_OS") == Ok("macos".to_string()) {
return;
}
pkg_config::find_library("libudev").unwrap();
if check_func("udev_hwdb_new") {
println!("cargo:rustc-cfg=hwdb");
println!("cargo:hwdb=true");
} else {
println!("cargo:hwdb=false");
}
}