1 use std::env;
2 use std::fs;
3 use std::path::PathBuf;
4 
main()5 fn main() {
6     let libstdcxx = cfg!(feature = "libstdc++");
7     let libcxx = cfg!(feature = "libc++");
8     let nothing = cfg!(feature = "nothing");
9 
10     if nothing {
11         return;
12     }
13 
14     if libstdcxx && libcxx {
15         println!(
16             "cargo:warning=-lstdc++ and -lc++ are both requested, \
17              using the platform's default"
18         );
19     }
20 
21     match (libstdcxx, libcxx) {
22         (true, false) => println!("cargo:rustc-link-lib=stdc++"),
23         (false, true) => println!("cargo:rustc-link-lib=c++"),
24         (false, false) | (true, true) => {
25             // The platform's default.
26             let out_dir = env::var_os("OUT_DIR").expect("missing OUT_DIR");
27             let path = PathBuf::from(out_dir).join("dummy.cc");
28             fs::write(&path, "int rust_link_cplusplus;\n").unwrap();
29             cc::Build::new().cpp(true).file(&path).compile("link-cplusplus");
30         }
31     }
32 }
33