Skip to content

Commit

Permalink
Fix no-default-features = true for non-nightly rust channels
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzgen committed Aug 9, 2018
1 parent 9719ac1 commit 89eaa2a
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions Cargo.toml
Expand Up @@ -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.
Expand All @@ -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
27 changes: 25 additions & 2 deletions README.md
Expand Up @@ -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!
Expand All @@ -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

Expand Down
File renamed without changes.
55 changes: 26 additions & 29 deletions src/lib.rs
Expand Up @@ -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::*;
Expand Down

0 comments on commit 89eaa2a

Please sign in to comment.