|
11 | 11 | #![deny(warnings)]
|
12 | 12 |
|
13 | 13 | extern crate build_helper;
|
| 14 | +extern crate cc; |
14 | 15 |
|
| 16 | +use build_helper::native_lib_boilerplate; |
15 | 17 | use std::env;
|
16 |
| -use std::process::Command; |
17 |
| -use build_helper::{run, native_lib_boilerplate}; |
| 18 | +use std::fs::File; |
18 | 19 |
|
19 | 20 | fn main() {
|
20 | 21 | let target = env::var("TARGET").expect("TARGET was not set");
|
21 |
| - let host = env::var("HOST").expect("HOST was not set"); |
22 | 22 | if cfg!(feature = "backtrace") &&
|
23 | 23 | !target.contains("cloudabi") &&
|
24 | 24 | !target.contains("emscripten") &&
|
25 | 25 | !target.contains("fuchsia") &&
|
26 | 26 | !target.contains("msvc") &&
|
27 | 27 | !target.contains("wasm32")
|
28 | 28 | {
|
29 |
| - let _ = build_libbacktrace(&host, &target); |
| 29 | + let _ = build_libbacktrace(&target); |
30 | 30 | }
|
31 | 31 |
|
32 | 32 | if target.contains("linux") {
|
@@ -84,26 +84,55 @@ fn main() {
|
84 | 84 | }
|
85 | 85 | }
|
86 | 86 |
|
87 |
| -fn build_libbacktrace(host: &str, target: &str) -> Result<(), ()> { |
88 |
| - let native = native_lib_boilerplate("libbacktrace", "libbacktrace", "backtrace", ".libs")?; |
89 |
| - let cflags = env::var("CFLAGS").unwrap_or_default() + " -fvisibility=hidden -O2"; |
| 87 | +fn build_libbacktrace(target: &str) -> Result<(), ()> { |
| 88 | + let native = native_lib_boilerplate("libbacktrace", "libbacktrace", "backtrace", "")?; |
90 | 89 |
|
91 |
| - run(Command::new("sh") |
92 |
| - .current_dir(&native.out_dir) |
93 |
| - .arg(native.src_dir.join("configure").to_str().unwrap() |
94 |
| - .replace("C:\\", "/c/") |
95 |
| - .replace("\\", "/")) |
96 |
| - .arg("--with-pic") |
97 |
| - .arg("--disable-multilib") |
98 |
| - .arg("--disable-shared") |
99 |
| - .arg("--disable-host-shared") |
100 |
| - .arg(format!("--host={}", build_helper::gnu_target(target))) |
101 |
| - .arg(format!("--build={}", build_helper::gnu_target(host))) |
102 |
| - .env("CFLAGS", cflags)); |
| 90 | + let mut build = cc::Build::new(); |
| 91 | + build |
| 92 | + .flag("-fvisibility=hidden") |
| 93 | + .include("../libbacktrace") |
| 94 | + .include(&native.out_dir) |
| 95 | + .out_dir(&native.out_dir) |
| 96 | + .warnings(false) |
| 97 | + .file("../libbacktrace/alloc.c") |
| 98 | + .file("../libbacktrace/backtrace.c") |
| 99 | + .file("../libbacktrace/dwarf.c") |
| 100 | + .file("../libbacktrace/fileline.c") |
| 101 | + .file("../libbacktrace/posix.c") |
| 102 | + .file("../libbacktrace/read.c") |
| 103 | + .file("../libbacktrace/sort.c") |
| 104 | + .file("../libbacktrace/state.c"); |
103 | 105 |
|
104 |
| - run(Command::new(build_helper::make(host)) |
105 |
| - .current_dir(&native.out_dir) |
106 |
| - .arg(format!("INCDIR={}", native.src_dir.display())) |
107 |
| - .arg("-j").arg(env::var("NUM_JOBS").expect("NUM_JOBS was not set"))); |
| 106 | + if target.contains("darwin") { |
| 107 | + build.file("../libbacktrace/macho.c"); |
| 108 | + } else if target.contains("windows") { |
| 109 | + build.file("../libbacktrace/pecoff.c"); |
| 110 | + } else { |
| 111 | + build.file("../libbacktrace/elf.c"); |
| 112 | + |
| 113 | + if target.contains("64") { |
| 114 | + build.define("BACKTRACE_ELF_SIZE", "64"); |
| 115 | + } else { |
| 116 | + build.define("BACKTRACE_ELF_SIZE", "32"); |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + File::create(native.out_dir.join("backtrace-supported.h")).unwrap(); |
| 121 | + build.define("BACKTRACE_SUPPORTED", "1"); |
| 122 | + build.define("BACKTRACE_USES_MALLOC", "1"); |
| 123 | + build.define("BACKTRACE_SUPPORTS_THREADS", "0"); |
| 124 | + build.define("BACKTRACE_SUPPORTS_DATA", "0"); |
| 125 | + |
| 126 | + File::create(native.out_dir.join("config.h")).unwrap(); |
| 127 | + if !target.contains("apple-ios") && |
| 128 | + !target.contains("solaris") && |
| 129 | + !target.contains("redox") && |
| 130 | + !target.contains("android") { |
| 131 | + build.define("HAVE_DL_ITERATE_PHDR", "1"); |
| 132 | + } |
| 133 | + build.define("_GNU_SOURCE", "1"); |
| 134 | + build.define("_LARGE_FILES", "1"); |
| 135 | + |
| 136 | + build.compile("backtrace"); |
108 | 137 | Ok(())
|
109 | 138 | }
|
0 commit comments