summaryrefslogtreecommitdiffstats
path: root/third_party/rust/libloading/build.rs
blob: fdc446d34b5e2b66708d3934b133478aa44ed2f2 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use std::io::Write;
use std::env;

fn dlerror_is_mtsafe(target_os: &str) {
    match target_os {
        // Confirmed MT-safe:
        "linux"
        | "android"
        | "openbsd"
        | "macos"
        | "ios"
        | "solaris"
        | "illumos"
        | "redox"
        | "fuchsia" => {
            println!("cargo:rustc-cfg=mtsafe_dlerror");
        }
        // Confirmed not MT-safe:
        "freebsd"
        | "dragonfly"
        | "netbsd"
        | "bitrig"
        | "haiku" => {}
        // Unknown:
        _ => {}
    }
}

fn link_libraries(target_os: &str) {
    match target_os {
        "linux" | "android" => println!("cargo:rustc-link-lib=dl"),
        "freebsd" | "dragonfly" => println!("cargo:rustc-link-lib=c"),
        // netbsd claims dl* will be available to any dynamically linked binary, but I haven’t
        // found any libraries that have to be linked to on other platforms.
        // What happens if the executable is not linked up dynamically?
        "openbsd" | "bitrig" | "netbsd" | "macos" | "ios" => {}
        "solaris" | "illumos" => {}
        "haiku" => {}
        "redox" => {}
        "fuchsia" => {}
        // dependencies come with winapi
        "windows" => {}
        tos => {
            writeln!(::std::io::stderr(),
                     "Building for an unknown target_os=`{:?}`!\nPlease report an issue ",
                     tos).expect("could not report the error");
            ::std::process::exit(0xfc);
        }
    }
}

fn main() {
    match env::var("CARGO_CFG_TARGET_OS") {
        Ok(target_os) => {
            dlerror_is_mtsafe(&target_os);
            link_libraries(&target_os);
        }
        Err(e) => {
            writeln!(::std::io::stderr(),
                     "Unable to get target_os=`{}`!", e).expect("could not report the error");
            ::std::process::exit(0xfd);
        }
    }
}