Skip to content

Commit 18e1931

Browse files
Utilize cfg_attr instead of a build script.
This also updates serde to a more recent version (1.0).
1 parent 07ad200 commit 18e1931

File tree

5 files changed

+15
-83
lines changed

5 files changed

+15
-83
lines changed

Cargo.toml

+3-7
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ documentation = "http://alexcrichton.com/backtrace-rs"
1111
description = """
1212
A library to acquire a stack trace (backtrace) at runtime in a Rust program.
1313
"""
14-
build = "build.rs"
15-
1614
[dependencies]
1715
libc = "0.2"
1816
cfg-if = "0.1"
1917
rustc-demangle = "0.1.4"
2018

2119
# Optionally enable the ability to serialize a `Backtrace`
22-
serde = { version = "0.8", optional = true }
20+
serde = { version = "1.0", optional = true }
21+
serde_derive = { version = "1.0", optional = true }
2322
rustc-serialize = { version = "0.3", optional = true }
2423

2524
# Optionally demangle C++ frames' symbols in backtraces.
@@ -33,9 +32,6 @@ winapi = { version = "0.2.5", optional = true }
3332
[target.'cfg(all(unix, not(target_os = "emscripten"), not(target_os = "macos"), not(target_os = "ios")))'.dependencies]
3433
backtrace-sys = { path = "backtrace-sys", version = "0.1.3", optional = true }
3534

36-
[build-dependencies]
37-
serde_codegen = { version = "0.8", optional = true }
38-
3935
# Each feature controls the two phases of finding a backtrace: getting a
4036
# backtrace and then resolving instruction pointers to symbols. The default
4137
# feature enables all the necessary features for each platform this library
@@ -88,4 +84,4 @@ default = ["libunwind", "libbacktrace", "coresymbolication", "dladdr", "dbghelp"
8884
#
8985
# Various features used for enabling rustc-serialize or syntex codegen.
9086
serialize-rustc = ["rustc-serialize"]
91-
serialize-serde = ["serde", "serde_codegen"]
87+
serialize-serde = ["serde", "serde_derive"]

build.rs

-51
This file was deleted.

src/capture.rs

+6-21
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,13 @@ use std::path::{Path, PathBuf};
55

66
use {trace, resolve, SymbolName};
77

8-
// Ok so the `//~ HACK` directives here are, well, hacks. Right now we want to
9-
// compile on stable for serde support, but we also want to use
10-
// #[derive(Serialize, Deserialize)] macros *along* with the
11-
// `#[derive(RustcEncodable, RustcDecodable)]` macros. In theory both of these
12-
// can be behind a #[cfg_attr], but that unfortunately doesn't work for two
13-
// reasons:
14-
//
15-
// 1. rust-lang/rust#32957 - means the include! of this module doesn't expand
16-
// the RustcDecodable/RustcEncodable blocks.
17-
// 2. serde-rs/serde#148 - means that Serialize/Deserialize won't get expanded.
18-
//
19-
// We just hack around it by doing #[cfg_attr] manually essentially. Our build
20-
// script will just strip the `//~ HACKn` prefixes here if the corresponding
21-
// feature is enabled.
22-
238
/// Representation of an owned and self-contained backtrace.
249
///
2510
/// This structure can be used to capture a backtrace at various points in a
2611
/// program and later used to inspect what the backtrace was at that time.
2712
#[derive(Clone)]
28-
//~ HACK1 #[derive(RustcDecodable, RustcEncodable)]
29-
//~ HACK2 #[derive(Deserialize, Serialize)]
13+
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
14+
#[cfg_attr(feature = "serialize-serde", derive(Deserialize, Serialize))]
3015
pub struct Backtrace {
3116
frames: Vec<BacktraceFrame>,
3217
}
@@ -36,8 +21,8 @@ pub struct Backtrace {
3621
/// This type is returned as a list from `Backtrace::frames` and represents one
3722
/// stack frame in a captured backtrace.
3823
#[derive(Clone)]
39-
//~ HACK1 #[derive(RustcDecodable, RustcEncodable)]
40-
//~ HACK2 #[derive(Deserialize, Serialize)]
24+
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
25+
#[cfg_attr(feature = "serialize-serde", derive(Deserialize, Serialize))]
4126
pub struct BacktraceFrame {
4227
ip: usize,
4328
symbol_address: usize,
@@ -49,8 +34,8 @@ pub struct BacktraceFrame {
4934
/// This type is returned as a list from `BacktraceFrame::symbols` and
5035
/// represents the metadata for a symbol in a backtrace.
5136
#[derive(Clone)]
52-
//~ HACK1 #[derive(RustcDecodable, RustcEncodable)]
53-
//~ HACK2 #[derive(Deserialize, Serialize)]
37+
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
38+
#[cfg_attr(feature = "serialize-serde", derive(Deserialize, Serialize))]
5439
pub struct BacktraceSymbol {
5540
name: Option<Vec<u8>>,
5641
addr: Option<usize>,

src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ extern crate libc;
7777
#[cfg(feature = "serde")]
7878
extern crate serde;
7979

80+
#[cfg(feature = "serde_derive")]
81+
#[cfg_attr(feature = "serde_derive", macro_use)]
82+
extern crate serde_derive;
83+
8084
#[cfg(feature = "rustc-serialize")]
8185
extern crate rustc_serialize;
8286

@@ -100,9 +104,7 @@ pub use symbolize::{resolve, Symbol, SymbolName};
100104
mod symbolize;
101105

102106
pub use capture::{Backtrace, BacktraceFrame, BacktraceSymbol};
103-
mod capture {
104-
include!(concat!(env!("OUT_DIR"), "/capture.rs"));
105-
}
107+
mod capture;
106108

107109
#[allow(dead_code)]
108110
struct Bomb {

tests/smoke.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn is_serde() {
160160
extern crate serde;
161161

162162
fn is_serialize<T: serde::ser::Serialize>() {}
163-
fn is_deserialize<T: serde::de::Deserialize>() {}
163+
fn is_deserialize<T: serde::de::DeserializeOwned>() {}
164164

165165
is_serialize::<backtrace::Backtrace>();
166166
is_deserialize::<backtrace::Backtrace>();

0 commit comments

Comments
 (0)