]> git.proxmox.com Git - rustc.git/blob - src/libstd/build.rs
New upstream version 1.28.0~beta.14+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 extern crate cc;
15
16 use build_helper::native_lib_boilerplate;
17 use std::env;
18 use std::fs::File;
19
20 fn main() {
21 let target = env::var("TARGET").expect("TARGET 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(&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 } else if target.contains("cloudabi") {
78 if cfg!(feature = "backtrace") {
79 println!("cargo:rustc-link-lib=unwind");
80 }
81 println!("cargo:rustc-link-lib=c");
82 println!("cargo:rustc-link-lib=compiler_rt");
83 }
84 }
85
86 fn build_libbacktrace(target: &str) -> Result<(), ()> {
87 let native = native_lib_boilerplate("libbacktrace", "libbacktrace", "backtrace", "")?;
88
89 let mut build = cc::Build::new();
90 build
91 .flag("-fvisibility=hidden")
92 .include("../libbacktrace")
93 .include(&native.out_dir)
94 .out_dir(&native.out_dir)
95 .warnings(false)
96 .file("../libbacktrace/alloc.c")
97 .file("../libbacktrace/backtrace.c")
98 .file("../libbacktrace/dwarf.c")
99 .file("../libbacktrace/fileline.c")
100 .file("../libbacktrace/posix.c")
101 .file("../libbacktrace/read.c")
102 .file("../libbacktrace/sort.c")
103 .file("../libbacktrace/state.c");
104
105 if target.contains("darwin") {
106 build.file("../libbacktrace/macho.c");
107 } else if target.contains("windows") {
108 build.file("../libbacktrace/pecoff.c");
109 } else {
110 build.file("../libbacktrace/elf.c");
111
112 if target.contains("64") {
113 build.define("BACKTRACE_ELF_SIZE", "64");
114 } else {
115 build.define("BACKTRACE_ELF_SIZE", "32");
116 }
117 }
118
119 File::create(native.out_dir.join("backtrace-supported.h")).unwrap();
120 build.define("BACKTRACE_SUPPORTED", "1");
121 build.define("BACKTRACE_USES_MALLOC", "1");
122 build.define("BACKTRACE_SUPPORTS_THREADS", "0");
123 build.define("BACKTRACE_SUPPORTS_DATA", "0");
124
125 File::create(native.out_dir.join("config.h")).unwrap();
126 if !target.contains("apple-ios") &&
127 !target.contains("solaris") &&
128 !target.contains("redox") &&
129 !target.contains("android") {
130 build.define("HAVE_DL_ITERATE_PHDR", "1");
131 }
132 build.define("_GNU_SOURCE", "1");
133 build.define("_LARGE_FILES", "1");
134
135 build.compile("backtrace");
136 Ok(())
137 }