]> git.lizzy.rs Git - rust.git/blob - src/libstd/build.rs
Auto merge of #49091 - nikomatsakis:issue-49043-ty-infer-hash, r=michaelwoerister
[rust.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     let cflags = env::var("CFLAGS").unwrap_or_default() + " -fvisibility=hidden -O2";
90
91     run(Command::new("sh")
92                 .current_dir(&native.out_dir)
93                 .arg(native.src_dir.join("configure").to_str().unwrap()
94                                    .replace("C:\\", "/c/")
95                                    .replace("\\", "/"))
96                 .arg("--with-pic")
97                 .arg("--disable-multilib")
98                 .arg("--disable-shared")
99                 .arg("--disable-host-shared")
100                 .arg(format!("--host={}", build_helper::gnu_target(target)))
101                 .arg(format!("--build={}", build_helper::gnu_target(host)))
102                 .env("CFLAGS", cflags));
103
104     run(Command::new(build_helper::make(host))
105                 .current_dir(&native.out_dir)
106                 .arg(format!("INCDIR={}", native.src_dir.display()))
107                 .arg("-j").arg(env::var("NUM_JOBS").expect("NUM_JOBS was not set")));
108     Ok(())
109 }