]> git.proxmox.com Git - rustc.git/blob - src/libstd/build.rs
New upstream version 1.24.1+dfsg1
[rustc.git] / src / libstd / build.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![deny(warnings)]
12
13 extern crate build_helper;
14
15 use std::env;
16 use std::process::Command;
17 use build_helper::{run, native_lib_boilerplate};
18
19 fn main() {
20 let target = env::var("TARGET").expect("TARGET was not set");
21 let host = env::var("HOST").expect("HOST was not set");
22 if cfg!(feature = "backtrace") &&
23 !target.contains("cloudabi") &&
24 !target.contains("emscripten") &&
25 !target.contains("fuchsia") &&
26 !target.contains("msvc") &&
27 !target.contains("wasm32")
28 {
29 let _ = build_libbacktrace(&host, &target);
30 }
31
32 if target.contains("linux") {
33 if target.contains("android") {
34 println!("cargo:rustc-link-lib=dl");
35 println!("cargo:rustc-link-lib=log");
36 println!("cargo:rustc-link-lib=gcc");
37 } else if !target.contains("musl") {
38 println!("cargo:rustc-link-lib=dl");
39 println!("cargo:rustc-link-lib=rt");
40 println!("cargo:rustc-link-lib=pthread");
41 }
42 } else if target.contains("freebsd") {
43 println!("cargo:rustc-link-lib=execinfo");
44 println!("cargo:rustc-link-lib=pthread");
45 } else if target.contains("dragonfly") || target.contains("bitrig") ||
46 target.contains("netbsd") || target.contains("openbsd") {
47 println!("cargo:rustc-link-lib=pthread");
48 } else if target.contains("solaris") {
49 println!("cargo:rustc-link-lib=socket");
50 println!("cargo:rustc-link-lib=posix4");
51 println!("cargo:rustc-link-lib=pthread");
52 println!("cargo:rustc-link-lib=resolv");
53 } else if target.contains("apple-darwin") {
54 println!("cargo:rustc-link-lib=System");
55
56 // res_init and friends require -lresolv on macOS/iOS.
57 // See #41582 and http://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html
58 println!("cargo:rustc-link-lib=resolv");
59 } else if target.contains("apple-ios") {
60 println!("cargo:rustc-link-lib=System");
61 println!("cargo:rustc-link-lib=objc");
62 println!("cargo:rustc-link-lib=framework=Security");
63 println!("cargo:rustc-link-lib=framework=Foundation");
64 println!("cargo:rustc-link-lib=resolv");
65 } else if target.contains("windows") {
66 println!("cargo:rustc-link-lib=advapi32");
67 println!("cargo:rustc-link-lib=ws2_32");
68 println!("cargo:rustc-link-lib=userenv");
69 println!("cargo:rustc-link-lib=shell32");
70 } else if target.contains("fuchsia") {
71 // use system-provided libbacktrace
72 if cfg!(feature = "backtrace") {
73 println!("cargo:rustc-link-lib=backtrace");
74 }
75 println!("cargo:rustc-link-lib=zircon");
76 println!("cargo:rustc-link-lib=fdio");
77 println!("cargo:rustc-link-lib=launchpad"); // for std::process
78 } else if target.contains("cloudabi") {
79 if cfg!(feature = "backtrace") {
80 println!("cargo:rustc-link-lib=unwind");
81 }
82 println!("cargo:rustc-link-lib=c");
83 println!("cargo:rustc-link-lib=compiler_rt");
84 }
85 }
86
87 fn build_libbacktrace(host: &str, target: &str) -> Result<(), ()> {
88 let native = native_lib_boilerplate("libbacktrace", "libbacktrace", "backtrace", ".libs")?;
89
90 run(Command::new("sh")
91 .current_dir(&native.out_dir)
92 .arg(native.src_dir.join("configure").to_str().unwrap()
93 .replace("C:\\", "/c/")
94 .replace("\\", "/"))
95 .arg("--with-pic")
96 .arg("--disable-multilib")
97 .arg("--disable-shared")
98 .arg("--disable-host-shared")
99 .arg(format!("--host={}", build_helper::gnu_target(target)))
100 .arg(format!("--build={}", build_helper::gnu_target(host)))
101 .env("CFLAGS", env::var("CFLAGS").unwrap_or_default() + " -fvisibility=hidden"));
102
103 run(Command::new(build_helper::make(host))
104 .current_dir(&native.out_dir)
105 .arg(format!("INCDIR={}", native.src_dir.display()))
106 .arg("-j").arg(env::var("NUM_JOBS").expect("NUM_JOBS was not set")));
107 Ok(())
108 }