Skip to content

Commit 90950a1

Browse files
committed
unwind: make build.rs do clean rebuilds
If the build by this was interrupted or otherwise left incomplete, there could be object files hanging around, which triggers an assertion later. Since we unconditionally rebuild everything here anyway, start with a clean slate each build.
1 parent 362e0f5 commit 90950a1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

library/unwind/build.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ fn main() {
6565
}
6666

6767
mod llvm_libunwind {
68-
use std::env;
69-
use std::path::Path;
68+
use std::path::{Path, PathBuf};
69+
use std::{env, fs, io};
7070

7171
/// Compile the libunwind C/C++ source code.
7272
pub fn compile() {
@@ -76,6 +76,14 @@ mod llvm_libunwind {
7676
let mut cpp_cfg = cc::Build::new();
7777
let root = Path::new("../../src/llvm-project/libunwind");
7878

79+
// We depend on starting with a fresh build directory each time.
80+
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
81+
if let Err(x) = fs::remove_dir_all(&out_dir) {
82+
if x.kind() != io::ErrorKind::NotFound {
83+
panic!("Failed removing OUT_DIR at {}: {}", out_dir.display(), x);
84+
}
85+
}
86+
7987
cpp_cfg.cpp(true);
8088
cpp_cfg.cpp_set_stdlib(None);
8189
cpp_cfg.flag("-nostdinc++");
@@ -137,7 +145,7 @@ mod llvm_libunwind {
137145
"UnwindRegistersSave.S",
138146
];
139147

140-
let cpp_sources = vec!["Unwind-EHABI.cpp", "Unwind-seh.cpp", "libunwind.cpp"];
148+
let cpp_sources = &["Unwind-EHABI.cpp", "Unwind-seh.cpp", "libunwind.cpp"];
141149
let cpp_len = cpp_sources.len();
142150

143151
if target.contains("x86_64-fortanix-unknown-sgx") {

0 commit comments

Comments
 (0)