Open ConradMearns opened 6 months ago
Ah I think this is a bug in the bindings generator. Would be good to have a fix, but I alas don't have time to take a look at this at this time.
+1 on this, do you maybe have had some time to look into this already @alexcrichton ? Is there any other way of getting componentized
Python modules to work with wasmtime
?
Alas I still do not have time to look into this, but assistance in helping to fix issues in the bindings would be much appreciated!
To clarify the issue here: componentize-py
does not currently have a way to stub out or omit wasi:cli
imports required by the CPython interpreter and standard library, and since wasmtime-py
does not include a wasi:cli
implementation, it can't run componentize-py
-generated components. Very early versions of componentize-py
did have such a feature, which is why it worked at one point, but the addition of native extension support required a large refactor, and I was forced to drop that feature.
I do plan to revisit that and add an option to stub out WASI imports in componentize-py
, but it would have to be done carefully. For example, we might need to patch the random
module so it (A) doesn't try to use wasi:random
to initialize the PRNG seed and (B) returns an error if any application code tries to use it.
BTW, there are two things missing in wasmtime-py
that prevent it from running components with WASI 0.2 imports (whether by way of componentize-py
or some other tool):
wasmtime-wasi
Rust implementation)Both of those items would require significant effort.
I went ahead and dug into this on the componentize-py
side, adding a --stub-wasi
feature which may be used to stub-out any WASI imports. This has the side effect of baking in the PRNG seed in Python's random
module, so it should not be used for apps which need a access to a secure RNG. Here's an example: https://github.com/bytecodealliance/componentize-py/tree/main/examples/sandbox
I'm attempting to follow along with https://github.com/bytecodealliance/componentize-py to write a python WASM component that returns "Hello World!", and import that WASM module into python to execute it.
I have a
hello.wit
hello.py
I can build the WASM file with
but when I try to start the process of utilizing this module, I run into an error with
wasmtime.bindgen
My versions from
poetry show
I'm not sure if I'm maybe missing a step, or when the breaking change was introduced.
Related: https://github.com/bytecodealliance/component-docs/issues/84 https://github.com/bytecodealliance/wasmtime-py/issues/197
If I find a version combination that works I'll report back :)