1 use pkg_config::Config;
2 
main()3 fn main() {
4     let target_dir = std::env::var_os("CARGO_TARGET_DIR").unwrap();
5     let cxx_outdir = std::env::var_os("CXX_OUTDIR").unwrap();
6 
7     // The main linking point with c++ code is the libbluetooth-static.a
8     // These includes all the symbols built via C++ but doesn't include other
9     // links (i.e. pkg-config)
10     println!("cargo:rustc-link-lib=static:-bundle,+whole-archive=bluetooth-static");
11     println!("cargo:rustc-link-search=native={}", target_dir.clone().into_string().unwrap());
12     // Also re-run the build if anything in the C++ build changes
13     println!("cargo:rerun-if-changed={}", cxx_outdir.into_string().unwrap());
14 
15     // A few dynamic links
16     Config::new().probe("flatbuffers").unwrap();
17     Config::new().probe("protobuf").unwrap();
18     println!("cargo:rustc-link-lib=dylib=resolv");
19 
20     // Clang requires -lc++ instead of -lstdc++
21     println!("cargo:rustc-link-lib=c++");
22 
23     // A few more dependencies from pkg-config. These aren't included as part of
24     // the libbluetooth-static.a
25     Config::new().probe("libchrome").unwrap();
26     Config::new().probe("libmodp_b64").unwrap();
27     Config::new().probe("tinyxml2").unwrap();
28     Config::new().probe("lc3").unwrap();
29     Config::new().probe("fmt").unwrap();
30 
31     // Include ChromeOS-specific dependencies.
32     if option_env!("TARGET_OS_VARIANT").unwrap_or("None") == "chromeos" {
33         Config::new().probe("libstructuredmetrics").unwrap();
34     }
35 
36     println!("cargo:rerun-if-changed=build.rs");
37 }
38