Add an explicit std feature so that features are purely additive.

This commit is contained in:
Dan Gohman
2018-02-13 17:48:04 -08:00
parent 61db54c447
commit e37f45667f
10 changed files with 41 additions and 27 deletions

View File

@@ -60,18 +60,20 @@ installed.
Building with `no_std`
----------------------
To build cretonne without libstd, enable the `no_std` feature on `lib/cretonne`,
`lib/frontend`, `lib/native`, and `lib/wasm`.
To build cretonne without libstd, disable the `std` feature on `lib/cretonne`,
`lib/frontend`, `lib/native`, and `lib/wasm`, which is otherwise enabled by
default, and enable the `no_std` feature.
For example, to build `cretonne`:
cd lib/cretonne
cargo build --features no_std
cargo build --no-default-features --features no_std
Or, when using `cretonne` as a dependency (in Cargo.toml):
[dependency.cretonne]
path = "..."
...
default-features = false
features = ["no_std"]
`no_std` is currently "best effort". We won't try to break it, and we'll

View File

@@ -21,6 +21,7 @@ for LIB in $LIBS
do
banner "Rust unit tests in $LIB"
cd "lib/$LIB"
cargo test --no-default-features --features no_std
cargo test --features no_std
cd "$topdir"
done

View File

@@ -17,14 +17,19 @@ name = "cretonne"
# Please don't add any unless they are essential to the task of creating binary
# machine code. Integration tests that need external dependencies can be
# accomodated in `tests`.
[dependencies.hashmap_core]
version = "0.1.1"
optional = true
[dependencies.error_core]
version = "0.1.0"
optional = true
[features]
# Currently, the only feature is the `no_std` feature.
# Enabling this disables use of `stdlib`.
no_std = ["hashmap_core", "error_core"]
# The "std" feature enables use of libstd. The "no_std" feature enables use
# of some minimal std-like replacement libraries. At least one of these two
# features to be enabled.
default = ["std"]
std = []
no_std = ["hashmap_core", "error_core"]

View File

@@ -1,16 +1,16 @@
//! Cretonne code generation library.
#![cfg_attr(feature = "no_std", no_std)]
#![deny(missing_docs)]
// Turns on alloc feature if no_std
#![cfg_attr(feature = "no_std", feature(alloc))]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
// Include the `hashmap_core` crate if no_std
#[cfg(feature = "no_std")]
extern crate hashmap_core;
#[cfg(feature = "no_std")]
extern crate error_core;
#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;
@@ -60,7 +60,7 @@ mod unreachable_code;
mod write;
/// This replaces `std` in builds with no_std.
#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
mod std {
pub use core::*;
pub use alloc::{boxed, vec, string};

View File

@@ -12,7 +12,9 @@ readme = "README.md"
name = "cton_frontend"
[dependencies]
cretonne = { path = "../cretonne", version = "0.1.0" }
cretonne = { path = "../cretonne", version = "0.1.0", default-features = false }
[features]
default = ["std"]
std = ["cretonne/std"]
no_std = ["cretonne/no_std"]

View File

@@ -142,14 +142,14 @@
//! }
//! ```
#![cfg_attr(feature = "no_std", no_std)]
#![deny(missing_docs)]
#![cfg_attr(feature = "no_std", feature(alloc))]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
extern crate cretonne;
#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
extern crate alloc;
pub use frontend::{ILBuilder, FunctionBuilder};
@@ -157,7 +157,7 @@ pub use frontend::{ILBuilder, FunctionBuilder};
mod frontend;
mod ssa;
#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
mod std {
pub use alloc::vec;
pub use core::*;

View File

@@ -11,10 +11,12 @@ readme = "README.md"
name = "cton_native"
[dependencies]
cretonne = { path = "../cretonne", version = "0.1.0" }
cretonne = { path = "../cretonne", version = "0.1.0", default-features = false }
[target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies]
raw-cpuid = "3.0.0"
[features]
default = ["std"]
std = ["cretonne/std"]
no_std = ["cretonne/no_std"]

View File

@@ -1,8 +1,9 @@
//! Performs autodetection of the host for the purposes of running
//! Cretonne to generate code to run on the same machine.
#![cfg_attr(feature = "no_std", no_std)]
#![deny(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
extern crate cretonne;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]

View File

@@ -12,12 +12,13 @@ name = "cton_wasm"
[dependencies]
wasmparser = "0.14.1"
cretonne = { path = "../cretonne", version = "0.1.0" }
cretonne-frontend = { path = "../frontend", version = "0.1.0" }
cretonne = { path = "../cretonne", version = "0.1.0", default_features = false }
cretonne-frontend = { path = "../frontend", version = "0.1.0", default_features = false }
[dependencies.hashmap_core]
version = "0.1.1"
optional = true
[dependencies.error_core]
version = "0.1.0"
optional = true
@@ -26,6 +27,6 @@ optional = true
tempdir = "0.3.5"
[features]
# Currently, the only feature is the `no_std` feature.
# Enabling this disables use of `stdlib`.
no_std = ["hashmap_core", "error_core", "cretonne/no_std", "cretonne-frontend/no_std"]
default = ["std"]
std = ["cretonne/std", "cretonne-frontend/std"]
no_std = ["hashmap_core", "error_core", "cretonne/no_std", "cretonne-frontend/no_std"]

View File

@@ -9,12 +9,12 @@
//!
//! The main function of this module is [`translate_module`](fn.translate_module.html).
#![cfg_attr(feature = "no_std", no_std)]
#![deny(missing_docs)]
#![cfg_attr(feature = "no_std", feature(alloc))]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;
@@ -42,7 +42,7 @@ pub use environ::{FuncEnvironment, ModuleEnvironment, DummyEnvironment, GlobalVa
pub use translation_utils::{FunctionIndex, GlobalIndex, TableIndex, MemoryIndex, SignatureIndex,
Global, GlobalInit, Table, Memory};
#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
mod std {
pub use alloc::vec;
pub use alloc::string;