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