4 println!("cargo:rerun-if-changed=build.rs");
5 let target = env::var("TARGET").expect("TARGET was not set");
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");
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");
49 #[cfg(all(not(bootstrap), feature = "llvm-libunwind"))]
54 /// Compile the libunwind C/C++ source code.
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();
61 cfg.cpp_set_stdlib(None);
64 if target_env == "msvc" {
65 // Don't pull in extra libraries on MSVC
68 cfg.define("_CRT_SECURE_NO_WARNINGS", None);
69 cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None);
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");
80 let mut unwind_sources = vec![
84 "UnwindLevel1-gcc-ext.c",
86 "UnwindRegistersRestore.S",
87 "UnwindRegistersSave.S",
91 if target_vendor == "apple" {
92 unwind_sources.push("Unwind_AppleExtras.cpp");
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));
101 cfg.compile("unwind");