std: always depend on backtrace, but only enable its features on demand
This commit is contained in:
parent
3287a65fc0
commit
b60954757e
9 changed files with 23 additions and 21 deletions
|
@ -490,7 +490,7 @@ impl Build {
|
||||||
features.push_str(" llvm-libunwind");
|
features.push_str(" llvm-libunwind");
|
||||||
}
|
}
|
||||||
if self.config.backtrace {
|
if self.config.backtrace {
|
||||||
features.push_str(" backtrace");
|
features.push_str(" backtrace_support");
|
||||||
}
|
}
|
||||||
if self.config.profiler {
|
if self.config.profiler {
|
||||||
features.push_str(" profiler");
|
features.push_str(" profiler");
|
||||||
|
|
|
@ -27,15 +27,8 @@ hashbrown = { version = "0.5.0", features = ['rustc-dep-of-std'] }
|
||||||
|
|
||||||
[dependencies.backtrace]
|
[dependencies.backtrace]
|
||||||
version = "0.3.37"
|
version = "0.3.37"
|
||||||
default-features = false # don't use coresymbolication on OSX
|
default-features = false # without the libstd `backtrace` feature, stub out everything
|
||||||
features = [
|
features = [ "rustc-dep-of-std" ] # enable build support for integrating into libstd
|
||||||
"rustc-dep-of-std", # enable build support for integrating into libstd
|
|
||||||
"dbghelp", # backtrace/symbolize on MSVC
|
|
||||||
"libbacktrace", # symbolize on most platforms
|
|
||||||
"libunwind", # backtrace on most platforms
|
|
||||||
"dladdr", # symbolize on platforms w/o libbacktrace
|
|
||||||
]
|
|
||||||
optional = true
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
|
@ -65,6 +58,13 @@ cc = "1.0"
|
||||||
[features]
|
[features]
|
||||||
default = ["std_detect_file_io", "std_detect_dlsym_getauxval"]
|
default = ["std_detect_file_io", "std_detect_dlsym_getauxval"]
|
||||||
|
|
||||||
|
backtrace_support = [
|
||||||
|
"backtrace/dbghelp", # backtrace/symbolize on MSVC
|
||||||
|
"backtrace/libbacktrace", # symbolize on most platforms
|
||||||
|
"backtrace/libunwind", # backtrace on most platforms
|
||||||
|
"backtrace/dladdr", # symbolize on platforms w/o libbacktrace
|
||||||
|
]
|
||||||
|
|
||||||
panic-unwind = ["panic_unwind"]
|
panic-unwind = ["panic_unwind"]
|
||||||
profiler = ["profiler_builtins"]
|
profiler = ["profiler_builtins"]
|
||||||
compiler-builtins-c = ["alloc/compiler-builtins-c"]
|
compiler-builtins-c = ["alloc/compiler-builtins-c"]
|
||||||
|
|
|
@ -49,7 +49,7 @@ fn main() {
|
||||||
println!("cargo:rustc-link-lib=zircon");
|
println!("cargo:rustc-link-lib=zircon");
|
||||||
println!("cargo:rustc-link-lib=fdio");
|
println!("cargo:rustc-link-lib=fdio");
|
||||||
} else if target.contains("cloudabi") {
|
} else if target.contains("cloudabi") {
|
||||||
if cfg!(feature = "backtrace") {
|
if cfg!(feature = "backtrace_support") {
|
||||||
println!("cargo:rustc-link-lib=unwind");
|
println!("cargo:rustc-link-lib=unwind");
|
||||||
}
|
}
|
||||||
println!("cargo:rustc-link-lib=c");
|
println!("cargo:rustc-link-lib=c");
|
||||||
|
|
|
@ -157,12 +157,12 @@ pub fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_hook(info: &PanicInfo<'_>) {
|
fn default_hook(info: &PanicInfo<'_>) {
|
||||||
#[cfg(feature = "backtrace")]
|
#[cfg(feature = "backtrace_support")]
|
||||||
use crate::sys_common::{backtrace as backtrace_mod};
|
use crate::sys_common::{backtrace as backtrace_mod};
|
||||||
|
|
||||||
// If this is a double panic, make sure that we print a backtrace
|
// If this is a double panic, make sure that we print a backtrace
|
||||||
// for this panic. Otherwise only print it if logging is enabled.
|
// for this panic. Otherwise only print it if logging is enabled.
|
||||||
#[cfg(feature = "backtrace")]
|
#[cfg(feature = "backtrace_support")]
|
||||||
let log_backtrace = {
|
let log_backtrace = {
|
||||||
let panics = update_panic_count(0);
|
let panics = update_panic_count(0);
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ fn default_hook(info: &PanicInfo<'_>) {
|
||||||
let _ = writeln!(err, "thread '{}' panicked at '{}', {}",
|
let _ = writeln!(err, "thread '{}' panicked at '{}', {}",
|
||||||
name, msg, location);
|
name, msg, location);
|
||||||
|
|
||||||
#[cfg(feature = "backtrace")]
|
#[cfg(feature = "backtrace_support")]
|
||||||
{
|
{
|
||||||
use crate::sync::atomic::{AtomicBool, Ordering};
|
use crate::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
|
|
|
@ -44,11 +44,11 @@ fn lang_start_internal(main: &(dyn Fn() -> i32 + Sync + crate::panic::RefUnwindS
|
||||||
sys::args::init(argc, argv);
|
sys::args::init(argc, argv);
|
||||||
|
|
||||||
// Let's run some code!
|
// Let's run some code!
|
||||||
#[cfg(feature = "backtrace")]
|
#[cfg(feature = "backtrace_support")]
|
||||||
let exit_code = panic::catch_unwind(|| {
|
let exit_code = panic::catch_unwind(|| {
|
||||||
sys_common::backtrace::__rust_begin_short_backtrace(move || main())
|
sys_common::backtrace::__rust_begin_short_backtrace(move || main())
|
||||||
});
|
});
|
||||||
#[cfg(not(feature = "backtrace"))]
|
#[cfg(not(feature = "backtrace_support"))]
|
||||||
let exit_code = panic::catch_unwind(move || main());
|
let exit_code = panic::catch_unwind(move || main());
|
||||||
|
|
||||||
sys_common::cleanup();
|
sys_common::cleanup();
|
||||||
|
|
|
@ -7,7 +7,6 @@ use crate::io;
|
||||||
use crate::borrow::Cow;
|
use crate::borrow::Cow;
|
||||||
use crate::io::prelude::*;
|
use crate::io::prelude::*;
|
||||||
use crate::path::{self, Path, PathBuf};
|
use crate::path::{self, Path, PathBuf};
|
||||||
use crate::sync::atomic::{self, Ordering};
|
|
||||||
use crate::sys::mutex::Mutex;
|
use crate::sys::mutex::Mutex;
|
||||||
|
|
||||||
use backtrace::{BacktraceFmt, BytesOrWideString, PrintFmt};
|
use backtrace::{BacktraceFmt, BytesOrWideString, PrintFmt};
|
||||||
|
@ -34,6 +33,7 @@ pub fn lock() -> impl Drop {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints the current backtrace.
|
/// Prints the current backtrace.
|
||||||
|
#[cfg(feature = "backtrace_support")]
|
||||||
pub fn print(w: &mut dyn Write, format: PrintFmt) -> io::Result<()> {
|
pub fn print(w: &mut dyn Write, format: PrintFmt) -> io::Result<()> {
|
||||||
// There are issues currently linking libbacktrace into tests, and in
|
// There are issues currently linking libbacktrace into tests, and in
|
||||||
// general during libstd's own unit tests we're not testing this path. In
|
// general during libstd's own unit tests we're not testing this path. In
|
||||||
|
@ -129,7 +129,10 @@ where
|
||||||
|
|
||||||
// For now logging is turned off by default, and this function checks to see
|
// For now logging is turned off by default, and this function checks to see
|
||||||
// whether the magical environment variable is present to see if it's turned on.
|
// whether the magical environment variable is present to see if it's turned on.
|
||||||
|
#[cfg(feature = "backtrace_support")]
|
||||||
pub fn log_enabled() -> Option<PrintFmt> {
|
pub fn log_enabled() -> Option<PrintFmt> {
|
||||||
|
use crate::sync::atomic::{self, Ordering};
|
||||||
|
|
||||||
// Setting environment variables for Fuchsia components isn't a standard
|
// Setting environment variables for Fuchsia components isn't a standard
|
||||||
// or easily supported workflow. For now, always display backtraces.
|
// or easily supported workflow. For now, always display backtraces.
|
||||||
if cfg!(target_os = "fuchsia") {
|
if cfg!(target_os = "fuchsia") {
|
||||||
|
|
|
@ -41,7 +41,6 @@ macro_rules! rtunwrap {
|
||||||
|
|
||||||
pub mod alloc;
|
pub mod alloc;
|
||||||
pub mod at_exit_imp;
|
pub mod at_exit_imp;
|
||||||
#[cfg(feature = "backtrace")]
|
|
||||||
pub mod backtrace;
|
pub mod backtrace;
|
||||||
pub mod condvar;
|
pub mod condvar;
|
||||||
pub mod io;
|
pub mod io;
|
||||||
|
|
|
@ -465,11 +465,11 @@ impl Builder {
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_info::set(imp::guard::current(), their_thread);
|
thread_info::set(imp::guard::current(), their_thread);
|
||||||
#[cfg(feature = "backtrace")]
|
#[cfg(feature = "backtrace_support")]
|
||||||
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||||
crate::sys_common::backtrace::__rust_begin_short_backtrace(f)
|
crate::sys_common::backtrace::__rust_begin_short_backtrace(f)
|
||||||
}));
|
}));
|
||||||
#[cfg(not(feature = "backtrace"))]
|
#[cfg(not(feature = "backtrace_support"))]
|
||||||
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(f));
|
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(f));
|
||||||
*their_packet.get() = Some(try_result);
|
*their_packet.get() = Some(try_result);
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,7 +23,7 @@ proc_macro = { path = "../libproc_macro" }
|
||||||
|
|
||||||
# Forward features to the `std` crate as necessary
|
# Forward features to the `std` crate as necessary
|
||||||
[features]
|
[features]
|
||||||
backtrace = ["std/backtrace"]
|
backtrace_support = ["std/backtrace_support"]
|
||||||
compiler-builtins-c = ["std/compiler-builtins-c"]
|
compiler-builtins-c = ["std/compiler-builtins-c"]
|
||||||
llvm-libunwind = ["std/llvm-libunwind"]
|
llvm-libunwind = ["std/llvm-libunwind"]
|
||||||
panic-unwind = ["std/panic_unwind"]
|
panic-unwind = ["std/panic_unwind"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue