Skip to content

Commit 40f3954

Browse files
authored
Migrate towards sunsetting features on this crate (#323)
* Move `kernel32` dependency to deprecated section This hasn't been used in ages actually! * Remove the `unix-backtrace` feature AFAIK there's not actual use case for this. This was added ages ago when backtrace functionality was first implemented but we've always preferred libunwind as an unwinder since it's more accurate. No platform uses this by default today, so this commit is removing the support and we can re-add it pretty easily if necessary for a new platform. * Make libunwind/dbghelp features defunkt AFAIK there's no current users of this crate who are tweaking the various methods of capturing a backtrace or symbolizing a backtrace. I believe everyone's just largely using the default features. Additionally it would be extremely hard to *not* use the default features given the wide usage of this crate. Given all this this commit simply removes the option of doing so. Instead this crate will automatically select the best implementation strategy per-platform and will provide the necessary support to enable it. It's intended to that this should give a much better default experience the avoids futzing around with features so much.
1 parent 7a95a02 commit 40f3954

File tree

10 files changed

+21
-130
lines changed

10 files changed

+21
-130
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,14 @@ jobs:
5959
- run: cargo build
6060
- run: cargo test
6161
- run: cargo test --features "gimli-symbolize"
62+
- run: cargo test --features "serialize-rustc"
63+
- run: cargo test --features "serialize-serde"
64+
- run: cargo test --features "verify-winapi"
65+
- run: cargo test --features "cpp_demangle"
6266
- run: cargo test --no-default-features
67+
- run: cargo test --no-default-features --features "libbacktrace"
68+
- run: cargo test --no-default-features --features "gimli-symbolize"
6369
- run: cargo test --no-default-features --features "std"
64-
- run: cargo test --no-default-features --features "libunwind std"
65-
- run: cargo test --no-default-features --features "libunwind dladdr std"
66-
- run: cargo test --no-default-features --features "libunwind libbacktrace std"
67-
- run: cargo test --no-default-features --features "libunwind libbacktrace dbghelp std"
68-
- run: cargo test --no-default-features --features "unix-backtrace std"
69-
- run: cargo test --no-default-features --features "unix-backtrace dladdr std"
70-
- run: cargo test --no-default-features --features "unix-backtrace libbacktrace std"
71-
- run: cargo test --no-default-features --features "serialize-serde std"
72-
- run: cargo test --no-default-features --features "serialize-rustc std"
73-
- run: cargo test --no-default-features --features "serialize-rustc serialize-serde std"
74-
- run: cargo test --no-default-features --features "cpp_demangle std"
75-
- run: cargo test --no-default-features --features "dbghelp std"
76-
- run: cargo test --no-default-features --features "dbghelp std verify-winapi"
7770
- run: cargo test --manifest-path crates/cpp_smoke_test/Cargo.toml
7871
- run: cargo test --manifest-path crates/macos_frames_test/Cargo.toml
7972
- run: cargo test --features libbacktrace --manifest-path crates/without_debuginfo/Cargo.toml

Cargo.toml

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,11 @@ winapi = { version = "0.3.3", optional = true }
5454
# Note that not all features are available on all platforms, so even though a
5555
# feature is enabled some other feature may be used instead.
5656
[features]
57-
default = ["std", "libunwind", "libbacktrace", "dbghelp"]
57+
default = ["std", "libbacktrace"]
5858

5959
# Include std support.
6060
std = []
6161

62-
#=======================================
63-
# Methods of acquiring a backtrace
64-
#
65-
# - libunwind: when using this the libgcc library is linked against to get
66-
# the unwinding support. This is generally the most reliable method to get
67-
# a backtrace on unix.
68-
# - unix-backtrace: this uses the backtrace(3) function to acquire a
69-
# backtrace, but is not as reliable as libunwind. It is, however,
70-
# generally found in more locations.
71-
# - dbghelp: on windows this enables usage of dbghelp.dll to find a
72-
# backtrace at runtime
73-
# - kernel32: on windows this enables using RtlCaptureStackBackTrace as the
74-
# function to acquire a backtrace
75-
libunwind = []
76-
unix-backtrace = []
77-
dbghelp = []
78-
kernel32 = []
79-
8062
#=======================================
8163
# Methods of resolving symbols
8264
#
@@ -107,6 +89,10 @@ serialize-serde = ["serde"]
10789
# Only here for backwards compatibility purposes, they do nothing now.
10890
coresymbolication = []
10991
dladdr = []
92+
kernel32 = []
93+
unix-backtrace = []
94+
libunwind = []
95+
dbghelp = []
11096

11197
#=======================================
11298
# Internal features for testing and such.
@@ -153,7 +139,7 @@ edition = '2018'
153139

154140
[[test]]
155141
name = "accuracy"
156-
required-features = ["std", "dbghelp", "libbacktrace", "libunwind"]
142+
required-features = ["std", "libbacktrace"]
157143
edition = '2018'
158144

159145
[[test]]

src/backtrace/mod.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ cfg_if::cfg_if! {
119119
unix,
120120
not(target_os = "emscripten"),
121121
not(all(target_os = "ios", target_arch = "arm")),
122-
feature = "libunwind",
123122
),
124123
all(
125124
target_env = "sgx",
@@ -130,17 +129,7 @@ cfg_if::cfg_if! {
130129
mod libunwind;
131130
use self::libunwind::trace as trace_imp;
132131
pub(crate) use self::libunwind::Frame as FrameImp;
133-
} else if #[cfg(
134-
all(
135-
unix,
136-
not(target_os = "emscripten"),
137-
feature = "unix-backtrace",
138-
)
139-
)] {
140-
mod unix_backtrace;
141-
use self::unix_backtrace::trace as trace_imp;
142-
pub(crate) use self::unix_backtrace::Frame as FrameImp;
143-
} else if #[cfg(all(windows, feature = "dbghelp", not(target_vendor = "uwp")))] {
132+
} else if #[cfg(all(windows, not(target_vendor = "uwp")))] {
144133
mod dbghelp;
145134
use self::dbghelp::trace as trace_imp;
146135
pub(crate) use self::dbghelp::Frame as FrameImp;

src/backtrace/unix_backtrace.rs

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/dbghelp.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ pub struct Init {
254254
/// Note that this function is **safe**, it internally has its own
255255
/// synchronization. Also note that it is safe to call this function multiple
256256
/// times recursively.
257-
#[cfg(all(windows, feature = "dbghelp"))]
258257
pub fn init() -> Result<Init, ()> {
259258
use core::sync::atomic::{AtomicUsize, Ordering::SeqCst};
260259

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ mod lock {
153153
}
154154
}
155155

156-
#[cfg(all(windows, feature = "dbghelp", not(target_vendor = "uwp")))]
156+
#[cfg(all(windows, not(target_vendor = "uwp")))]
157157
mod dbghelp;
158158
#[cfg(windows)]
159159
mod windows;

src/symbolize/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ pub fn clear_symbol_cache() {
456456
}
457457

458458
cfg_if::cfg_if! {
459-
if #[cfg(all(windows, target_env = "msvc", feature = "dbghelp", not(target_vendor = "uwp")))] {
459+
if #[cfg(all(windows, target_env = "msvc", not(target_vendor = "uwp")))] {
460460
mod dbghelp;
461461
use self::dbghelp::resolve as resolve_imp;
462462
use self::dbghelp::Symbol as SymbolImp;

tests/long_fn_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mod _234567890_234567890_234567890_234567890_234567890 {
1818
// Long function names must be truncated to (MAX_SYM_NAME - 1) characters.
1919
// Only run this test for msvc, since gnu prints "<no info>" for all frames.
2020
#[test]
21-
#[cfg(all(windows, feature = "dbghelp", target_env = "msvc"))]
21+
#[cfg(all(windows, target_env = "msvc"))]
2222
fn test_long_fn_name() {
2323
use _234567890_234567890_234567890_234567890_234567890::_234567890_234567890_234567890_234567890_234567890 as S;
2424

tests/skip_inner_frames.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ const ENABLED: bool = cfg!(all(
99
// Windows hasn't really been tested, and OSX doesn't support actually
1010
// finding an enclosing frame, so disable this
1111
target_os = "linux",
12-
// This is the only method currently that supports accurate enough
13-
// backtraces for this test to work.
14-
feature = "libunwind",
1512
// On ARM finding the enclosing function is simply returning the ip itself.
1613
not(target_arch = "arm"),
1714
));

tests/smoke.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ extern crate backtrace;
33
use backtrace::Frame;
44
use std::thread;
55

6-
static LIBUNWIND: bool = cfg!(all(unix, feature = "libunwind"));
7-
static UNIX_BACKTRACE: bool = cfg!(all(unix, feature = "unix-backtrace"));
86
static LIBBACKTRACE: bool = cfg!(feature = "libbacktrace") && !cfg!(target_os = "fuchsia");
9-
static DBGHELP: bool = cfg!(all(windows, feature = "dbghelp"));
10-
static MSVC: bool = cfg!(target_env = "msvc");
117
static GIMLI_SYMBOLIZE: bool = cfg!(all(feature = "gimli-symbolize", unix, target_os = "linux"));
128

139
#[test]
@@ -26,13 +22,6 @@ fn smoke_test_frames() {
2622
true
2723
});
2824

29-
if v.len() < 5 {
30-
assert!(!LIBUNWIND);
31-
assert!(!UNIX_BACKTRACE);
32-
assert!(!DBGHELP);
33-
return;
34-
}
35-
3625
// Various platforms have various bits of weirdness about their
3726
// backtraces. To find a good starting spot let's search through the
3827
// frames
@@ -128,12 +117,12 @@ fn smoke_test_frames() {
128117
// right now...
129118
//
130119
// This assertion can also fail for release builds, so skip it there
131-
if !DBGHELP && cfg!(debug_assertions) {
120+
if cfg!(debug_assertions) {
132121
assert!(sym - actual_fn_pointer < 1024);
133122
}
134123

135124
let mut resolved = 0;
136-
let can_resolve = LIBBACKTRACE || DBGHELP || GIMLI_SYMBOLIZE;
125+
let can_resolve = LIBBACKTRACE || GIMLI_SYMBOLIZE;
137126

138127
let mut name = None;
139128
let mut addr = None;
@@ -149,12 +138,11 @@ fn smoke_test_frames() {
149138

150139
// dbghelp doesn't always resolve symbols right now
151140
match resolved {
152-
0 => return assert!(!can_resolve || DBGHELP),
141+
0 => return assert!(!can_resolve),
153142
_ => {}
154143
}
155144

156-
// * windows dbghelp isn't great for GNU
157-
if can_resolve && !(DBGHELP && !MSVC) {
145+
if can_resolve {
158146
let name = name.expect("didn't find a name");
159147

160148
// in release mode names get weird as functions can get merged
@@ -173,7 +161,7 @@ fn smoke_test_frames() {
173161
addr.expect("didn't find a symbol");
174162
}
175163

176-
if (LIBBACKTRACE || (DBGHELP && MSVC)) && cfg!(debug_assertions) {
164+
if cfg!(debug_assertions) {
177165
let line = line.expect("didn't find a line number");
178166
let file = file.expect("didn't find a line number");
179167
if !expected_file.is_empty() {

0 commit comments

Comments
 (0)