Stream: git-wasmtime

Topic: wasmtime / issue #7653 component-model: unknown binary ve...


view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2023 at 17:13):

JMLX42 edited issue #7653:

Test Case

add.wasm: add.zip

Steps to Reproduce

    let engine = Engine::default();
    let module = Module::from_binary(&engine, &data).expect("Failed to load module");
    let mut store = Store::new(&engine, ());
    let instance = Instance::new(&mut store, &module, &[])?;
    let answer = instance
        .get_func(&mut store, "add")
        .expect("`add` was not an exported function");

Expected Results

Module::from_binary() returns a Ok(Module).

Actual Results

Panic!

thread 'main' panicked at crates/wasm2openapi/src/main.rs:186:54:
Failed to load module: failed to parse WebAssembly module

Caused by:
    Invalid input WebAssembly code at offset 0: unknown binary version and encoding combination: 0xd and 0x1, note: encoded as a component but the WebAssembly component model feature is not enabled - enable the feature to allow component validation
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Versions and Environment

For the add.wasm component:

cargo-component-bindings = "0.5.0"

For the host app:

wasmtime = { version = "15.0.1", features = ["component-model"] }

Operating system: Ubuntu 22.04

Architecture: 64bit

Extra Info

Trying to dynamically call WASM Component exported functions via HTTP: https://github.com/JMLX42/wasm2openapi

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2023 at 18:26):

pchickey commented on issue #7653:

Set https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.wasm_component_model

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2023 at 18:26):

pchickey closed issue #7653:

Test Case

add.wasm: add.zip

Steps to Reproduce

    let engine = Engine::default();
    let module = Module::from_binary(&engine, &data).expect("Failed to load module");
    let mut store = Store::new(&engine, ());
    let instance = Instance::new(&mut store, &module, &[])?;
    let answer = instance
        .get_func(&mut store, "add")
        .expect("`add` was not an exported function");

Expected Results

Module::from_binary() returns a Ok(Module).

Actual Results

Panic!

thread 'main' panicked at crates/wasm2openapi/src/main.rs:186:54:
Failed to load module: failed to parse WebAssembly module

Caused by:
    Invalid input WebAssembly code at offset 0: unknown binary version and encoding combination: 0xd and 0x1, note: encoded as a component but the WebAssembly component model feature is not enabled - enable the feature to allow component validation
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Versions and Environment

For the add.wasm component:

cargo-component-bindings = "0.5.0"

For the host app:

wasmtime = { version = "15.0.1", features = ["component-model"] }

Operating system: Ubuntu 22.04

Architecture: 64bit

Extra Info

Trying to dynamically call WASM Component exported functions via HTTP: https://github.com/JMLX42/wasm2openapi

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2023 at 22:09):

JMLX42 commented on issue #7653:

Set https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.wasm_component_model

Thank you @pchickey !

Yet as a Rust developer, when I read the "the WebAssembly component model feature is not enabled" part of the error message, I thought of a Cargo feature. May I suggest to make the error message more specific?

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2023 at 22:13):

JMLX42 edited a comment on issue #7653:

Set https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.wasm_component_model

Thank you @pchickey !

Yet as a Rust developer, when I read the "the WebAssembly component model feature is not enabled" part of the error message, I thought of a Cargo feature. May I suggest to make the error message more specific?

Update: the code still fails with a similar "feature" related error

    let config = {
        let mut config = Config::new();
        config.wasm_component_model(true);
        config
    };
    let engine = Engine::new(&config).expect("Failed to create WASM engine");
    let module = Module::from_binary(&engine, &data).expect("Failed to load module");
    let mut store = Store::new(&engine, ());
    let instance = Instance::new(&mut store, &module, &[])?;
    let answer = instance
        .get_func(&mut store, "add")
        .expect("`add` was not an exported function");
thread 'main' panicked at crates/wasm2openapi/src/main.rs:191:54:
Failed to load module: failed to parse WebAssembly module

Caused by:
    Unsupported feature: component model

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2023 at 22:13):

JMLX42 edited a comment on issue #7653:

Set https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.wasm_component_model

Thank you @pchickey !

Yet as a Rust developer, when I read the "the WebAssembly component model feature is not enabled" part of the error message, I thought of a Cargo feature. May I suggest to make the error message more specific?

Update: the code still fails with a similar "feature" related error

    let config = {
        let mut config = Config::new();
        config.wasm_component_model(true);
        config
    };
    let engine = Engine::new(&config).expect("Failed to create WASM engine");
    let module = Module::from_binary(&engine, &data).expect("Failed to load module");
    let mut store = Store::new(&engine, ());
    let instance = Instance::new(&mut store, &module, &[])?;
    let answer = instance
        .get_func(&mut store, "add")
        .expect("`add` was not an exported function");
thread 'main' panicked at crates/wasm2openapi/src/main.rs:191:54:
Failed to load module: failed to parse WebAssembly module

Caused by:
    Unsupported feature: component model

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2023 at 22:13):

pchickey commented on issue #7653:

Its a good suggestion, but it will require some plumbing. That error message is being thrown from wasmparser's validator https://github.com/bytecodealliance/wasm-tools/blob/main/crates/wasmparser/src/validator.rs#L599 , which is in a separate repository from Wasmtime. You could change it to a new (pub) error struct with that same text in the Display impl, and add code in wasmtime to try to downcast to that concrete error and make suggestions for the wasmtime (feature = "component-model") and the Config method dynamically.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2023 at 22:16):

JMLX42 commented on issue #7653:

Ah... lots of plumbing that might not be very future-proof. Still people will now find this issue at least I guess!

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2023 at 22:17):

pchickey commented on issue #7653:

Its also worth noting that we will be turning all of these features on by default when we ship a completed WASI Preview 2 in the Wasmtime 17 release. So hopefully you are one of the last to run into this.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2023 at 22:17):

pchickey edited a comment on issue #7653:

Its also worth noting that we will be turning all of these features on by default when we ship a ratified WASI Preview 2 in the Wasmtime 17 release. So hopefully you are one of the last to run into this.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2023 at 22:31):

JMLX42 commented on issue #7653:

```
thread 'main' panicked at crates/wasm2openapi/src/main.rs:191:54:
Failed to load module: failed to parse WebAssembly module

Caused by:
Unsupported feature: component model
```

If anyone else runs into this error, here is how to properly instantiate a component:

    let config = {
        let mut config = Config::new();
        config.wasm_component_model(true);
        config
    };
    let engine = Engine::new(&config).expect("Failed to create WASM engine");
    let component = Component::from_binary(&engine, &data).expect("Failed to load component");
    let linker: Linker<()> = Linker::new(&engine);
    let mut store = Store::new(&engine, ());
    let instance = linker
        .instantiate(&mut store, &component)
        .expect("Failed to instantiate component");

Its also worth noting that we will be turning all of these features on by default when we ship a ratified WASI Preview 2 in the Wasmtime 17 release. So hopefully you are one of the last to run into this.

Looks like you guys are right on schedule based on https://bytecodealliance.org/articles/webassembly-the-updated-roadmap-for-developers

Outstanding work! :rocket:


Last updated: Dec 23 2024 at 13:07 UTC