Officeyutong opened issue #5785:
I have two wasm components
gcd2.wasmandgcd4.wasm.
- The first one implements and exports a function
gcd2: func(a: s64, b: s64) -> s64which calculates the greatest common divisor of two integers.- The second one imports the
gcd2function, whose signature is the same as described above, and exports a functiongcd4: func(a: s64, b: s64, c: s64, d: s64) -> s64, which uses the importedgcd2function to calculate the greatest common divisor of four integers (i.egcd(a,b,c,d)=gcd(gcd(gcd(a,b),c),d)).I'm using
wasmtime::componentto load the two components, link them together, and invoke thegcd4function, butLinker::instantiatereturned an error, indicating thatgcd2is 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:
Steps to Reproduce
- Create a new rust project using
cargo new- Modify
main.rslike mentioned above- Put the two wasm component files in the root directory of the project
cargo runExpected 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 backtraceVersions and Environment
Wasmtime version or commit: rev
255fd6b, with featurecomponent-modelOperating system:
Windows 10, 21H1 19044.2486Architecture: 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"] }
Officeyutong labeled issue #5785:
I have two wasm components
gcd2.wasmandgcd4.wasm.
- The first one implements and exports a function
gcd2: func(a: s64, b: s64) -> s64which calculates the greatest common divisor of two integers.- The second one imports the
gcd2function, whose signature is the same as described above, and exports a functiongcd4: func(a: s64, b: s64, c: s64, d: s64) -> s64, which uses the importedgcd2function to calculate the greatest common divisor of four integers (i.egcd(a,b,c,d)=gcd(gcd(gcd(a,b),c),d)).I'm using
wasmtime::componentto load the two components, link them together, and invoke thegcd4function, butLinker::instantiatereturned an error, indicating thatgcd2is 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:
Steps to Reproduce
- Create a new rust project using
cargo new- Modify
main.rslike mentioned above- Put the two wasm component files in the root directory of the project
cargo runExpected 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 backtraceVersions and Environment
Wasmtime version or commit: rev
255fd6b, with featurecomponent-modelOperating system:
Windows 10, 21H1 19044.2486Architecture: 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"] }
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 composewhere it's linked together at the component model level before something reaches Wasmtime.
Officeyutong closed issue #5785:
I have two wasm components
gcd2.wasmandgcd4.wasm.
- The first one implements and exports a function
gcd2: func(a: s64, b: s64) -> s64which calculates the greatest common divisor of two integers.- The second one imports the
gcd2function, whose signature is the same as described above, and exports a functiongcd4: func(a: s64, b: s64, c: s64, d: s64) -> s64, which uses the importedgcd2function to calculate the greatest common divisor of four integers (i.egcd(a,b,c,d)=gcd(gcd(gcd(a,b),c),d)).I'm using
wasmtime::componentto load the two components, link them together, and invoke thegcd4function, butLinker::instantiatereturned an error, indicating thatgcd2is 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:
Steps to Reproduce
- Create a new rust project using
cargo new- Modify
main.rslike mentioned above- Put the two wasm component files in the root directory of the project
cargo runExpected 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 backtraceVersions and Environment
Wasmtime version or commit: rev
255fd6b, with featurecomponent-modelOperating system:
Windows 10, 21H1 19044.2486Architecture: 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"] }
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 composewhere it's linked together at the component model level before something reaches Wasmtime.Thanks! I'll look into
wasm-tools
Last updated: Dec 13 2025 at 19:03 UTC