Stream: wasmtime

Topic: ✔ wasmtime.loader does not load .wasm files


view this post on Zulip Christoph Brewing (Jul 08 2024 at 11:41):

I wonder if wasmtime-py is able to process components in form of .wasm files. Can anyone confirm that?

The example loader_component.py seems to load and call a component indeed. I can see it executing. However, it loads a .wat.

In case I try to load a component as .wasm, I get the following error:

$ python -m myloader
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/finnfalter/dev/python/wasmtimecomp/myloader.py", line 2, in <module>
    import demo_component
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "myloader.py", line 80, in exec_module
    exec(component_files[relative_path], module.__dict__)
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "myloader.py", line 80, in exec_module
    exec(component_files[relative_path], module.__dict__)
         ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'imports.py'

Running

import wasmtime, wasmtime.loader
import demo_component

store = wasmtime.Store()
component = demo_component.Root(store)
component.run(store)

Where demo_component corresponds to demo.component here

Python WebAssembly runtime powered by Wasmtime. Contribute to bytecodealliance/wasmtime-py development by creating an account on GitHub.
Python WebAssembly runtime powered by Wasmtime. Contribute to bytecodealliance/wasmtime-py development by creating an account on GitHub.

view this post on Zulip Alex Crichton (Jul 08 2024 at 14:19):

Support for this was the intention of https://github.com/bytecodealliance/wasmtime-py/pull/224 but you might have stumbled across a bug? If so mind opening an issue?

Fixes #220. Closes #219. Depends on #221. Depends on #222. Works like this: $ ls wavedrom.wasm ... $ python -c 'import wasmtime.loader, json, wavedrom; store = wasmtime.Store(); print(wavedrom.R...

view this post on Zulip Christoph Brewing (Jul 08 2024 at 20:06):

Thank you, yes, I have seen that PR and I can positively repeat it but I do not succeed with any .wasm file.

Just created issue #245

I also created a public repo with an example to quickly replay my observation.

Even though having successfully repeated this example to load a component, my observation is that components in form of *.wasm are not loaded but yield an error instead. See this public repo with a...
Contribute to wamli/wasmtime-py-component-loader development by creating an account on GitHub.

view this post on Zulip Christoph Brewing (Jul 11 2024 at 07:15):

@Catherine (whitequark) would you be able to quickly see if that may be a bug or rather a problem in front of the computer?

view this post on Zulip Catherine (whitequark) (Jul 11 2024 at 10:13):

This is a bug in my PR. For whatever reason, wasmtime's bindgen actually produces a different list of Python build products between .wasm and .wat inputs, so while I assumed that the .wat and .wasm cause the same code paths to be taken, that was not correct.

view this post on Zulip Catherine (whitequark) (Jul 11 2024 at 10:15):

Oh, wait. I realize now that the .wasm/.wat distinction is a red herring. Your demo component includes an import, and I don't handle those right; the included example with an adder does not.

But I also don't think we have a design to handle component imports of Python functions (if I recall; I may be wrong) so that will probably have to be solved first.

view this post on Zulip Christoph Brewing (Jul 11 2024 at 10:20):

Thank you for your fast feedback!

I am very interested in that feature. If I can help somehow, please let me know.
At least, I might test it.

view this post on Zulip Catherine (whitequark) (Jul 11 2024 at 12:16):

Sorry, my health does not permit me to spend time on this fix right now.

view this post on Zulip Notification Bot (Jul 15 2024 at 07:09):

Christoph Brewing has marked this topic as resolved.


Last updated: Nov 22 2024 at 16:03 UTC