]> git.proxmox.com Git - rustc.git/blob - vendor/libloading/build.rs
New upstream version 1.48.0+dfsg1
[rustc.git] / vendor / libloading / build.rs
1 use std::io::Write;
2 use std::env;
3
4 fn dlerror_is_mtsafe(target_os: &str) {
5 match target_os {
6 // Confirmed MT-safe:
7 "linux"
8 | "android"
9 | "openbsd"
10 | "macos"
11 | "ios"
12 | "solaris"
13 | "illumos"
14 | "redox"
15 | "fuchsia" => {
16 println!("cargo:rustc-cfg=mtsafe_dlerror");
17 }
18 // Confirmed not MT-safe:
19 "freebsd"
20 | "dragonfly"
21 | "netbsd"
22 | "bitrig"
23 | "haiku" => {}
24 // Unknown:
25 _ => {}
26 }
27 }
28
29 fn link_libraries(target_os: &str) {
30 match target_os {
31 "linux" | "android" => println!("cargo:rustc-link-lib=dl"),
32 "freebsd" | "dragonfly" => println!("cargo:rustc-link-lib=c"),
33 // netbsd claims dl* will be available to any dynamically linked binary, but I haven’t
34 // found any libraries that have to be linked to on other platforms.
35 // What happens if the executable is not linked up dynamically?
36 "openbsd" | "bitrig" | "netbsd" | "macos" | "ios" => {}
37 "solaris" | "illumos" => {}
38 "haiku" => {}
39 "redox" => {}
40 "fuchsia" => {}
41 // dependencies come with winapi
42 "windows" => {}
43 tos => {
44 writeln!(::std::io::stderr(),
45 "Building for an unknown target_os=`{:?}`!\nPlease report an issue ",
46 tos).expect("could not report the error");
47 ::std::process::exit(0xfc);
48 }
49 }
50 }
51
52 fn main() {
53 match env::var("CARGO_CFG_TARGET_OS") {
54 Ok(target_os) => {
55 dlerror_is_mtsafe(&target_os);
56 link_libraries(&target_os);
57 }
58 Err(e) => {
59 writeln!(::std::io::stderr(),
60 "Unable to get target_os=`{}`!", e).expect("could not report the error");
61 ::std::process::exit(0xfd);
62 }
63 }
64
65 // For tests
66 println!(
67 "cargo:rustc-env=LIBLOADING_TEST_TARGET={}",
68 std::env::var("TARGET").expect("$TARGET is not set")
69 );
70 }