Skip to content
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

Running example #45

Closed
stevesloka opened this issue Nov 29, 2023 · 3 comments
Closed

Running example #45

stevesloka opened this issue Nov 29, 2023 · 3 comments

Comments

@stevesloka
Copy link

I'm looking to get the example in the readme working. I have the component wasm compiled via this command:

$ componentize-py -d hello.wit -w hello componentize app -o app.wasm

Now I want to run this via wasmtime but that gives me this error:

$ wasmtime run --wasm component-model app.wasm                             
Error: failed to run main module `app.wasm`

Caused by:
    exported instance `wasi:cli/run@0.2.0-rc-2023-11-10` not present

I thought I could convert this to a core module with wasm-tools but that gives me a different error:

$ wasm-tools component new -v app.wasm -o out.wasm --adapt wasi_snapshot_preview1.reactor.wasm
error: failed to encode a component from module

Caused by:
    0: unknown table 2: exported table index out of bounds (at offset 0xb)

Ideally I'd like to take Python and covert it into wasm much like how it's done in Javy (https://github.com/bytecodealliance/javy) where the output of javy compile is code that I can execute with wasmtime <output>.wasm.

Thanks for any help or ideas! =)

@dicej
Copy link
Collaborator

dicej commented Nov 29, 2023

Hi @stevesloka; thanks for the report.

Regarding the first issue: hello.wit does not export wasi:cli/run, so it's not a CLI command as defined by WASI Preview 2. The only way to run a component targeting a custom world like this is to write a Rust program that uses Wasmtime's component API to instantiate the component and invoke its hello export. Or use something like https://github.com/rylev/wepl, although I don't think it's been updated to Wasmtime 15 yet. Anyway, if you want to make a CLI command, you'll need to target a world which exports wasi:cli/run at minimum (and maybe import wasi:cli/stdio if you want to print to the console).

When I have a few minutes, I'll add a CLI example to the repo for reference.

Regarding the second error: that wasm-tools command is for turning a core module into a component, not vice versa. And there's no way in general to convert a component into a core module, since a component is often made up of multiple core modules. Components generated by componentize-py are always made up of at least 11 modules.

@dicej
Copy link
Collaborator

dicej commented Nov 30, 2023

#46 adds a CLI example (and fixes a componentize-py bug I found when testing it). Unfortunately, there's also a bug in wasmtime-wasi that prevents wasmtime run from running the example. That will be fixed when bytecodealliance/wasmtime#7613 is merged.

@stevesloka
Copy link
Author

Thanks for the explanation and examples @dicej! I have a better understanding of how this all fits together, thanks for bearing with me through all of it and explaining.

I'm still trying to get the example you have in your PR to work, ran into a different error which I commented on. Once I get an example running locally, I think it will help out my mental model of everything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants