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
// libstd features
pub debug_jemalloc: bool,
pub use_jemalloc: bool,
+ pub backtrace: bool, // support for RUST_BACKTRACE
// misc
pub channel: String,
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>,
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;
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();
# 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"
if self.config.use_jemalloc {
features.push_str(" jemalloc");
}
+ if self.config.backtrace {
+ features.push_str(" backtrace");
+ }
return features
}
gcc = "0.3"
[features]
+backtrace = []
jemalloc = ["alloc_jemalloc"]
debug-jemalloc = ["alloc_jemalloc/debug"]
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);
}
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;
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.
}
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;
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.");
+ }
}
};
pub mod args;
pub mod at_exit_imp;
+#[cfg(feature = "backtrace")]
pub mod backtrace;
pub mod condvar;
pub mod io;
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;
pub mod weak;
pub mod android;
+#[cfg(feature = "backtrace")]
pub mod backtrace;
pub mod condvar;
pub mod ext;
[features]
jemalloc = ["std/jemalloc"]
debug-jemalloc = ["std/debug-jemalloc"]
+backtrace = ["std/backtrace"]