From 90950a1eccf54507730123eac1713385b5e3a5e7 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Mon, 9 Aug 2021 17:02:34 -0700 Subject: [PATCH] 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. --- library/unwind/build.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/library/unwind/build.rs b/library/unwind/build.rs index 0529d24a27408..da98a8e921b49 100644 --- a/library/unwind/build.rs +++ b/library/unwind/build.rs @@ -65,8 +65,8 @@ fn main() { } mod llvm_libunwind { - use std::env; - use std::path::Path; + use std::path::{Path, PathBuf}; + use std::{env, fs, io}; /// Compile the libunwind C/C++ source code. pub fn compile() { @@ -76,6 +76,14 @@ mod llvm_libunwind { let mut cpp_cfg = cc::Build::new(); let root = Path::new("../../src/llvm-project/libunwind"); + // We depend on starting with a fresh build directory each time. + let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); + if let Err(x) = fs::remove_dir_all(&out_dir) { + if x.kind() != io::ErrorKind::NotFound { + panic!("Failed removing OUT_DIR at {}: {}", out_dir.display(), x); + } + } + cpp_cfg.cpp(true); cpp_cfg.cpp_set_stdlib(None); cpp_cfg.flag("-nostdinc++"); @@ -137,7 +145,7 @@ mod llvm_libunwind { "UnwindRegistersSave.S", ]; - let cpp_sources = vec!["Unwind-EHABI.cpp", "Unwind-seh.cpp", "libunwind.cpp"]; + let cpp_sources = &["Unwind-EHABI.cpp", "Unwind-seh.cpp", "libunwind.cpp"]; let cpp_len = cpp_sources.len(); if target.contains("x86_64-fortanix-unknown-sgx") {