summaryrefslogtreecommitdiffstats
path: root/vendor/link-cplusplus/build.rs
blob: 1f679229edd126d72eafd7d51b7c6a9786c93b27 (plain)
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
use std::env;
use std::fs;
use std::path::PathBuf;

fn main() {
    println!("cargo:rerun-if-changed=build.rs");

    let libstdcxx = cfg!(feature = "libstdc++");
    let libcxx = cfg!(feature = "libc++");
    let nothing = cfg!(feature = "nothing");

    if nothing {
        return;
    }

    if libstdcxx && libcxx {
        println!(
            "cargo:warning=-lstdc++ and -lc++ are both requested, \
             using the platform's default"
        );
    }

    match (libstdcxx, libcxx) {
        (true, false) => println!("cargo:rustc-link-lib=stdc++"),
        (false, true) => println!("cargo:rustc-link-lib=c++"),
        (false, false) | (true, true) => {
            // The platform's default.
            let out_dir = env::var_os("OUT_DIR").expect("missing OUT_DIR");
            let path = PathBuf::from(out_dir).join("dummy.cc");
            fs::write(&path, "int rust_link_cplusplus;\n").unwrap();
            cc::Build::new().cpp(true).file(&path).compile("link-cplusplus");
        }
    }
}