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:
22
README.rst
22
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
|
||||
--------------------------
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::*;
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,4 +19,4 @@ raw-cpuid = "3.0.0"
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = ["cretonne/std"]
|
||||
no_std = ["cretonne/no_std"]
|
||||
core = ["cretonne/core"]
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user