Stream: git-wasmtime

Topic: wasmtime / issue #7536 "Unknown import" error when runnin...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 14:45):

kellytk opened issue #7536:

$ git repo
commit 321294a5d21f7006a959ba378ebd32782a76d3d2
...

$ wasmtime --version
wasmtime-cli 16.0.0

crates/test-programs$ cargo build --target=wasm32-wasi

$ wasmtime preview2_ip_name_lookup.wasm
Error: failed to run main module preview2_ip_name_lookup.wasm

Caused by:
0: failed to instantiate "preview2_ip_name_lookup.wasm"
1: unknown import: wasi:sockets/network@0.2.0-rc-2023-11-10::[resource-drop]network has not been defined

How can this error be resolved?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 14:50):

kellytk edited issue #7536:

$ git log
commit 321294a5d21f7006a959ba378ebd32782a76d3d2
...

$ wasmtime --version
wasmtime-cli 16.0.0

crates/test-programs$ cargo build --target=wasm32-wasi

$ wasmtime preview2_ip_name_lookup.wasm
Error: failed to run main module preview2_ip_name_lookup.wasm

Caused by:
0: failed to instantiate "preview2_ip_name_lookup.wasm"
1: unknown import: wasi:sockets/network@0.2.0-rc-2023-11-10::[resource-drop]network has not been defined

How can this error be resolved?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 14:52):

kellytk edited issue #7536:

$ git log
commit 321294a5d21f7006a959ba378ebd32782a76d3d2
...

$ wasmtime --version
wasmtime-cli 16.0.0

crates/test-programs$ cargo build --target=wasm32-wasi

$ wasmtime preview2_ip_name_lookup.wasm

Error: failed to run main module `preview2_ip_name_lookup.wasm`

Caused by:
    0: failed to instantiate "preview2_ip_name_lookup.wasm"
    1: unknown import: `wasi:sockets/network@0.2.0-rc-2023-11-10::[resource-drop]network` has not been defined

How can this error be resolved?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 15:48):

alexcrichton commented on issue #7536:

Thanks for the report! I think this indicates that you're running a WebAssembly core module which was intended to become a component directly as a core module instead of a component. There is no specification for the API that you listed at this time, meaning that youre program cannot be run directly. Instead you'll need to run wasm-tools component new to produce a component which can then be run inside of Wasmtime.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 16:05):

kellytk commented on issue #7536:

Thank you for such a prompt reply. The code I'm attempting to run is located at https://github.com/bytecodealliance/wasmtime/blob/main/crates/test-programs/src/bin/preview2_ip_name_lookup.rs. Is the workflow for using wasm-tools through to running the program documented somewhere? I would think code within the wasmtime repo would all be easily runnable.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 17:04):

kellytk commented on issue #7536:

I don't know if this is what you're referring to, however wasm-tools component new preview2_ip_name_lookup.wasm -o out.wasm (from https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wit-component#cli-usage) generates:

error: failed to encode a component from module
Caused by:
    0: module requires an import interface named `wasi_snapshot_preview1`

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 17:41):

alexcrichton commented on issue #7536:

Unfortunately no it's not currently documented, but you'll need to pass an --adapt argument to the wasm-tools command which points to a preview1-to-preview2 adapter. Those can be found in Wasmtime releases for example

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 17:54):

kellytk commented on issue #7536:

Ok, I'll do something to improve that.

Is wasm-tools component new preview2_ip_name_lookup.wasm -o out.wasm --adapt ~/wasi_snapshot_preview1.command.wasm correct? If so, it runs with apparently no output.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 17:55):

alexcrichton commented on issue #7536:

That should produce an out.wasm component file. You can inspect it with wasm-tools component wit out.wasm for example.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 18:08):

kellytk commented on issue #7536:

Haha, right, pardon me.

$ wasm-tools component wit out.wasm

package root:component;

world root {
  import wasi:io/poll@0.2.0-rc-2023-11-10;
  import wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10;
  import wasi:sockets/network@0.2.0-rc-2023-11-10;
  import wasi:sockets/instance-network@0.2.0-rc-2023-11-10;
  import wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10;
  import wasi:io/streams@0.2.0-rc-2023-10-18;
  import wasi:filesystem/types@0.2.0-rc-2023-10-18;
  import wasi:filesystem/preopens@0.2.0-rc-2023-10-18;
  import wasi:sockets/tcp@0.2.0-rc-2023-10-18;
  import wasi:cli/environment@0.2.0-rc-2023-10-18;
  import wasi:cli/exit@0.2.0-rc-2023-10-18;
  import wasi:cli/stdin@0.2.0-rc-2023-10-18;
  import wasi:cli/stdout@0.2.0-rc-2023-10-18;
  import wasi:cli/stderr@0.2.0-rc-2023-10-18;
  import wasi:cli/terminal-input@0.2.0-rc-2023-10-18;
  import wasi:cli/terminal-output@0.2.0-rc-2023-10-18;
  import wasi:cli/terminal-stdin@0.2.0-rc-2023-10-18;
  import wasi:cli/terminal-stdout@0.2.0-rc-2023-10-18;
  import wasi:cli/terminal-stderr@0.2.0-rc-2023-10-18;

  export wasi:cli/run@0.2.0-rc-2023-10-18;
}

$ wasmtime out.wasm

Error: cannot execute a component without `--wasm component-model`

$ wasmtime --wasm component-model out.wasm

Error: failed to run main module `out.wasm`

Caused by:
    0: import `wasi:io/streams@0.2.0-rc-2023-10-18` has the wrong type
    1: instance export `output-stream` has the wrong type
    2: expected resource found nothing

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 18:36):

pchickey commented on issue #7536:

If you are using wasmtime-cli from source, it has a newer version of those interfaces than the ones you have built with that adapter, so make sure you use a wasmtime-cli from the same release as the adapter, or build the adapter from source.

These problems will go away once we ship preview 2 and have stable versions across wasmtime releases, we are almost there.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 18:36):

pchickey edited a comment on issue #7536:

If you are using wasmtime-cli from source, it has a newer version of those interfaces than the ones you have built with that adapter, so make sure you use a wasmtime-cli from the same release as the adapter, or build the adapter from source.

These problems will go away once we ship preview 2 and have stable interface versions across wasmtime releases, we are almost there.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 18:44):

kellytk commented on issue #7536:

Thank you both for enduring the overhead while the ecosystem is so green.

Is the process for building adapters from source documented? I have the wasmtime repo cloned and have built wasmtime from it.

These problems will go away once we ship preview 2 and have stable interface versions across wasmtime releases, we are almost there.

Is an up-to-date schedule for such milestones published?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 18:52):

alexcrichton commented on issue #7536:

We're working on getting all these things documented but one thing I'll point out is that when everything is in flux there's not always great documentation. I'd recommend reading a bit into how things work in this repository while we're working on stabilizing everything. The source-of-truth for example about building the adapter is our GitHub Actions configuration which would point you to this script.

Additionally for schedules and milestones and such we do not have a concrete set of documentation to point you towards at this time. Much of this depends on the stabilization of WASI itself which is moving through the standards process. It's intended that by the end of the year WASI has stabilized.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 18:53):

alexcrichton edited a comment on issue #7536:

We're working on getting all these things documented but one thing I'll point out is that when everything is in flux there's not always great documentation. I'd recommend reading a bit into how things work in this repository while we're working on stabilizing everything. The source-of-truth for example about building the adapter is our GitHub Actions configuration which would point you to this script.

Additionally for schedules and milestones and such we do not have a concrete set of documentation to point you towards at this time. Much of this depends on the stabilization of WASI itself which is moving through the standards process. It's intended that by the end of the year WASI has a more stable 0.2.0 release.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2023 at 18:58):

kellytk closed issue #7536:

$ git log
commit 321294a5d21f7006a959ba378ebd32782a76d3d2
...

$ wasmtime --version
wasmtime-cli 16.0.0

crates/test-programs$ cargo build --target=wasm32-wasi

$ wasmtime preview2_ip_name_lookup.wasm

Error: failed to run main module `preview2_ip_name_lookup.wasm`

Caused by:
    0: failed to instantiate "preview2_ip_name_lookup.wasm"
    1: unknown import: `wasi:sockets/network@0.2.0-rc-2023-11-10::[resource-drop]network` has not been defined

How can this error be resolved?


Last updated: Oct 23 2024 at 20:03 UTC