wiggle: make wasmtime a mandatory dep, get rid of own Trap enum (#5137)

* wiggle: no longer need to guard wasmtime integration behind a feature

this existed so we could use wiggle in lucet, but lucet is long EOL

* replace wiggle::Trap with wiggle::wasmtime_crate::Trap

* wiggle tests: unwrap traps because we cant assert_eq on them

* wasi-common: emit a wasmtime::Trap instead of a wiggle::Trap

formally add a dependency on wasmtime here to make it obvious, though
we do now have a transitive one via wiggle no matter what (and therefore
can get rid of the default-features=false on the wiggle dep)

* wasi-nn: use wasmtime::Trap instead of wiggle::Trap

there's no way the implementation of this func is actually
a good idea, it will panic the host process on any error,
but I'll ask @mtr to fix that

* wiggle test-helpers examples: fixes

* wasi-common cant cross compile to wasm32-unknown-emscripten anymore

this was originally for the WASI polyfill for web targets. Those days
are way behind us now.

* wasmtime wont compile for armv7-unknown-linux-gnueabihf either
This commit is contained in:
Pat Hickey
2022-10-27 09:28:10 -07:00
committed by GitHub
parent b20128a6cb
commit 0290a83502
30 changed files with 147 additions and 155 deletions

View File

@@ -31,7 +31,10 @@ mod convert_just_errno {
/// When the `errors` mapping in witx is non-empty, we need to impl the
/// types::UserErrorConversion trait that wiggle generates from that mapping.
impl<'a> types::UserErrorConversion for WasiCtx<'a> {
fn errno_from_rich_error(&mut self, e: RichError) -> Result<types::Errno, wiggle::Trap> {
fn errno_from_rich_error(
&mut self,
e: RichError,
) -> Result<types::Errno, wiggle::wasmtime_crate::Trap> {
// WasiCtx can collect a Vec<String> log so we can test this. We're
// logging the Display impl that `thiserror::Error` provides us.
self.log.borrow_mut().push(e.to_string());
@@ -62,19 +65,19 @@ mod convert_just_errno {
// Exercise each of the branches in `foo`.
// Start with the success case:
let r0 = one_error_conversion::foo(&mut ctx, &host_memory, 0);
let r0 = one_error_conversion::foo(&mut ctx, &host_memory, 0).unwrap();
assert_eq!(
r0,
Ok(types::Errno::Ok as i32),
types::Errno::Ok as i32,
"Expected return value for strike=0"
);
assert!(ctx.log.borrow().is_empty(), "No error log for strike=0");
// First error case:
let r1 = one_error_conversion::foo(&mut ctx, &host_memory, 1);
let r1 = one_error_conversion::foo(&mut ctx, &host_memory, 1).unwrap();
assert_eq!(
r1,
Ok(types::Errno::PicketLine as i32),
types::Errno::PicketLine as i32,
"Expected return value for strike=1"
);
assert_eq!(
@@ -84,10 +87,10 @@ mod convert_just_errno {
);
// Second error case:
let r2 = one_error_conversion::foo(&mut ctx, &host_memory, 2);
let r2 = one_error_conversion::foo(&mut ctx, &host_memory, 2).unwrap();
assert_eq!(
r2,
Ok(types::Errno::InvalidArg as i32),
types::Errno::InvalidArg as i32,
"Expected return value for strike=2"
);
assert_eq!(
@@ -114,7 +117,7 @@ mod convert_multiple_error_types {
// Just like the prior test, except that we have a second errno type. This should mean there
// are two functions in UserErrorConversion.
// Additionally, test that the function "baz" marked noreturn always returns a wiggle::Trap.
// Additionally, test that the function "baz" marked noreturn always returns a wasmtime::Trap.
wiggle::from_witx!({
witx_literal: "
(typename $errno (enum (@witx tag u8) $ok $invalid_arg $picket_line))
@@ -140,13 +143,16 @@ mod convert_multiple_error_types {
// each member of the `errors` mapping.
// Bodies elided.
impl<'a> types::UserErrorConversion for WasiCtx<'a> {
fn errno_from_rich_error(&mut self, _e: RichError) -> Result<types::Errno, wiggle::Trap> {
fn errno_from_rich_error(
&mut self,
_e: RichError,
) -> Result<types::Errno, wiggle::wasmtime_crate::Trap> {
unimplemented!()
}
fn errno2_from_another_rich_error(
&mut self,
_e: AnotherRichError,
) -> Result<types::Errno2, wiggle::Trap> {
) -> Result<types::Errno2, wiggle::wasmtime_crate::Trap> {
unimplemented!()
}
}
@@ -159,7 +165,7 @@ mod convert_multiple_error_types {
fn bar(&mut self, _: u32) -> Result<(), AnotherRichError> {
unimplemented!()
}
fn baz(&mut self, _: u32) -> wiggle::Trap {
fn baz(&mut self, _: u32) -> wiggle::wasmtime_crate::Trap {
unimplemented!()
}
}