Rename the no_std feature to core.

See
https://github.com/yurydelendik/wasmparser.rs/pull/49#issuecomment-375436225
for more details.
This commit is contained in:
Dan Gohman
2018-03-22 13:43:06 -07:00
parent aaf0def241
commit fc7b0a7e51
12 changed files with 48 additions and 48 deletions

View File

@@ -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"]

View File

@@ -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<io::BufWriter<File>> = 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<File> {
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();
}
}

View File

@@ -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::*;

View File

@@ -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`

View File

@@ -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");
}
}