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`,
|
To build cretonne without libstd, disable the `std` feature on `lib/cretonne`,
|
||||||
`lib/frontend`, `lib/native`, and `lib/wasm`, which is otherwise enabled by
|
`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`:
|
For example, to build `cretonne`:
|
||||||
|
|
||||||
.. code-block:: sh
|
.. code-block:: sh
|
||||||
|
|
||||||
cd lib/cretonne
|
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):
|
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]
|
[dependency.cretonne]
|
||||||
...
|
...
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["no_std"]
|
features = ["core"]
|
||||||
|
|
||||||
`no_std` is currently "best effort". We won't try to break it, and we'll
|
`no_std` support is currently "best effort". We won't try to break it, and
|
||||||
accept patches fixing problems, however we don't expect all developers to
|
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
|
build and test `no_std` when submitting patches. Accordingly, the
|
||||||
`./test-all.sh` script does not test `no_std`.
|
`./test-all.sh` script does not test `no_std`.
|
||||||
|
|
||||||
There is a separate `./test-no_std.sh` script that tests the `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.
|
It's important to note that cretonne still needs liballoc to compile.
|
||||||
Thus, whatever environment is used must implement an allocator.
|
Thus, whatever environment is used must implement an allocator.
|
||||||
|
|
||||||
Also, to allow the use of HashMaps in `no_std` mode, an external crate
|
Also, to allow the use of HashMaps with `no_std`, an external crate called
|
||||||
called `hashmap_core` is pulled in (only in `no_std` builds). This
|
`hashmap_core` is pulled in (via the `core` feature). This is mostly the same
|
||||||
is mostly the same as `std::collections::HashMap`, except that it doesn't
|
as `std::collections::HashMap`, except that it doesn't have DOS protection.
|
||||||
have DOS protection. Just something to think about.
|
Just something to think about.
|
||||||
|
|
||||||
Building the documentation
|
Building the documentation
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ 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 --no-default-features --features core
|
||||||
cargo test --features no_std
|
cargo test --features core
|
||||||
cd "$topdir"
|
cd "$topdir"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ version = "0.1.1"
|
|||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[features]
|
[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
|
# of some minimal std-like replacement libraries. At least one of these two
|
||||||
# features to be enabled.
|
# features to be enabled.
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
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
|
/// The output will appear in files named `cretonne.dbg.*`, where the suffix is named after the
|
||||||
/// thread doing the logging.
|
/// thread doing the logging.
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
use std::env;
|
use std::env;
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
use std::sync::atomic;
|
use std::sync::atomic;
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
static STATE: atomic::AtomicIsize = atomic::ATOMIC_ISIZE_INIT;
|
static STATE: atomic::AtomicIsize = atomic::ATOMIC_ISIZE_INIT;
|
||||||
|
|
||||||
/// Is debug tracing enabled?
|
/// Is debug tracing enabled?
|
||||||
@@ -33,7 +33,7 @@ static STATE: atomic::AtomicIsize = atomic::ATOMIC_ISIZE_INIT;
|
|||||||
/// other than `0`.
|
/// other than `0`.
|
||||||
///
|
///
|
||||||
/// This inline function turns into a constant `false` when debug assertions are disabled.
|
/// This inline function turns into a constant `false` when debug assertions are disabled.
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn enabled() -> bool {
|
pub fn enabled() -> bool {
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
@@ -47,14 +47,14 @@ pub fn enabled() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Does nothing
|
/// Does nothing
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(not(feature = "std"))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn enabled() -> bool {
|
pub fn enabled() -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialize `STATE` from the environment variable.
|
/// Initialize `STATE` from the environment variable.
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
fn initialize() -> bool {
|
fn initialize() -> bool {
|
||||||
let enable = match env::var_os("CRETONNE_DBG") {
|
let enable = match env::var_os("CRETONNE_DBG") {
|
||||||
Some(s) => s != OsStr::new("0"),
|
Some(s) => s != OsStr::new("0"),
|
||||||
@@ -70,7 +70,7 @@ fn initialize() -> bool {
|
|||||||
enable
|
enable
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
thread_local! {
|
thread_local! {
|
||||||
static WRITER : RefCell<io::BufWriter<File>> = RefCell::new(open_file());
|
static WRITER : RefCell<io::BufWriter<File>> = RefCell::new(open_file());
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ thread_local! {
|
|||||||
/// Write a line with the given format arguments.
|
/// Write a line with the given format arguments.
|
||||||
///
|
///
|
||||||
/// This is for use by the `dbg!` macro.
|
/// 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<()> {
|
pub fn writeln_with_format_args(args: fmt::Arguments) -> io::Result<()> {
|
||||||
WRITER.with(|rc| {
|
WRITER.with(|rc| {
|
||||||
let mut w = rc.borrow_mut();
|
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.
|
/// Open the tracing file for the current thread.
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
fn open_file() -> io::BufWriter<File> {
|
fn open_file() -> io::BufWriter<File> {
|
||||||
let curthread = thread::current();
|
let curthread = thread::current();
|
||||||
let tmpstr;
|
let tmpstr;
|
||||||
@@ -116,7 +116,7 @@ macro_rules! dbg {
|
|||||||
if $crate::dbg::enabled() {
|
if $crate::dbg::enabled() {
|
||||||
// Drop the error result so we don't get compiler errors for ignoring it.
|
// Drop the error result so we don't get compiler errors for ignoring it.
|
||||||
// What are you going to do, log the error?
|
// 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();
|
$crate::dbg::writeln_with_format_args(format_args!($($arg)+)).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
trivial_numeric_casts,
|
trivial_numeric_casts,
|
||||||
unused_extern_crates)]
|
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"), no_std)]
|
||||||
#![cfg_attr(not(feature = "std"), feature(alloc))]
|
#![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)]
|
#[allow(unused_extern_crates)]
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(not(feature = "std"))]
|
||||||
extern crate hashmap_core;
|
extern crate hashmap_core;
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@@ -66,7 +66,7 @@ mod topo_order;
|
|||||||
mod unreachable_code;
|
mod unreachable_code;
|
||||||
mod write;
|
mod write;
|
||||||
|
|
||||||
/// This replaces `std` in builds with no_std.
|
/// This replaces `std` in builds with `core`.
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
mod std {
|
mod std {
|
||||||
pub use core::*;
|
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
|
/// 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
|
/// 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
|
/// `TimingToken` and `PassTimes` types and `take_current`, `add_to_current`, and `start_pass` funcs
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
mod details {
|
mod details {
|
||||||
use super::{Pass, NUM_PASSES, DESCRIPTIONS};
|
use super::{Pass, NUM_PASSES, DESCRIPTIONS};
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
@@ -216,7 +216,7 @@ mod details {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Dummy `debug` implementation
|
/// Dummy `debug` implementation
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(not(feature = "std"))]
|
||||||
mod details {
|
mod details {
|
||||||
use super::Pass;
|
use super::Pass;
|
||||||
/// Dummy `TimingToken`
|
/// Dummy `TimingToken`
|
||||||
|
|||||||
@@ -1125,9 +1125,9 @@ mod tests {
|
|||||||
Ok(_) => { panic!("Expected an error!") },
|
Ok(_) => { panic!("Expected an error!") },
|
||||||
Err(Error { message, .. } ) => {
|
Err(Error { message, .. } ) => {
|
||||||
if !message.contains($msg) {
|
if !message.contains($msg) {
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
panic!(format!("'{}' did not contain the substring '{}'", message, $msg));
|
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");
|
panic!("error message did not contain the expected substring");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ cretonne = { path = "../cretonne", version = "0.3.4", default-features = false }
|
|||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
std = ["cretonne/std"]
|
std = ["cretonne/std"]
|
||||||
no_std = ["cretonne/no_std"]
|
core = ["cretonne/core"]
|
||||||
|
|||||||
@@ -1026,9 +1026,9 @@ mod tests {
|
|||||||
match verify_function(&func, &flags) {
|
match verify_function(&func, &flags) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
panic!(err.message);
|
panic!(err.message);
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(not(feature = "std"))]
|
||||||
panic!("function failed to verify");
|
panic!("function failed to verify");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1205,9 +1205,9 @@ mod tests {
|
|||||||
match verify_function(&func, &flags) {
|
match verify_function(&func, &flags) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
panic!(err.message);
|
panic!(err.message);
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(not(feature = "std"))]
|
||||||
panic!("function failed to verify");
|
panic!("function failed to verify");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1256,9 +1256,9 @@ mod tests {
|
|||||||
match verify_function(&func, &flags) {
|
match verify_function(&func, &flags) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(feature = "std")]
|
||||||
panic!(err.message);
|
panic!(err.message);
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(not(feature = "std"))]
|
||||||
panic!("function failed to verify");
|
panic!("function failed to verify");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,4 +19,4 @@ raw-cpuid = "3.0.0"
|
|||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
std = ["cretonne/std"]
|
std = ["cretonne/std"]
|
||||||
no_std = ["cretonne/no_std"]
|
core = ["cretonne/core"]
|
||||||
|
|||||||
@@ -26,4 +26,4 @@ tempdir = "0.3.5"
|
|||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
std = ["cretonne/std", "cretonne-frontend/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;
|
extern crate alloc;
|
||||||
|
|
||||||
#[allow(unused_extern_crates)]
|
#[allow(unused_extern_crates)]
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(not(feature = "std"))]
|
||||||
extern crate hashmap_core;
|
extern crate hashmap_core;
|
||||||
|
|
||||||
extern crate wasmparser;
|
extern crate wasmparser;
|
||||||
|
|||||||
Reference in New Issue
Block a user