Skip to content

Commit

Permalink
Merge rust-num#46
Browse files Browse the repository at this point in the history
46: Add a mandatory "std" feature r=cuviper a=cuviper

We don't actually support `no_std` yet, and probably won't until `alloc`
is stable.  We're just reserving this ability with the "std" feature
now, and compilation will fail without.

Co-authored-by: Josh Stone <[email protected]>
  • Loading branch information
bors[bot] and cuviper committed May 16, 2018
2 parents d449f32 + 23743e0 commit 7f59335
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,25 @@ default-features = false
[dependencies.num-traits]
version = "0.2.4"
default-features = false
features = ["std"]

[dependencies.rand]
optional = true
version = "0.4"
default-features = false

[dependencies.serde]
optional = true
version = "1.0"
default-features = false
features = ["std"]

[dev-dependencies]
serde_test = "1.0"
[dev-dependencies.serde_test]
version = "1.0"

[dev-dependencies.rand]
version = "0.4"

[features]
default = []
default = ["std"]
i128 = ["num-integer/i128", "num-traits/i128"]
std = ["num-integer/std", "num-traits/std"]
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ extern crate num_bigint;

## Features

The `std` crate feature is mandatory and enabled by default. If you depend on
`num-bigint` with `default-features = false`, you must manually enable the
`std` feature yourself. In the future, we hope to support `#![no_std]` with
the `alloc` crate when `std` is not enabled.

Implementations for `i128` and `u128` are only available with Rust 1.26 and
later. The build script automatically detects this, but you can make it
mandatory by enabling the `i128` crate feature.
Expand Down
30 changes: 13 additions & 17 deletions ci/test_full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@ set -ex

echo Testing num-bigint on rustc ${TRAVIS_RUST_VERSION}

FEATURES="rand serde"
if [[ "$TRAVIS_RUST_VERSION" =~ ^(nightly|beta|stable)$ ]]; then
FEATURES="$FEATURES i128"
fi

# num-bigint should build and test everywhere.
cargo build --verbose
cargo test --verbose

# It should build with minimal features too.
cargo build --no-default-features
cargo test --no-default-features
cargo build --no-default-features --features="std"
cargo test --no-default-features --features="std"

# Each isolated feature should also work everywhere.
for feature in rand serde; do
cargo build --verbose --no-default-features --features="$feature"
cargo test --verbose --no-default-features --features="$feature"
for feature in $FEATURES; do
cargo build --verbose --no-default-features --features="std $feature"
cargo test --verbose --no-default-features --features="std $feature"
done

# test `i128` and all features together
if [[ "$TRAVIS_RUST_VERSION" =~ ^(nightly|beta|stable)$ ]]; then
cargo build --verbose --features=i128
cargo test --verbose --features=i128

cargo build --all-features
cargo test --all-features
else
# all except `i128`
cargo build --features="rand serde"
cargo test --features="rand serde"
fi
# test all supported features together
cargo build --features="std $FEATURES"
cargo test --features="std $FEATURES"
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@
//!
//! The `num-bigint` crate is tested for rustc 1.15 and greater.

#![doc(html_root_url = "https://docs.rs/num-bigint/0.1")]
#![doc(html_root_url = "https://docs.rs/num-bigint/0.2")]

// We don't actually support `no_std` yet, and probably won't until `alloc` is stable. We're just
// reserving this ability with the "std" feature now, and compilation will fail without.
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(any(feature = "rand", test))]
extern crate rand;
#[cfg(feature = "rustc-serialize")]
extern crate rustc_serialize;
#[cfg(feature = "serde")]
extern crate serde;

Expand Down

0 comments on commit 7f59335

Please sign in to comment.