summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenry Gressmann <mail@henrygressmann.de>2023-12-11 00:23:21 +0100
committerHenry Gressmann <mail@henrygressmann.de>2023-12-11 00:23:21 +0100
commitcdf44f4852ed6f52deb9823331f26e0bbaf07732 (patch)
tree0da3182bbb48cf0c6637c18d7f46c6aa2f08ff38
parentabdfb744723f5931add7c248ffc242a11d52b976 (diff)
chore: don't require nightly for no_std
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
-rw-r--r--crates/parser/src/conversion.rs3
-rw-r--r--crates/tinywasm/Cargo.toml1
-rw-r--r--crates/tinywasm/src/error.rs1
-rw-r--r--crates/tinywasm/src/lib.rs15
-rw-r--r--crates/tinywasm/src/std.rs2
-rw-r--r--crates/tinywasm/tests/mvp.rs18
-rw-r--r--crates/wasm-testsuite/lib.rs2
7 files changed, 18 insertions, 24 deletions
diff --git a/crates/parser/src/conversion.rs b/crates/parser/src/conversion.rs
index f15c9ae..19b7586 100644
--- a/crates/parser/src/conversion.rs
+++ b/crates/parser/src/conversion.rs
@@ -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)?;
diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml
index dd7da94..1865614 100644
--- a/crates/tinywasm/Cargo.toml
+++ b/crates/tinywasm/Cargo.toml
@@ -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=[]
diff --git a/crates/tinywasm/src/error.rs b/crates/tinywasm/src/error.rs
index 926a9bc..dc53106 100644
--- a/crates/tinywasm/src/error.rs
+++ b/crates/tinywasm/src/error.rs
@@ -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")]
diff --git a/crates/tinywasm/src/lib.rs b/crates/tinywasm/src/lib.rs
index 8abf280..179cca3 100644
--- a/crates/tinywasm/src/lib.rs
+++ b/crates/tinywasm/src/lib.rs
@@ -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
//!
@@ -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;
diff --git a/crates/tinywasm/src/std.rs b/crates/tinywasm/src/std.rs
index c31de8f..b77675b 100644
--- a/crates/tinywasm/src/std.rs
+++ b/crates/tinywasm/src/std.rs
@@ -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;
}
diff --git a/crates/tinywasm/tests/mvp.rs b/crates/tinywasm/tests/mvp.rs
index dacffe3..87a36d8 100644
--- a/crates/tinywasm/tests/mvp.rs
+++ b/crates/tinywasm/tests/mvp.rs
@@ -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");
@@ -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,
@@ -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(())
}
}
@@ -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,
}
diff --git a/crates/wasm-testsuite/lib.rs b/crates/wasm-testsuite/lib.rs
index 50ff48f..7e6afb4 100644
--- a/crates/wasm-testsuite/lib.rs
+++ b/crates/wasm-testsuite/lib.rs
@@ -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())))
}