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