From fc7b0a7e510606a16ed5c8da3f6be3d85902683d Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 22 Mar 2018 13:43:06 -0700 Subject: [PATCH] Rename the `no_std` feature to `core`. See https://github.com/yurydelendik/wasmparser.rs/pull/49#issuecomment-375436225 for more details. --- README.rst | 22 +++++++++++----------- cranelift/test-no_std.sh | 4 ++-- lib/cretonne/Cargo.toml | 4 ++-- lib/cretonne/src/dbg.rs | 30 +++++++++++++++--------------- lib/cretonne/src/lib.rs | 8 ++++---- lib/cretonne/src/timing.rs | 4 ++-- lib/cretonne/src/verifier/mod.rs | 4 ++-- lib/frontend/Cargo.toml | 2 +- lib/frontend/src/ssa.rs | 12 ++++++------ lib/native/Cargo.toml | 2 +- lib/wasm/Cargo.toml | 2 +- lib/wasm/src/lib.rs | 2 +- 12 files changed, 48 insertions(+), 48 deletions(-) diff --git a/README.rst b/README.rst index 51ee362d10..8368aed68f 100644 --- a/README.rst +++ b/README.rst @@ -62,14 +62,14 @@ Building with `no_std` 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. +default, and enable the `core` feature. For example, to build `cretonne`: .. code-block:: sh cd lib/cretonne - cargo build --no-default-features --features no_std + cargo build --no-default-features --features core Or, when using `cretonne` as a dependency (in Cargo.toml): @@ -78,23 +78,23 @@ Or, when using `cretonne` as a dependency (in Cargo.toml): [dependency.cretonne] ... default-features = false - features = ["no_std"] + features = ["core"] -`no_std` is currently "best effort". We won't try to break it, and we'll -accept patches fixing problems, however we don't expect all developers to -build and test with `no_std` when submitting patches. Accordingly, the +`no_std` support is currently "best effort". We won't try to break it, and +we'll accept patches fixing problems, however we don't expect all developers to +build and test `no_std` when submitting patches. Accordingly, the `./test-all.sh` script does not test `no_std`. There is a separate `./test-no_std.sh` script that tests the `no_std` -feature in packages which support it. +support in packages which support it. It's important to note that cretonne still needs liballoc to compile. Thus, whatever environment is used must implement an allocator. -Also, to allow the use of HashMaps in `no_std` mode, an external crate -called `hashmap_core` is pulled in (only in `no_std` builds). This -is mostly the same as `std::collections::HashMap`, except that it doesn't -have DOS protection. Just something to think about. +Also, to allow the use of HashMaps with `no_std`, an external crate called +`hashmap_core` is pulled in (via the `core` feature). This is mostly the same +as `std::collections::HashMap`, except that it doesn't have DOS protection. +Just something to think about. Building the documentation -------------------------- diff --git a/cranelift/test-no_std.sh b/cranelift/test-no_std.sh index d3edbb921f..c2857ff756 100755 --- a/cranelift/test-no_std.sh +++ b/cranelift/test-no_std.sh @@ -21,8 +21,8 @@ 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 + cargo test --no-default-features --features core + cargo test --features core cd "$topdir" done diff --git a/lib/cretonne/Cargo.toml b/lib/cretonne/Cargo.toml index 89340e0a1a..01b7e2ab70 100644 --- a/lib/cretonne/Cargo.toml +++ b/lib/cretonne/Cargo.toml @@ -26,9 +26,9 @@ version = "0.1.1" optional = true [features] -# The "std" feature enables use of libstd. The "no_std" feature enables use +# The "std" feature enables use of libstd. The "core" 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"] +core = ["hashmap_core"] diff --git a/lib/cretonne/src/dbg.rs b/lib/cretonne/src/dbg.rs index 8f949f00e1..6c51bd23e5 100644 --- a/lib/cretonne/src/dbg.rs +++ b/lib/cretonne/src/dbg.rs @@ -8,23 +8,23 @@ /// /// The output will appear in files named `cretonne.dbg.*`, where the suffix is named after the /// thread doing the logging. -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::cell::RefCell; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::env; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::ffi::OsStr; use std::fmt; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::fs::File; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::io::{self, Write}; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::sync::atomic; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] use std::thread; -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] static STATE: atomic::AtomicIsize = atomic::ATOMIC_ISIZE_INIT; /// Is debug tracing enabled? @@ -33,7 +33,7 @@ static STATE: atomic::AtomicIsize = atomic::ATOMIC_ISIZE_INIT; /// other than `0`. /// /// This inline function turns into a constant `false` when debug assertions are disabled. -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] #[inline] pub fn enabled() -> bool { if cfg!(debug_assertions) { @@ -47,14 +47,14 @@ pub fn enabled() -> bool { } /// Does nothing -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] #[inline] pub fn enabled() -> bool { false } /// Initialize `STATE` from the environment variable. -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] fn initialize() -> bool { let enable = match env::var_os("CRETONNE_DBG") { Some(s) => s != OsStr::new("0"), @@ -70,7 +70,7 @@ fn initialize() -> bool { enable } -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] thread_local! { static WRITER : RefCell> = RefCell::new(open_file()); } @@ -78,7 +78,7 @@ thread_local! { /// Write a line with the given format arguments. /// /// This is for use by the `dbg!` macro. -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] pub fn writeln_with_format_args(args: fmt::Arguments) -> io::Result<()> { WRITER.with(|rc| { let mut w = rc.borrow_mut(); @@ -88,7 +88,7 @@ pub fn writeln_with_format_args(args: fmt::Arguments) -> io::Result<()> { } /// Open the tracing file for the current thread. -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] fn open_file() -> io::BufWriter { let curthread = thread::current(); let tmpstr; @@ -116,7 +116,7 @@ macro_rules! dbg { if $crate::dbg::enabled() { // Drop the error result so we don't get compiler errors for ignoring it. // What are you going to do, log the error? - #[cfg(not(feature = "no_std"))] + #[cfg(feature = "std")] $crate::dbg::writeln_with_format_args(format_args!($($arg)+)).ok(); } } diff --git a/lib/cretonne/src/lib.rs b/lib/cretonne/src/lib.rs index 29643d552f..8511951b50 100644 --- a/lib/cretonne/src/lib.rs +++ b/lib/cretonne/src/lib.rs @@ -4,13 +4,13 @@ trivial_numeric_casts, unused_extern_crates)] -// Turns on alloc feature if no_std +// Turns on no_std and alloc features if std is not available. #![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 std is not available. #[allow(unused_extern_crates)] -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] extern crate hashmap_core; #[cfg(not(feature = "std"))] #[macro_use] @@ -66,7 +66,7 @@ mod topo_order; mod unreachable_code; mod write; -/// This replaces `std` in builds with no_std. +/// This replaces `std` in builds with `core`. #[cfg(not(feature = "std"))] mod std { pub use core::*; diff --git a/lib/cretonne/src/timing.rs b/lib/cretonne/src/timing.rs index a70ed5fb21..bbe2fce07c 100644 --- a/lib/cretonne/src/timing.rs +++ b/lib/cretonne/src/timing.rs @@ -93,7 +93,7 @@ impl fmt::Display for Pass { /// This whole module can be gated on a `cfg` feature to provide a dummy implementation for /// performance-sensitive builds or restricted environments. The dummy implementation must provide /// `TimingToken` and `PassTimes` types and `take_current`, `add_to_current`, and `start_pass` funcs -#[cfg(not(feature = "no_std"))] +#[cfg(feature = "std")] mod details { use super::{Pass, NUM_PASSES, DESCRIPTIONS}; use std::cell::{Cell, RefCell}; @@ -216,7 +216,7 @@ mod details { } /// Dummy `debug` implementation -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] mod details { use super::Pass; /// Dummy `TimingToken` diff --git a/lib/cretonne/src/verifier/mod.rs b/lib/cretonne/src/verifier/mod.rs index d8c2cb6dc3..b2ad18c8e8 100644 --- a/lib/cretonne/src/verifier/mod.rs +++ b/lib/cretonne/src/verifier/mod.rs @@ -1125,9 +1125,9 @@ mod tests { Ok(_) => { panic!("Expected an error!") }, Err(Error { message, .. } ) => { if !message.contains($msg) { - #[cfg(not(feature = "no_std"))] + #[cfg(feature = "std")] panic!(format!("'{}' did not contain the substring '{}'", message, $msg)); - #[cfg(feature = "no_std")] + #[cfg(not(feature = "std"))] panic!("error message did not contain the expected substring"); } } diff --git a/lib/frontend/Cargo.toml b/lib/frontend/Cargo.toml index cdbabdda79..75822af7ce 100644 --- a/lib/frontend/Cargo.toml +++ b/lib/frontend/Cargo.toml @@ -17,4 +17,4 @@ cretonne = { path = "../cretonne", version = "0.3.4", default-features = false } [features] default = ["std"] std = ["cretonne/std"] -no_std = ["cretonne/no_std"] +core = ["cretonne/core"] diff --git a/lib/frontend/src/ssa.rs b/lib/frontend/src/ssa.rs index cf44371983..37e4fd8751 100644 --- a/lib/frontend/src/ssa.rs +++ b/lib/frontend/src/ssa.rs @@ -1026,9 +1026,9 @@ mod tests { match verify_function(&func, &flags) { Ok(()) => {} Err(err) => { - #[cfg(not(feature = "no_std"))] + #[cfg(feature = "std")] panic!(err.message); - #[cfg(feature = "no_std")] + #[cfg(not(feature = "std"))] panic!("function failed to verify"); } } @@ -1205,9 +1205,9 @@ mod tests { match verify_function(&func, &flags) { Ok(()) => {} Err(err) => { - #[cfg(not(feature = "no_std"))] + #[cfg(feature = "std")] panic!(err.message); - #[cfg(feature = "no_std")] + #[cfg(not(feature = "std"))] panic!("function failed to verify"); } } @@ -1256,9 +1256,9 @@ mod tests { match verify_function(&func, &flags) { Ok(()) => {} Err(err) => { - #[cfg(not(feature = "no_std"))] + #[cfg(feature = "std")] panic!(err.message); - #[cfg(feature = "no_std")] + #[cfg(not(feature = "std"))] panic!("function failed to verify"); } } diff --git a/lib/native/Cargo.toml b/lib/native/Cargo.toml index e89b0f02fe..817f12c73d 100644 --- a/lib/native/Cargo.toml +++ b/lib/native/Cargo.toml @@ -19,4 +19,4 @@ raw-cpuid = "3.0.0" [features] default = ["std"] std = ["cretonne/std"] -no_std = ["cretonne/no_std"] +core = ["cretonne/core"] diff --git a/lib/wasm/Cargo.toml b/lib/wasm/Cargo.toml index 3f35ee5c96..27177521ee 100644 --- a/lib/wasm/Cargo.toml +++ b/lib/wasm/Cargo.toml @@ -26,4 +26,4 @@ tempdir = "0.3.5" [features] default = ["std"] std = ["cretonne/std", "cretonne-frontend/std"] -no_std = ["hashmap_core", "cretonne/no_std", "cretonne-frontend/no_std"] +core = ["hashmap_core", "cretonne/core", "cretonne-frontend/core"] diff --git a/lib/wasm/src/lib.rs b/lib/wasm/src/lib.rs index a6492b5d66..d791a14846 100644 --- a/lib/wasm/src/lib.rs +++ b/lib/wasm/src/lib.rs @@ -21,7 +21,7 @@ extern crate alloc; #[allow(unused_extern_crates)] -#[cfg(feature = "no_std")] +#[cfg(not(feature = "std"))] extern crate hashmap_core; extern crate wasmparser;