diff --git a/.travis.yml b/.travis.yml index 0d1a660..9b3c1ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,8 @@ matrix: env: JOB=fuzz script: cargo build --features fuzz - rust: nightly - env: JOB=nostd - script: cargo build --no-default-features + env: JOB=test-nostd + script: cargo test --no-default-features --features alloc - rust: stable env: JOB=doc script: cargo doc diff --git a/CHANGELOG.md b/CHANGELOG.md index 5400eb2..baa3087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,14 +28,27 @@ Released YYYY/MM/DD -------------------------------------------------------------------------------- +# 0.2.11 + +Released 2018/08/09 + +## Fixed + +* Fixed builds using `no-default-features = true` to not accidentally enable + `no_std` mode, which requires nightly rust, and break builds on non-nightly + channels. Enabling the `no_std` mode now requires disabling the `std` feature + *and* enabling the `alloc` feature. + +-------------------------------------------------------------------------------- + # 0.2.10 Released 2018/08/08 ## Added -* Added support for `nostd`! This currently requires nightly Rust's `alloc` - feature to get access to `BTreeMap`. Enable `nostd` support by building +* Added support for `no_std`! This currently requires nightly Rust's `alloc` + feature to get access to `BTreeMap`. Enable `no_std` support by building without the on-by-default `std` feature. [#148][] ## Fixed diff --git a/Cargo.toml b/Cargo.toml index 4a25a98..94fe07a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,26 +30,28 @@ required-features = ["afl"] [build-dependencies] glob = "0.2.11" +[dependencies] +cfg-if = "0.1.4" + [dependencies.afl] optional = true version = "0.4" -[dependencies.clap] -optional = true -version = "2.27.1" - [dev-dependencies] +clap = "2.27.1" diff = "0.1.10" [features] # Default features. -default = ["cppfilt", "std"] +default = ["std"] -# Build using the `std` library. Disabling this feature enables `nostd` support. +# Build using the `std` library. Disabling this and enabling the `alloc` feature +# enables `no_std` support. std = [] -# Build the `c++filt` clone executable. -cppfilt = ["clap"] +# Use collections from the `alloc` crate rather than from `std`. Combined with +# disabling `std`, this enables `no_std` support. +alloc = [] # Enable copious amounts of logging. This is for internal use only, and is only # useful for hacking on `cpp_demangle` itself. @@ -62,10 +64,12 @@ run_libiberty_tests = [] # Enable fuzzing support. This is for internal use only. fuzz = ["afl"] -# DEPRECATED. Don't use this, it does nothing. +# DEPRECATED. Don't use these features, they do nothing. # # TODO: remove on next breaking version bump. nightly = [] +cppfilt = [] + [profile.release] debug = true diff --git a/README.md b/README.md index bae66bc..bc19749 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Add `cpp_demangle` to your crate's `Cargo.toml`: ```toml [dependencies] -cpp_demangle = "0.2.9" +cpp_demangle = "0.2.11" ``` And then demangle some C++ symbols! @@ -53,13 +53,36 @@ let demangled = sym.to_string(); assert_eq!(demangled, "space::foo(int, bool, char)"); ``` +### `no_std` Support + +`cpp_demangle` may be configured for working in `no_std` environments that still +have allocation support via the `alloc` crate. This is nightly rust only, at the +moment, since the `alloc` crate's collections aren't stabilized. + +Disable the "std" feature, and enable the "alloc" feature: + +```tom +[dependencies] +cpp_demangle = { + version = "0.2.11", + default-features = false, + features = ["alloc"] +} +``` + ## Documentation [Documentation on docs.rs](https://docs.rs/cpp_demangle) Example programs: -* [A `c++filt` clone](./src/bin/cppfilt.rs) +* [A `c++filt` clone.](./src/bin/cppfilt.rs) + + Install it locally with this command: + + ``` + cargo install cpp_demangle --example cppfilt + ``` ## Implementation Status diff --git a/src/bin/cppfilt.rs b/examples/cppfilt.rs similarity index 100% rename from src/bin/cppfilt.rs rename to examples/cppfilt.rs diff --git a/src/lib.rs b/src/lib.rs index 6d3b7ac..acce161 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,41 +30,38 @@ #![deny(missing_docs)] #![deny(missing_debug_implementations)] #![deny(unsafe_code)] + // Clippy stuff. #![allow(unknown_lints)] #![allow(inline_always)] -#![no_std] -#![cfg_attr(not(feature = "std"), feature(alloc))] - -#[cfg(feature = "std")] -#[macro_use] -extern crate std; - -#[cfg(not(feature = "std"))] -#[macro_use] -extern crate core as std; +#![cfg_attr(all(not(feature = "std"), feature = "alloc"), no_std)] +#![cfg_attr(all(not(feature = "std"), feature = "alloc"), feature(alloc))] -#[cfg(not(feature = "std"))] #[macro_use] -extern crate alloc; - -#[cfg(feature = "std")] -mod imports { - pub use std::boxed; - pub use std::vec; - pub use std::string; - pub use std::borrow; - pub use std::collections::btree_map; -} - -#[cfg(not(feature = "std"))] -mod imports { - pub use alloc::boxed; - pub use alloc::vec; - pub use alloc::string; - pub use alloc::borrow; - pub use alloc::collections::btree_map; +extern crate cfg_if; + +cfg_if! { + if #[cfg(feature = "std")] { + mod imports { + pub use std::boxed; + pub use std::vec; + pub use std::string; + pub use std::borrow; + pub use std::collections::btree_map; + } + } else if #[cfg(feature = "alloc")] { + extern crate core as std; + #[macro_use] + extern crate alloc; + mod imports { + pub use alloc::boxed; + pub use alloc::vec; + pub use alloc::string; + pub use alloc::borrow; + pub use alloc::collections::btree_map; + } + } } use imports::*;