]> git.lizzy.rs Git - rust.git/commitdiff
rustbuild: make backtraces (RUST_BACKTRACE) optional
authorJorge Aparicio <japaricious@gmail.com>
Tue, 26 Jul 2016 20:21:25 +0000 (15:21 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Tue, 26 Jul 2016 20:21:25 +0000 (15:21 -0500)
but keep them enabled by default to maintain the status quo.

When disabled shaves ~56KB off every x86_64-unknown-linux-gnu
binary.

To disable backtraces you have to use a config.toml (see
src/bootstrap/config.toml.example for details) when building rustc/std:

$ python bootstrap.py --config=config.toml

src/bootstrap/config.rs
src/bootstrap/config.toml.example
src/bootstrap/lib.rs
src/libstd/Cargo.toml
src/libstd/build.rs
src/libstd/panicking.rs
src/libstd/sys/common/mod.rs
src/libstd/sys/unix/mod.rs
src/rustc/std_shim/Cargo.toml

index e64d7e5a437e6103b13f7b5a471c90fa1f9b7c5b..aafbf68d1b7b60b712fac8ba7a6b091b2266c98d 100644 (file)
@@ -72,6 +72,7 @@ pub struct Config {
     // libstd features
     pub debug_jemalloc: bool,
     pub use_jemalloc: bool,
+    pub backtrace: bool, // support for RUST_BACKTRACE
 
     // misc
     pub channel: String,
@@ -134,6 +135,7 @@ struct Rust {
     debuginfo: Option<bool>,
     debug_jemalloc: Option<bool>,
     use_jemalloc: Option<bool>,
+    backtrace: Option<bool>,
     default_linker: Option<String>,
     default_ar: Option<String>,
     channel: Option<String>,
@@ -158,6 +160,7 @@ pub fn parse(build: &str, file: Option<PathBuf>) -> Config {
         let mut config = Config::default();
         config.llvm_optimize = true;
         config.use_jemalloc = true;
+        config.backtrace = true;
         config.rust_optimize = true;
         config.rust_optimize_tests = true;
         config.submodules = true;
@@ -230,6 +233,7 @@ pub fn parse(build: &str, file: Option<PathBuf>) -> Config {
             set(&mut config.rust_rpath, rust.rpath);
             set(&mut config.debug_jemalloc, rust.debug_jemalloc);
             set(&mut config.use_jemalloc, rust.use_jemalloc);
+            set(&mut config.backtrace, rust.backtrace);
             set(&mut config.channel, rust.channel.clone());
             config.rustc_default_linker = rust.default_linker.clone();
             config.rustc_default_ar = rust.default_ar.clone();
index 6f0658423283be3c61f9377c0f04dcc8f0b24f49..2894adafef622dab873f3595bd264aaac1cfb004 100644 (file)
@@ -99,6 +99,9 @@
 # Whether or not jemalloc is built with its debug option set
 #debug-jemalloc = false
 
+# Whether or not `panic!`s generate backtraces (RUST_BACKTRACE)
+#backtrace = true
+
 # The default linker that will be used by the generated compiler. Note that this
 # is not the linker used to link said compiler.
 #default-linker = "cc"
index 367322e8816465d6f298c1e4a8fec8edcb7fd035..25356b86221c1975e4b59ee6d31901611852752c 100644 (file)
@@ -652,6 +652,9 @@ fn std_features(&self) -> String {
         if self.config.use_jemalloc {
             features.push_str(" jemalloc");
         }
+        if self.config.backtrace {
+            features.push_str(" backtrace");
+        }
         return features
     }
 
index eded6e24f3ef5db2f6f0d2f06179c43b73f9ea8c..b442d21b72ba94d6a02acd48c91586700dbd127a 100644 (file)
@@ -27,5 +27,6 @@ build_helper = { path = "../build_helper" }
 gcc = "0.3"
 
 [features]
+backtrace = []
 jemalloc = ["alloc_jemalloc"]
 debug-jemalloc = ["alloc_jemalloc/debug"]
index 9c408366f8b481d38e983d83f4bdcac9cdcfbbde..9018e48d06bd1a2da7b32bbad80b836643f00497 100644 (file)
@@ -25,7 +25,8 @@ fn main() {
 
     let target = env::var("TARGET").unwrap();
     let host = env::var("HOST").unwrap();
-    if !target.contains("apple") && !target.contains("msvc") && !target.contains("emscripten"){
+    if cfg!(feature = "backtrace") && !target.contains("apple") && !target.contains("msvc") &&
+        !target.contains("emscripten") {
         build_libbacktrace(&host, &target);
     }
 
index d73e9542d21253e765958f4a1a1d51140a393dd5..319fbdaac55dbe83fd1447e2938ab90964845401 100644 (file)
 use mem;
 use raw;
 use sys_common::rwlock::RWLock;
+#[cfg(feature = "backtrace")]
 use sync::atomic::{AtomicBool, Ordering};
 use sys::stdio::Stderr;
+#[cfg(feature = "backtrace")]
 use sys_common::backtrace;
 use sys_common::thread_info;
 use sys_common::util;
@@ -71,6 +73,7 @@ enum Hook {
 
 static HOOK_LOCK: RWLock = RWLock::new();
 static mut HOOK: Hook = Hook::Default;
+#[cfg(feature = "backtrace")]
 static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
 
 /// Registers a custom panic hook, replacing any that was previously registered.
@@ -183,10 +186,12 @@ pub fn line(&self) -> u32 {
 }
 
 fn default_hook(info: &PanicInfo) {
+    #[cfg(feature = "backtrace")]
     let panics = PANIC_COUNT.with(|c| c.get());
 
     // If this is a double panic, make sure that we print a backtrace
     // for this panic. Otherwise only print it if logging is enabled.
+    #[cfg(feature = "backtrace")]
     let log_backtrace = panics >= 2 || backtrace::log_enabled();
 
     let file = info.location.file;
@@ -207,10 +212,13 @@ fn default_hook(info: &PanicInfo) {
         let _ = writeln!(err, "thread '{}' panicked at '{}', {}:{}",
                          name, msg, file, line);
 
-        if log_backtrace {
-            let _ = backtrace::write(err);
-        } else if FIRST_PANIC.compare_and_swap(true, false, Ordering::SeqCst) {
-            let _ = writeln!(err, "note: Run with `RUST_BACKTRACE=1` for a backtrace.");
+        #[cfg(feature = "backtrace")]
+        {
+            if log_backtrace {
+                let _ = backtrace::write(err);
+            } else if FIRST_PANIC.compare_and_swap(true, false, Ordering::SeqCst) {
+                let _ = writeln!(err, "note: Run with `RUST_BACKTRACE=1` for a backtrace.");
+            }
         }
     };
 
index c9279883ae59d8e2bb32c2a0d32bfee6c73b9800..67b19682fc9a8603bf5fdee29e47db71facc2104 100644 (file)
@@ -28,6 +28,7 @@ macro_rules! rtassert {
 
 pub mod args;
 pub mod at_exit_imp;
+#[cfg(feature = "backtrace")]
 pub mod backtrace;
 pub mod condvar;
 pub mod io;
@@ -42,6 +43,7 @@ macro_rules! rtassert {
 pub mod util;
 pub mod wtf8;
 
+#[cfg(feature = "backtrace")]
 #[cfg(any(all(unix, not(any(target_os = "macos", target_os = "ios", target_os = "emscripten"))),
           all(windows, target_env = "gnu")))]
 pub mod gnu;
index f0fd42fc99b806eadba0b261ddefe2ca61872980..9aac7be80176ee494ceb949089782bea8952f5f3 100644 (file)
@@ -30,6 +30,7 @@
 pub mod weak;
 
 pub mod android;
+#[cfg(feature = "backtrace")]
 pub mod backtrace;
 pub mod condvar;
 pub mod ext;
index 5602ef866b83ae800e44f877f026f16ef054d566..693cbe06ba987bcc4e60d6f1d9071d9bc5f5511c 100644 (file)
@@ -46,3 +46,4 @@ std = { path = "../../libstd" }
 [features]
 jemalloc = ["std/jemalloc"]
 debug-jemalloc = ["std/debug-jemalloc"]
+backtrace = ["std/backtrace"]