Debian Codegraph @

build.rs

raw symbols SCIP
1 extern crate pkg_config;
2
3 use std::env;
4 use std::fs::File;
5 use std::path::Path;
6 use std::process::Command;
7
8 use std::io::prelude::*;
9
10 fn check_func(function_name: &str) -> bool {
11 let out_dir = env::var_os("OUT_DIR").unwrap();
12 let test_file_name = Path::new(&out_dir).join(format!("check_{}.rs", function_name));
13
14 {
15 let mut test_file = File::create(&test_file_name).unwrap();
16
17 writeln!(&mut test_file, "extern \"C\" {{").unwrap();
18 writeln!(&mut test_file, " fn {}();", function_name).unwrap();
19 writeln!(&mut test_file, "}}").unwrap();
20 writeln!(&mut test_file, "").unwrap();
21 writeln!(&mut test_file, "fn main() {{").unwrap();
22 writeln!(&mut test_file, " unsafe {{").unwrap();
23 writeln!(&mut test_file, " {}();", function_name).unwrap();
24 writeln!(&mut test_file, " }}").unwrap();
25 writeln!(&mut test_file, "}}").unwrap();
26 }
27
28 let output = Command::new("rustc").
29 arg(&test_file_name).
30 arg("--out-dir").arg(&out_dir).
31 arg("-l").arg("udev").
32 output().unwrap();
33
34 output.status.success()
35 }
36
37 fn main() {
38 pkg_config::find_library("libudev").unwrap();
39
40 if check_func("udev_hwdb_new") {
41 println!("cargo:rustc-cfg=hwdb");
42 println!("cargo:hwdb=true");
43 }
44 else {
45 println!("cargo:hwdb=false");
46 }
47 }