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` Building with `no_std`
---------------------- ----------------------
To build cretonne without libstd, enable the `no_std` feature on `lib/cretonne`, To build cretonne without libstd, disable the `std` feature on `lib/cretonne`,
`lib/frontend`, `lib/native`, and `lib/wasm`. `lib/frontend`, `lib/native`, and `lib/wasm`, which is otherwise enabled by
default, and enable the `no_std` feature.
For example, to build `cretonne`: For example, to build `cretonne`:
cd lib/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): Or, when using `cretonne` as a dependency (in Cargo.toml):
[dependency.cretonne] [dependency.cretonne]
path = "..." ...
default-features = false
features = ["no_std"] features = ["no_std"]
`no_std` is currently "best effort". We won't try to break it, and we'll `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 do
banner "Rust unit tests in $LIB" banner "Rust unit tests in $LIB"
cd "lib/$LIB" cd "lib/$LIB"
cargo test --no-default-features --features no_std
cargo test --features no_std cargo test --features no_std
cd "$topdir" cd "$topdir"
done done

View File

@@ -17,14 +17,19 @@ name = "cretonne"
# Please don't add any unless they are essential to the task of creating binary # 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 # machine code. Integration tests that need external dependencies can be
# accomodated in `tests`. # accomodated in `tests`.
[dependencies.hashmap_core] [dependencies.hashmap_core]
version = "0.1.1" version = "0.1.1"
optional = true optional = true
[dependencies.error_core] [dependencies.error_core]
version = "0.1.0" version = "0.1.0"
optional = true optional = true
[features] [features]
# Currently, the only feature is the `no_std` feature. # The "std" feature enables use of libstd. The "no_std" feature enables use
# Enabling this disables use of `stdlib`. # 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"] no_std = ["hashmap_core", "error_core"]

View File

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

View File

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

View File

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

View File

@@ -11,10 +11,12 @@ readme = "README.md"
name = "cton_native" name = "cton_native"
[dependencies] [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] [target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies]
raw-cpuid = "3.0.0" raw-cpuid = "3.0.0"
[features] [features]
default = ["std"]
std = ["cretonne/std"]
no_std = ["cretonne/no_std"] no_std = ["cretonne/no_std"]

View File

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

View File

@@ -12,12 +12,13 @@ name = "cton_wasm"
[dependencies] [dependencies]
wasmparser = "0.14.1" wasmparser = "0.14.1"
cretonne = { path = "../cretonne", version = "0.1.0" } cretonne = { path = "../cretonne", version = "0.1.0", default_features = false }
cretonne-frontend = { path = "../frontend", version = "0.1.0" } cretonne-frontend = { path = "../frontend", version = "0.1.0", default_features = false }
[dependencies.hashmap_core] [dependencies.hashmap_core]
version = "0.1.1" version = "0.1.1"
optional = true optional = true
[dependencies.error_core] [dependencies.error_core]
version = "0.1.0" version = "0.1.0"
optional = true optional = true
@@ -26,6 +27,6 @@ optional = true
tempdir = "0.3.5" tempdir = "0.3.5"
[features] [features]
# Currently, the only feature is the `no_std` feature. default = ["std"]
# Enabling this disables use of `stdlib`. std = ["cretonne/std", "cretonne-frontend/std"]
no_std = ["hashmap_core", "error_core", "cretonne/no_std", "cretonne-frontend/no_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). //! The main function of this module is [`translate_module`](fn.translate_module.html).
#![cfg_attr(feature = "no_std", no_std)]
#![deny(missing_docs)] #![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] #[macro_use]
extern crate alloc; extern crate alloc;
@@ -42,7 +42,7 @@ pub use environ::{FuncEnvironment, ModuleEnvironment, DummyEnvironment, GlobalVa
pub use translation_utils::{FunctionIndex, GlobalIndex, TableIndex, MemoryIndex, SignatureIndex, pub use translation_utils::{FunctionIndex, GlobalIndex, TableIndex, MemoryIndex, SignatureIndex,
Global, GlobalInit, Table, Memory}; Global, GlobalInit, Table, Memory};
#[cfg(feature = "no_std")] #[cfg(not(feature = "std"))]
mod std { mod std {
pub use alloc::vec; pub use alloc::vec;
pub use alloc::string; pub use alloc::string;