-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(wamr): add wasm-micro-runtime shim implementation #716
Conversation
…error upstream to the official wamr SDK solves this issue Signed-off-by: jiaxiao zhou <[email protected]>
I believe there are more work to be done to parse the runtimeError to appropriate exit code. failures: wamr_tests::test_custom_entrypoint wamr_tests::test_exit_code wamr_tests::test_hello_world_oci wamr_tests::test_seccomp wamr_tests::test_unreachable Signed-off-by: jiaxiao zhou <[email protected]>
…lows Signed-off-by: jiaxiao zhou <[email protected]>
Signed-off-by: jiaxiao zhou <[email protected]>
.or_else(|err| { | ||
log::error!("Error: {:?}", err); | ||
Err(err) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should parse the RuntimeError to appropriate exit code. Any thoughts on this one, @lum1n0us?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding that, I just noticed that WAMR only uses error strings to convey information if something goes wrong during the execution of a Wasm function. So, if it's okay, can we continue to display the error string in the log and use a simple -1 and 0 to indicate failure and success, respectively?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking for exit code that can pass this test: https://github.com/containerd/runwasi/blob/main/crates/containerd-shim-wasmer/src/tests.rs#L79-L88
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, how can I get exit code 42 from running this wasm module?
(module
;; Import the required proc_exit WASI function which terminates the program with an exit code.
;; The function signature for proc_exit is:
;; (exit_code: i32) -> !
(import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (param i32)))
(memory 1)
(export "memory" (memory 0))
(func $main (export "_start")
(call $proc_exit (i32.const 42))
unreachable
)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a fix for this situation. Please have a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged
Signed-off-by: jiaxiao zhou <[email protected]>
@lum1n0us do you know why the entrypoint_test failed? thread 'wamr_tests::test_custom_entrypoint' panicked at crates/containerd-shim-wamr/src/tests.rs:58:5:
assertion `left == right` failed
left: "hello world\n[00:08:01:896 - 7FA1CA910640]: warning: a module with WASI apis should be either a command or a reactor\n"
right: "hello world\n" |
Signed-off-by: jiaxiao zhou <[email protected]>
Also, it doesn't seem like it runs on Windows: https://github.com/containerd/runwasi/actions/runs/11692971119/job/32563482903?pr=716#step:8:167 |
Signed-off-by: jiaxiao zhou <[email protected]>
Signed-off-by: jiaxiao zhou <[email protected]>
Signed-off-by: jiaxiao zhou <[email protected]>
Yes, that's because WAMR enforces a strict application ABI check. Every wasm32-wasi .wasm should be classified as either a command or a reactor. For your case,
|
Signed-off-by: jiaxiao zhou <[email protected]>
So, which option? |
I disabled that test for now and I don't think we need to pass it to get this PR merged. Let me fix the linting issue. |
if the target is windows, do not import the APIs changed the compiler_error to panic! Signed-off-by: jiaxiao zhou <[email protected]>
@jprendes @andreiltd can you give this PR a review please 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, left a few comments and suggestions
unsafe impl Send for WamrEngine {} | ||
unsafe impl Sync for WamrEngine {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Could you add a comment as to why this is safe to do? I guess Runtime
is not Send
/Sync
, should Runtime
be made Send
/Sync
upstream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the Runtime
should be made Send
/ Sync
upstream
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lum1n0us is this the case? Does Wamr Runtime
contain any thread-local storage? Does it have any shared internal states?
impl Clone for WamrEngine { | ||
fn clone(&self) -> Self { | ||
let runtime = Runtime::new().unwrap(); | ||
Self { runtime } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Is this correct? doesn't Runtime
hold any state? I don't remember why we require the engine to be Clone
:-\
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want the Engine
to be Clone
because we want cheap copies of the Runtime for each container in the pod. This is the case for Wasmtime, WasmEdge and Wasmer. I believe it should be the case for Wamr as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we don't clone the engine for each container, we clone the process...
In any case, if we create a new runtime with each clone, we might as well use a marker struct for the Engine and create a new runtime inside the run_wasi method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I agree with you that we clone the entire process so there is no point to clone the engine.
In any case, if we create a new runtime with each clone,
at least for wasmtime, Engine::clone()
is a cheap operation: https://docs.wasmtime.dev/api/wasmtime/struct.Engine.html#engines-and-clone
Signed-off-by: Jiaxiao Zhou <[email protected]>
Co-authored-by: Jorge Prendes <[email protected]> Signed-off-by: Jiaxiao Zhou <[email protected]>
Signed-off-by: jiaxiao zhou <[email protected]>
Signed-off-by: jiaxiao zhou <[email protected]>
…ance to wamrInst Signed-off-by: jiaxiao zhou <[email protected]>
Follow up on the work done by #508 and #642. The runtime execution
"thread signal env initialized failed"
error was resolved by the upstream Wamr SDK and thus I used the latest sdk to re-build the wamr shim.Now it actually worked!
TODO