Skip to content

Commit

Permalink
chore: don't require nightly for no_std
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
  • Loading branch information
explodingcamera committed Dec 10, 2023
1 parent abdfb74 commit cdf44f4
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 24 deletions.
3 changes: 1 addition & 2 deletions crates/parser/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,12 @@ pub(crate) fn convert_memarg(memarg: wasmparser::MemArg) -> MemArg {
}

pub fn process_operators<'a>(
offset: usize,
mut offset: usize,
ops: impl Iterator<Item = Result<wasmparser::Operator<'a>, wasmparser::BinaryReaderError>>,
mut validator: FuncValidator<ValidatorResources>,
) -> Result<Box<[Instruction]>> {
let mut instructions = Vec::new();

let mut offset = offset.into();
for op in ops {
let op = op?;
validator.op(offset, &op)?;
Expand Down
1 change: 0 additions & 1 deletion crates/tinywasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ default=["std", "parser", "logging"]
logging=["log", "tinywasm-types/logging", "tinywasm-parser?/logging"]
std=["tinywasm-parser?/std", "tinywasm-types/std"]
parser=["tinywasm-parser"]
nightly=[]
1 change: 1 addition & 0 deletions crates/tinywasm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl Display for Error {
}
}

#[cfg(any(feature = "std", all(not(feature = "std"), nightly)))]
impl crate::std::error::Error for Error {}

#[cfg(feature = "parser")]
Expand Down
15 changes: 6 additions & 9 deletions crates/tinywasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
)
))]
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
#![cfg_attr(feature = "nightly", feature(error_in_core))]
#![cfg_attr(nightly, feature(error_in_core))]

//! A tiny WebAssembly Runtime written in Rust
//!
Expand Down Expand Up @@ -56,14 +56,11 @@
//! - `parser` (default): Enables the `tinywasm_parser` crate for parsing WebAssembly modules.
//!
//! ## No-std support
//! TinyWasm supports `no_std` environments by disabling the `std` feature. This removes
//! support for parsing from files and streams, but otherwise the API is the same.
//! Additionally, you must use a nightly compiler as TinyWasm uses the `error_in_core` feature
//! and have a `GlobalAlloc` implementation for allocating memory.
// compiler error when using no_std without nightly
#[cfg(all(not(feature = "std"), not(nightly)))]
const _: () = { compile_error!("`nightly` feature is required for `no_std`") };
//! TinyWasm supports `no_std` environments by disabling the `std` feature and registering
//! a custom allocator. This removes support for parsing from files and streams,
//! but otherwise the API is the same.
//!
//! Additionally, if you want proper error types, you must use a `nightly` compiler.
mod std;
extern crate alloc;
Expand Down
2 changes: 1 addition & 1 deletion crates/tinywasm/src/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ pub(crate) mod error {
#[cfg(feature = "std")]
pub(crate) use std::error::Error;

#[cfg(not(feature = "std"))]
#[cfg(all(not(feature = "std"), nightly))]
pub(crate) use core::error::Error;
}
18 changes: 8 additions & 10 deletions crates/tinywasm/tests/mvp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ fn parse_module(mut module: wast::core::Module) -> Result<TinyWasmModule, Error>

#[test]
#[ignore]
fn test_mvp() {
fn test_mvp() -> Result<()> {
let mut test_suite = TestSuite::new();

wasm_testsuite::MVP_TESTS.iter().for_each(|group| {
println!("test: {}", group);

let test_group = test_suite.test_group(group);

let wast = wasm_testsuite::get_test_wast(group).expect("failed to get test wast");
Expand Down Expand Up @@ -59,11 +57,9 @@ fn test_mvp() {
AssertMalformed {
span,
module: QuoteWat::Wat(wast::Wat::Module(module)),
message,
message: _,
} => {
println!(" assert_malformed: {}", message);
let res = std::panic::catch_unwind(|| parse_module(module).map(|_| ()));

test_group.add_result(
&format!("{}-malformed", name),
span,
Expand All @@ -85,9 +81,11 @@ fn test_mvp() {
});

if test_suite.failed() {
panic!("failed one or more tests: {:#?}", test_suite);
eprintln!("\n\nfailed one or more tests:\n{:#?}", test_suite);
Err(Error::Other("failed one or more tests".to_string()))
} else {
println!("passed all tests: {:#?}", test_suite);
println!("\n\npassed all tests:\n{:#?}", test_suite);
Ok(())
}
}

Expand Down Expand Up @@ -169,11 +167,11 @@ impl TestGroup {
}

fn add_result(&mut self, name: &str, span: wast::token::Span, result: Result<()>) {
self.tests.insert(name.to_string(), TestCase { result, span });
self.tests.insert(name.to_string(), TestCase { result, _span: span });
}
}

struct TestCase {
result: Result<()>,
span: wast::token::Span,
_span: wast::token::Span,
}
2 changes: 1 addition & 1 deletion crates/wasm-testsuite/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub const V2_DRAFT_1_TESTS: &[&str] = &["address.wast","align.wast","binary-leb1

/// Get all test file names and their contents.
pub fn get_tests_wast(include_proposals: &[String]) -> impl Iterator<Item = (String, Cow<'static, [u8]>)> {
get_tests(&include_proposals)
get_tests(include_proposals)
.filter_map(|name| Some((name.clone(), get_test_wast(&name)?)))
.map(|(name, data)| (name, Cow::Owned(data.to_vec())))
}
Expand Down

0 comments on commit cdf44f4

Please sign in to comment.