]>
git.proxmox.com Git - rustc.git/blob - 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.
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.
13 extern crate build_helper
;
16 use build_helper
::native_lib_boilerplate
;
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("msvc") &&
26 !target
.contains("wasm32")
28 let _
= build_libbacktrace(&target
);
31 if target
.contains("linux") {
32 if target
.contains("android") {
33 println
!("cargo:rustc-link-lib=dl");
34 println
!("cargo:rustc-link-lib=log");
35 println
!("cargo:rustc-link-lib=gcc");
36 } else if !target
.contains("musl") {
37 println
!("cargo:rustc-link-lib=dl");
38 println
!("cargo:rustc-link-lib=rt");
39 println
!("cargo:rustc-link-lib=pthread");
41 } else if target
.contains("freebsd") {
42 println
!("cargo:rustc-link-lib=execinfo");
43 println
!("cargo:rustc-link-lib=pthread");
44 } else if target
.contains("dragonfly") || target
.contains("bitrig") ||
45 target
.contains("netbsd") || target
.contains("openbsd") {
46 println
!("cargo:rustc-link-lib=pthread");
47 } else if target
.contains("solaris") {
48 println
!("cargo:rustc-link-lib=socket");
49 println
!("cargo:rustc-link-lib=posix4");
50 println
!("cargo:rustc-link-lib=pthread");
51 println
!("cargo:rustc-link-lib=resolv");
52 } else if target
.contains("apple-darwin") {
53 println
!("cargo:rustc-link-lib=System");
55 // res_init and friends require -lresolv on macOS/iOS.
56 // See #41582 and http://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html
57 println
!("cargo:rustc-link-lib=resolv");
58 } else if target
.contains("apple-ios") {
59 println
!("cargo:rustc-link-lib=System");
60 println
!("cargo:rustc-link-lib=objc");
61 println
!("cargo:rustc-link-lib=framework=Security");
62 println
!("cargo:rustc-link-lib=framework=Foundation");
63 println
!("cargo:rustc-link-lib=resolv");
64 } else if target
.contains("windows") {
65 println
!("cargo:rustc-link-lib=advapi32");
66 println
!("cargo:rustc-link-lib=ws2_32");
67 println
!("cargo:rustc-link-lib=userenv");
68 println
!("cargo:rustc-link-lib=shell32");
69 } else if target
.contains("fuchsia") {
70 println
!("cargo:rustc-link-lib=zircon");
71 println
!("cargo:rustc-link-lib=fdio");
72 } else if target
.contains("cloudabi") {
73 if cfg
!(feature
= "backtrace") {
74 println
!("cargo:rustc-link-lib=unwind");
76 println
!("cargo:rustc-link-lib=c");
77 println
!("cargo:rustc-link-lib=compiler_rt");
81 fn build_libbacktrace(target
: &str) -> Result
<(), ()> {
82 let native
= native_lib_boilerplate("libbacktrace", "libbacktrace", "backtrace", "")?
;
84 let mut build
= cc
::Build
::new();
86 .flag("-fvisibility=hidden")
87 .include("../libbacktrace")
88 .include(&native
.out_dir
)
89 .out_dir(&native
.out_dir
)
91 .file("../libbacktrace/alloc.c")
92 .file("../libbacktrace/backtrace.c")
93 .file("../libbacktrace/dwarf.c")
94 .file("../libbacktrace/fileline.c")
95 .file("../libbacktrace/posix.c")
96 .file("../libbacktrace/read.c")
97 .file("../libbacktrace/sort.c")
98 .file("../libbacktrace/state.c");
100 let any_debug
= env
::var("RUSTC_DEBUGINFO").unwrap_or_default() == "true" ||
101 env
::var("RUSTC_DEBUGINFO_LINES").unwrap_or_default() == "true";
102 build
.debug(any_debug
);
104 if target
.contains("darwin") {
105 build
.file("../libbacktrace/macho.c");
106 } else if target
.contains("windows") {
107 build
.file("../libbacktrace/pecoff.c");
109 build
.file("../libbacktrace/elf.c");
111 let pointer_width
= env
::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap();
112 if pointer_width
== "64" {
113 build
.define("BACKTRACE_ELF_SIZE", "64");
115 build
.define("BACKTRACE_ELF_SIZE", "32");
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");
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 !target
.contains("haiku") {
131 build
.define("HAVE_DL_ITERATE_PHDR", "1");
133 build
.define("_GNU_SOURCE", "1");
134 build
.define("_LARGE_FILES", "1");
136 build
.compile("backtrace");