]> git.lizzy.rs Git - rust.git/blob - src/libunwind/build.rs
Rollup merge of #60756 - matthewjasper:extra-impl-trait-tests, r=nikomatsakis
[rust.git] / src / libunwind / build.rs
1 use std::env;
2
3 fn main() {
4     println!("cargo:rerun-if-changed=build.rs");
5     let target = env::var("TARGET").expect("TARGET was not set");
6
7     if cfg!(feature = "llvm-libunwind") &&
8         (target.contains("linux") ||
9          target.contains("fuchsia")) {
10         // Build the unwinding from libunwind C/C++ source code.
11         #[cfg(feature = "llvm-libunwind")]
12         llvm_libunwind::compile();
13     } else if target.contains("linux") {
14         if target.contains("musl") {
15             // musl is handled in lib.rs
16         } else if !target.contains("android") {
17             println!("cargo:rustc-link-lib=gcc_s");
18         }
19     } else if target.contains("freebsd") {
20         println!("cargo:rustc-link-lib=gcc_s");
21     } else if target.contains("rumprun") {
22         println!("cargo:rustc-link-lib=unwind");
23     } else if target.contains("netbsd") {
24         println!("cargo:rustc-link-lib=gcc_s");
25     } else if target.contains("openbsd") {
26         println!("cargo:rustc-link-lib=c++abi");
27     } else if target.contains("solaris") {
28         println!("cargo:rustc-link-lib=gcc_s");
29     } else if target.contains("dragonfly") {
30         println!("cargo:rustc-link-lib=gcc_pic");
31     } else if target.contains("windows-gnu") {
32         println!("cargo:rustc-link-lib=static-nobundle=gcc_eh");
33         println!("cargo:rustc-link-lib=static-nobundle=pthread");
34     } else if target.contains("fuchsia") {
35         println!("cargo:rustc-link-lib=unwind");
36     } else if target.contains("haiku") {
37         println!("cargo:rustc-link-lib=gcc_s");
38     } else if target.contains("redox") {
39         println!("cargo:rustc-link-lib=gcc");
40     } else if target.contains("cloudabi") {
41         println!("cargo:rustc-link-lib=unwind");
42     }
43 }
44
45 #[cfg(feature = "llvm-libunwind")]
46 mod llvm_libunwind {
47     use std::env;
48     use std::path::Path;
49
50     /// Compile the libunwind C/C++ source code.
51     pub fn compile() {
52         let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
53         let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();
54         let cfg = &mut cc::Build::new();
55
56         cfg.cpp(true);
57         cfg.cpp_set_stdlib(None);
58         cfg.warnings(false);
59
60         if target_env == "msvc" {
61             // Don't pull in extra libraries on MSVC
62             cfg.flag("/Zl");
63             cfg.flag("/EHsc");
64             cfg.define("_CRT_SECURE_NO_WARNINGS", None);
65             cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None);
66         } else {
67             cfg.flag("-std=c99");
68             cfg.flag("-std=c++11");
69             cfg.flag("-nostdinc++");
70             cfg.flag("-fno-exceptions");
71             cfg.flag("-fno-rtti");
72             cfg.flag("-fstrict-aliasing");
73             cfg.flag("-funwind-tables");
74         }
75
76         let mut unwind_sources = vec![
77             "Unwind-EHABI.cpp",
78             "Unwind-seh.cpp",
79             "Unwind-sjlj.c",
80             "UnwindLevel1-gcc-ext.c",
81             "UnwindLevel1.c",
82             "UnwindRegistersRestore.S",
83             "UnwindRegistersSave.S",
84             "libunwind.cpp",
85         ];
86
87         if target_vendor == "apple" {
88             unwind_sources.push("Unwind_AppleExtras.cpp");
89         }
90
91         let root = Path::new("../llvm-project/libunwind");
92         cfg.include(root.join("include"));
93         for src in unwind_sources {
94             cfg.file(root.join("src").join(src));
95         }
96
97         cfg.compile("unwind");
98     }
99 }