2020-06-30 17:19:09 +08:00
|
|
|
fn main() {
|
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
2020-07-02 11:36:38 +08:00
|
|
|
llvm_libunwind::compile_cpp();
|
|
|
|
llvm_libunwind::compile_c();
|
2020-06-30 17:19:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mod llvm_libunwind {
|
|
|
|
use std::path::Path;
|
|
|
|
|
2020-07-02 11:36:38 +08:00
|
|
|
fn setup_options(cfg: &mut cc::Build) {
|
|
|
|
cfg.no_default_flags(true);
|
2020-06-30 17:19:09 +08:00
|
|
|
cfg.warnings(false);
|
|
|
|
|
|
|
|
cfg.flag("-nostdlib");
|
|
|
|
cfg.flag("-ffreestanding");
|
|
|
|
cfg.flag("-fno-PIC");
|
|
|
|
cfg.flag("-Isrc");
|
|
|
|
cfg.flag("-isystem../include");
|
|
|
|
cfg.flag("-fno-stack-protector");
|
|
|
|
cfg.flag("--target=armv7-none-eabihf");
|
2020-07-02 11:36:38 +08:00
|
|
|
cfg.flag("-O2");
|
|
|
|
|
|
|
|
cfg.flag("-std=c99");
|
|
|
|
cfg.flag("-fstrict-aliasing");
|
|
|
|
cfg.flag("-fvisibility=hidden");
|
|
|
|
cfg.flag_if_supported("-fvisibility-global-new-delete-hidden");
|
2020-06-30 17:19:09 +08:00
|
|
|
cfg.define("_LIBUNWIND_IS_BAREMETAL", Some("1"));
|
|
|
|
cfg.define("_LIBUNWIND_NO_HEAP", Some("1"));
|
|
|
|
cfg.define("_LIBUNWIND_HAS_NO_THREADS", Some("1"));
|
|
|
|
cfg.define("NDEBUG", Some("1"));
|
2020-07-02 11:36:38 +08:00
|
|
|
// libunwind expects a __LITTLE_ENDIAN__ macro to be set for LE archs, cf. #65765
|
|
|
|
cfg.define("__LITTLE_ENDIAN__", Some("1"));
|
|
|
|
cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None);
|
|
|
|
cfg.flag("-U_FORTIFY_SOURCE");
|
|
|
|
cfg.define("_FORTIFY_SOURCE", Some("0"));
|
|
|
|
}
|
2020-06-30 17:19:09 +08:00
|
|
|
|
2020-07-02 11:36:38 +08:00
|
|
|
pub fn compile_c() {
|
|
|
|
let cfg = &mut cc::Build::new();
|
|
|
|
setup_options(cfg);
|
|
|
|
cfg.compiler("clang");
|
2020-07-02 13:10:11 +08:00
|
|
|
cfg.flag("-funwind-tables");
|
2020-07-02 11:36:38 +08:00
|
|
|
|
|
|
|
let unwind_sources = vec![
|
|
|
|
"Unwind-sjlj.c",
|
|
|
|
"UnwindLevel1-gcc-ext.c",
|
|
|
|
"UnwindLevel1.c",
|
|
|
|
"UnwindRegistersRestore.S",
|
|
|
|
"UnwindRegistersSave.S",
|
|
|
|
];
|
|
|
|
|
|
|
|
let root = Path::new("../llvm_libunwind");
|
|
|
|
cfg.include(root.join("include"));
|
|
|
|
for src in unwind_sources {
|
|
|
|
println!("cargo:rerun-if-changed={}", src);
|
|
|
|
cfg.file(root.join("src").join(src));
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg.compile("unwind_c");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Compile the libunwind C/C++ source code.
|
|
|
|
pub fn compile_cpp() {
|
|
|
|
let cfg = &mut cc::Build::new();
|
|
|
|
setup_options(cfg);
|
|
|
|
cfg.compiler("clang++");
|
|
|
|
cfg.cpp(true);
|
|
|
|
cfg.cpp_set_stdlib(None);
|
|
|
|
|
|
|
|
// c++ options
|
2020-06-30 17:19:09 +08:00
|
|
|
cfg.flag("-std=c++11");
|
|
|
|
cfg.flag("-nostdinc++");
|
|
|
|
cfg.flag("-fno-exceptions");
|
|
|
|
cfg.flag("-fno-rtti");
|
|
|
|
cfg.flag("-fstrict-aliasing");
|
|
|
|
cfg.flag("-funwind-tables");
|
|
|
|
cfg.flag("-fvisibility=hidden");
|
|
|
|
cfg.flag_if_supported("-fvisibility-global-new-delete-hidden");
|
|
|
|
|
|
|
|
let unwind_sources = vec![
|
|
|
|
"Unwind-EHABI.cpp",
|
|
|
|
"Unwind-seh.cpp",
|
|
|
|
"libunwind.cpp"
|
|
|
|
];
|
|
|
|
|
|
|
|
let root = Path::new("../llvm_libunwind");
|
|
|
|
cfg.include(root.join("include"));
|
|
|
|
for src in unwind_sources {
|
|
|
|
println!("cargo:rerun-if-changed={}", src);
|
|
|
|
cfg.file(root.join("src").join(src));
|
|
|
|
}
|
|
|
|
|
2020-07-02 11:36:38 +08:00
|
|
|
cfg.compile("unwind_cpp");
|
2020-06-30 17:19:09 +08:00
|
|
|
}
|
|
|
|
}
|