From 03147a503b0ef0ea873467682ae20b1c6e429ef0 Mon Sep 17 00:00:00 2001 From: Azriel Hoh Date: Wed, 12 Dec 2018 13:32:35 +1300 Subject: [PATCH 1/6] Include Rust 1.25.0 compatible implementations. Issue #135 --- src/symbolize/dbghelp.rs | 4 ++++ src/types.rs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/symbolize/dbghelp.rs b/src/symbolize/dbghelp.rs index e6324bbb7..fbb043db3 100644 --- a/src/symbolize/dbghelp.rs +++ b/src/symbolize/dbghelp.rs @@ -10,8 +10,12 @@ #![allow(bad_style)] +#[cfg(feature = "std")] +use std::char; + use core::mem; use core::slice; +#[cfg(not(feature = "std"))] use core::char; use winapi::ctypes::*; diff --git a/src/types.rs b/src/types.rs index eefcf426e..a8a6e3306 100644 --- a/src/types.rs +++ b/src/types.rs @@ -31,8 +31,8 @@ impl<'a> BytesOrWideString<'a> { use self::BytesOrWideString::*; match self { - Bytes(slice) => String::from_utf8_lossy(slice), - Wide(wide) => Cow::Owned(String::from_utf16_lossy(wide)), + &Bytes(slice) => String::from_utf8_lossy(slice), + &Wide(wide) => Cow::Owned(String::from_utf16_lossy(wide)), } } From e50b0dc9f9ba0b7e75677e1ac81fa9b260251aa6 Mon Sep 17 00:00:00 2001 From: Azriel Hoh Date: Wed, 12 Dec 2018 22:06:55 +1300 Subject: [PATCH 2/6] Added Rust 1.25.0 to CI configuration. See --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7e0080261..405e5775a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,6 +43,10 @@ matrix: - rust: nightly script: *test_all + # Test everything on Rust 1.25.0 for backward compatibility + - rust: 1.25.0 + script: *test_all + # Upload docs on nightly - rust: nightly script: From 4c8bdb147009c1459ef029c75590b70e60e8d3ea Mon Sep 17 00:00:00 2001 From: Azriel Hoh Date: Thu, 13 Dec 2018 14:32:58 +1300 Subject: [PATCH 3/6] Indicate `no_std` support is only available on Rust >= 1.30.0. Issue #135 --- .travis.yml | 20 ++++++++++++++++++-- Cargo.toml | 3 +++ build.rs | 11 +++++++++++ src/types.rs | 4 +++- 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 build.rs diff --git a/.travis.yml b/.travis.yml index 405e5775a..38ed19cba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,9 +43,25 @@ matrix: - rust: nightly script: *test_all - # Test everything on Rust 1.25.0 for backward compatibility + # Test features with std on Rust 1.25.0 for backward compatibility - rust: 1.25.0 - script: *test_all + script: + - cargo build --manifest-path backtrace-sys/Cargo.toml + - cargo build + - cargo test + - cargo test --no-default-features --features 'libunwind std' + - cargo test --no-default-features --features 'libunwind dladdr std' + - cargo test --no-default-features --features 'libunwind libbacktrace std' + - cargo test --no-default-features --features 'unix-backtrace std' + - cargo test --no-default-features --features 'unix-backtrace dladdr std' + - cargo test --no-default-features --features 'unix-backtrace libbacktrace std' + - cargo test --no-default-features --features 'serialize-serde std' + - cargo test --no-default-features --features 'serialize-rustc std' + - cargo test --no-default-features --features 'serialize-rustc serialize-serde std' + - cargo test --no-default-features --features 'cpp_demangle std' + - cargo test --no-default-features --features 'gimli-symbolize std' + - cd ./cpp_smoke_test && cargo test && cd .. + - cargo clean && cargo build # Upload docs on nightly - rust: nightly diff --git a/Cargo.toml b/Cargo.toml index 2f5a9907b..b0c3427d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,9 @@ winapi = { version = "0.3.3", features = ["dbghelp", "processthreadsapi", "winnt [target.'cfg(all(unix, not(target_os = "fuchsia"), not(target_os = "emscripten"), not(target_os = "macos"), not(target_os = "ios")))'.dependencies] backtrace-sys = { path = "backtrace-sys", version = "0.1.17", optional = true } +[build-dependencies] +autocfg = "0.1" + # Each feature controls the two phases of finding a backtrace: getting a # backtrace and then resolving instruction pointers to symbols. The default # feature enables all the necessary features for each platform this library diff --git a/build.rs b/build.rs new file mode 100644 index 000000000..14c968cd1 --- /dev/null +++ b/build.rs @@ -0,0 +1,11 @@ +extern crate autocfg; + +fn main() { + let ac = autocfg::new(); + + // ffi types moved from `std` to `core` in Rust 1.30, so we need to adjust imports based on + // this. + // + // + ac.emit_rustc_version(1, 30); +} \ No newline at end of file diff --git a/src/types.rs b/src/types.rs index a8a6e3306..236931466 100644 --- a/src/types.rs +++ b/src/types.rs @@ -7,8 +7,10 @@ cfg_if! { use std::fmt; use std::path::PathBuf; use std::prelude::v1::*; - } else { + } else if #[cfg(rustc_1_30)] { pub use core::ffi::c_void; + } else { + compile_error!("`backtrace` requires Rust >=1.30.0 to support `no_std`."); } } From b17b757ac0b9f660453239a684487d11f7412519 Mon Sep 17 00:00:00 2001 From: Azriel Hoh Date: Thu, 13 Dec 2018 15:55:01 +1300 Subject: [PATCH 4/6] Do not include `"gimli-symbolize"` support on Rust 1.25.0. --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 38ed19cba..663c9e664 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,6 +44,11 @@ matrix: script: *test_all # Test features with std on Rust 1.25.0 for backward compatibility + # + # Not supported: + # + # * no_std + # * gimli-symbolize feature - rust: 1.25.0 script: - cargo build --manifest-path backtrace-sys/Cargo.toml @@ -59,7 +64,6 @@ matrix: - cargo test --no-default-features --features 'serialize-rustc std' - cargo test --no-default-features --features 'serialize-rustc serialize-serde std' - cargo test --no-default-features --features 'cpp_demangle std' - - cargo test --no-default-features --features 'gimli-symbolize std' - cd ./cpp_smoke_test && cargo test && cd .. - cargo clean && cargo build From cf89c5db5db6dd773104143158ec2c9904d0ec01 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 13 Dec 2018 07:46:13 -0800 Subject: [PATCH 5/6] Trim down tests for 1.25.0 No need to test exhaustiveness, we can rely on that through bug reports! --- .travis.yml | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 663c9e664..22e77326c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,29 +43,9 @@ matrix: - rust: nightly script: *test_all - # Test features with std on Rust 1.25.0 for backward compatibility - # - # Not supported: - # - # * no_std - # * gimli-symbolize feature + # Make sure the default crate builds with 1.25.0 - rust: 1.25.0 - script: - - cargo build --manifest-path backtrace-sys/Cargo.toml - - cargo build - - cargo test - - cargo test --no-default-features --features 'libunwind std' - - cargo test --no-default-features --features 'libunwind dladdr std' - - cargo test --no-default-features --features 'libunwind libbacktrace std' - - cargo test --no-default-features --features 'unix-backtrace std' - - cargo test --no-default-features --features 'unix-backtrace dladdr std' - - cargo test --no-default-features --features 'unix-backtrace libbacktrace std' - - cargo test --no-default-features --features 'serialize-serde std' - - cargo test --no-default-features --features 'serialize-rustc std' - - cargo test --no-default-features --features 'serialize-rustc serialize-serde std' - - cargo test --no-default-features --features 'cpp_demangle std' - - cd ./cpp_smoke_test && cargo test && cd .. - - cargo clean && cargo build + script: cargo test # Upload docs on nightly - rust: nightly From 2f27cffa0a6aca305c8080d0a5aaac27d3b0c0cc Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 13 Dec 2018 07:52:40 -0800 Subject: [PATCH 6/6] Comment what's going on in dbghelp --- build.rs | 4 +++- src/symbolize/dbghelp.rs | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/build.rs b/build.rs index 14c968cd1..a648ea1ce 100644 --- a/build.rs +++ b/build.rs @@ -8,4 +8,6 @@ fn main() { // // ac.emit_rustc_version(1, 30); -} \ No newline at end of file + + println!("cargo:rerun-if-changed=build.rs"); +} diff --git a/src/symbolize/dbghelp.rs b/src/symbolize/dbghelp.rs index fbb043db3..abc89868a 100644 --- a/src/symbolize/dbghelp.rs +++ b/src/symbolize/dbghelp.rs @@ -10,13 +10,18 @@ #![allow(bad_style)] +// This is a hack for compatibility with rustc 1.25.0. The no_std mode of this +// crate is not supported pre-1.30.0, but in std mode the `char` module here +// moved in rustc 1.26.0 (ish). As a result, in std mode we use `std::char` to +// retain compatibility with rustc 1.25.0, but in `no_std` mode (which is +// 1.30.0+ already) we use `core::char`. #[cfg(feature = "std")] use std::char; +#[cfg(not(feature = "std"))] +use core::char; use core::mem; use core::slice; -#[cfg(not(feature = "std"))] -use core::char; use winapi::ctypes::*; use winapi::shared::basetsd::*;