Stream: git-wasmtime

Topic: wasmtime / issue #5785 Function not found when linking tw...


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

Officeyutong opened issue #5785:

I have two wasm components gcd2.wasm and gcd4.wasm.

I'm using wasmtime::component to load the two components, link them together, and invoke the gcd4 function, but Linker::instantiate returned an error, indicating that gcd2 is not defined.

My code is here:

use wasmtime::{
    component::{Component, Linker},
    Store,
};
struct MyState {}
fn main() {
    let mut config = wasmtime::Config::new();
    config.wasm_component_model(true);
    let engine = wasmtime::Engine::new(&config).unwrap();

    let gcd2 = Component::from_file(&engine, "gcd2.wasm").unwrap();
    let gcd4 = Component::from_file(&engine, "gcd4.wasm").unwrap();

    let mut store = Store::new(&engine, MyState {});
    let linker = Linker::new(&engine);
    // linker.instance("ss").unwrap().
    linker.instantiate(&mut store, &gcd2).unwrap();
    linker.instantiate(&mut store, &gcd4).unwrap();
}

Test Case

The two wasm components are in the following zip file:

linker-demo.zip

Steps to Reproduce

Expected Results

No panics happened

Actual Results

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: import `gcd2` has the
wrong type

Caused by:
    expected func found nothing', src\main.rs:18:43
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Versions and Environment

Wasmtime version or commit: rev 255fd6b, with feature component-model

Operating system: Windows 10, 21H1 19044.2486

Architecture: x64

Extra Info

Cargo.toml:

[package]
name = "linker-demo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", rev = "255fd6b", features = ["component-model"] }

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

Officeyutong labeled issue #5785:

I have two wasm components gcd2.wasm and gcd4.wasm.

I'm using wasmtime::component to load the two components, link them together, and invoke the gcd4 function, but Linker::instantiate returned an error, indicating that gcd2 is not defined.

My code is here:

use wasmtime::{
    component::{Component, Linker},
    Store,
};
struct MyState {}
fn main() {
    let mut config = wasmtime::Config::new();
    config.wasm_component_model(true);
    let engine = wasmtime::Engine::new(&config).unwrap();

    let gcd2 = Component::from_file(&engine, "gcd2.wasm").unwrap();
    let gcd4 = Component::from_file(&engine, "gcd4.wasm").unwrap();

    let mut store = Store::new(&engine, MyState {});
    let linker = Linker::new(&engine);
    // linker.instance("ss").unwrap().
    linker.instantiate(&mut store, &gcd2).unwrap();
    linker.instantiate(&mut store, &gcd4).unwrap();
}

Test Case

The two wasm components are in the following zip file:

linker-demo.zip

Steps to Reproduce

Expected Results

No panics happened

Actual Results

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: import `gcd2` has the
wrong type

Caused by:
    expected func found nothing', src\main.rs:18:43
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Versions and Environment

Wasmtime version or commit: rev 255fd6b, with feature component-model

Operating system: Windows 10, 21H1 19044.2486

Architecture: x64

Extra Info

Cargo.toml:

[package]
name = "linker-demo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", rev = "255fd6b", features = ["component-model"] }

view this post on Zulip Wasmtime GitHub notifications bot (Feb 15 2023 at 15:05):

alexcrichton commented on issue #5785:

Instantiating a component does not modify the Linker, you'd have to re-insert items into the linker. Additionally unlike core wasm components cannot have their functions directly hooked up via the embedder API at this time, so you'd need to have the host interpose between the two components.

Linking components together at this time is planned to be left to tooling like wasm-tools compose where it's linked together at the component model level before something reaches Wasmtime.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 15 2023 at 15:58):

Officeyutong closed issue #5785:

I have two wasm components gcd2.wasm and gcd4.wasm.

I'm using wasmtime::component to load the two components, link them together, and invoke the gcd4 function, but Linker::instantiate returned an error, indicating that gcd2 is not defined.

My code is here:

use wasmtime::{
    component::{Component, Linker},
    Store,
};
struct MyState {}
fn main() {
    let mut config = wasmtime::Config::new();
    config.wasm_component_model(true);
    let engine = wasmtime::Engine::new(&config).unwrap();

    let gcd2 = Component::from_file(&engine, "gcd2.wasm").unwrap();
    let gcd4 = Component::from_file(&engine, "gcd4.wasm").unwrap();

    let mut store = Store::new(&engine, MyState {});
    let linker = Linker::new(&engine);
    // linker.instance("ss").unwrap().
    linker.instantiate(&mut store, &gcd2).unwrap();
    linker.instantiate(&mut store, &gcd4).unwrap();
}

Test Case

The two wasm components are in the following zip file:

linker-demo.zip

Steps to Reproduce

Expected Results

No panics happened

Actual Results

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: import `gcd2` has the
wrong type

Caused by:
    expected func found nothing', src\main.rs:18:43
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Versions and Environment

Wasmtime version or commit: rev 255fd6b, with feature component-model

Operating system: Windows 10, 21H1 19044.2486

Architecture: x64

Extra Info

Cargo.toml:

[package]
name = "linker-demo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", rev = "255fd6b", features = ["component-model"] }

view this post on Zulip Wasmtime GitHub notifications bot (Feb 15 2023 at 15:58):

Officeyutong commented on issue #5785:

Instantiating a component does not modify the Linker, you'd have to re-insert items into the linker. Additionally unlike core wasm components cannot have their functions directly hooked up via the embedder API at this time, so you'd need to have the host interpose between the two components.

Linking components together at this time is planned to be left to tooling like wasm-tools compose where it's linked together at the component model level before something reaches Wasmtime.

Thanks! I'll look into wasm-tools


Last updated: Nov 22 2024 at 16:03 UTC