Stream: git-wasmtime

Topic: wasmtime / issue #5834 How can I link two modules that ea...


view this post on Zulip Wasmtime GitHub notifications bot (Feb 19 2023 at 17:46):

Officeyutong opened issue #5834:

For example, the following program panicked when linking the first module due to module2::testfunc2 not defined.

use wasmtime::{Engine, Linker, Module, Store};

struct State {}

fn main() {
    let engine = Engine::default();
    let mut linker = Linker::new(&engine);
    let mut store = Store::new(&engine, State {});
    let module1 = Module::new(
        &engine,
        r#"
    (module
        (import "module2" "testfunc2" (func $testfunc2 (result i32) ) )
        (func $testfunc1 (result i32)
            i32.const 123
        )
        (export "testfunc1" (func $testfunc1))
    )
    "#
        .as_bytes(),
    )
    .unwrap();
    let module2 = Module::new(
        &engine,
        r#"
    (module
        (import "module1" "testfunc1" (func $testfunc1 (result i32) ) )
        (func $testfunc2 (result i32)
            call $testfunc1
        )
        (export "testfunc2" (func $testfunc2))
    )
    "#
        .as_bytes(),
    )
    .unwrap();
    linker.module(&mut store, "module1", &module1).unwrap();
    linker.module(&mut store, "module2", &module2).unwrap();
}

view this post on Zulip Wasmtime GitHub notifications bot (Feb 19 2023 at 17:49):

Officeyutong edited issue #5834:

For example, the following program panicked when linking the first module due to module2::testfunc2 not defined.

use wasmtime::{Engine, Linker, Module, Store};

struct State {}

fn main() {
    let engine = Engine::default();
    let mut linker = Linker::new(&engine);
    let mut store = Store::new(&engine, State {});
    let module1 = Module::new(
        &engine,
        r#"
    (module
        (import "module2" "testfunc2" (func $testfunc2 (result i32) ) )
        (func $testfunc1 (result i32)
            i32.const 123
        )
        (export "testfunc1" (func $testfunc1))
    )
    "#
        .as_bytes(),
    )
    .unwrap();
    let module2 = Module::new(
        &engine,
        r#"
    (module
        (import "module1" "testfunc1" (func $testfunc1 (result i32) ) )
        (func $testfunc2 (result i32)
            call $testfunc1
        )
        (export "testfunc2" (func $testfunc2))
    )
    "#
        .as_bytes(),
    )
    .unwrap();
    linker.module(&mut store, "module1", &module1).unwrap();
    linker.module(&mut store, "module2", &module2).unwrap();
}

view this post on Zulip Wasmtime GitHub notifications bot (Feb 19 2023 at 18:48):

pchickey commented on issue #5834:

Cyclic imports are not possible with the wasmtime Linker. You will need to break the cycle with some sort of trampoline. You can build one of these in pure wasm using tables, or you can use a native Func and some data in the Store to

view this post on Zulip Wasmtime GitHub notifications bot (Feb 19 2023 at 18:48):

pchickey closed issue #5834:

For example, the following program panicked when linking the first module due to module2::testfunc2 not defined.

use wasmtime::{Engine, Linker, Module, Store};

struct State {}

fn main() {
    let engine = Engine::default();
    let mut linker = Linker::new(&engine);
    let mut store = Store::new(&engine, State {});
    let module1 = Module::new(
        &engine,
        r#"
    (module
        (import "module2" "testfunc2" (func $testfunc2 (result i32) ) )
        (func $testfunc1 (result i32)
            i32.const 123
        )
        (export "testfunc1" (func $testfunc1))
    )
    "#
        .as_bytes(),
    )
    .unwrap();
    let module2 = Module::new(
        &engine,
        r#"
    (module
        (import "module1" "testfunc1" (func $testfunc1 (result i32) ) )
        (func $testfunc2 (result i32)
            call $testfunc1
        )
        (export "testfunc2" (func $testfunc2))
    )
    "#
        .as_bytes(),
    )
    .unwrap();
    linker.module(&mut store, "module1", &module1).unwrap();
    linker.module(&mut store, "module2", &module2).unwrap();
}

view this post on Zulip Wasmtime GitHub notifications bot (Feb 19 2023 at 18:48):

pchickey reopened issue #5834:

For example, the following program panicked when linking the first module due to module2::testfunc2 not defined.

use wasmtime::{Engine, Linker, Module, Store};

struct State {}

fn main() {
    let engine = Engine::default();
    let mut linker = Linker::new(&engine);
    let mut store = Store::new(&engine, State {});
    let module1 = Module::new(
        &engine,
        r#"
    (module
        (import "module2" "testfunc2" (func $testfunc2 (result i32) ) )
        (func $testfunc1 (result i32)
            i32.const 123
        )
        (export "testfunc1" (func $testfunc1))
    )
    "#
        .as_bytes(),
    )
    .unwrap();
    let module2 = Module::new(
        &engine,
        r#"
    (module
        (import "module1" "testfunc1" (func $testfunc1 (result i32) ) )
        (func $testfunc2 (result i32)
            call $testfunc1
        )
        (export "testfunc2" (func $testfunc2))
    )
    "#
        .as_bytes(),
    )
    .unwrap();
    linker.module(&mut store, "module1", &module1).unwrap();
    linker.module(&mut store, "module2", &module2).unwrap();
}

view this post on Zulip Wasmtime GitHub notifications bot (Feb 19 2023 at 18:48):

pchickey edited a comment on issue #5834:

Cyclic imports are not possible with the wasmtime Linker. You will need to break the cycle with some sort of trampoline. You can build one of these in pure wasm using tables, or you can use a native Func and some data in the Store. (Sorry to close, fat finger)

view this post on Zulip Wasmtime GitHub notifications bot (Feb 20 2023 at 06:28):

Officeyutong commented on issue #5834:

Cyclic imports are not possible with the wasmtime Linker. You will need to break the cycle with some sort of trampoline. You can build one of these in pure wasm using tables, or you can use a native Func and some data in the Store. (Sorry to close, fat finger)

I'll use a native Func and Store, thank you!

view this post on Zulip Wasmtime GitHub notifications bot (Feb 20 2023 at 06:28):

Officeyutong closed issue #5834:

For example, the following program panicked when linking the first module due to module2::testfunc2 not defined.

use wasmtime::{Engine, Linker, Module, Store};

struct State {}

fn main() {
    let engine = Engine::default();
    let mut linker = Linker::new(&engine);
    let mut store = Store::new(&engine, State {});
    let module1 = Module::new(
        &engine,
        r#"
    (module
        (import "module2" "testfunc2" (func $testfunc2 (result i32) ) )
        (func $testfunc1 (result i32)
            i32.const 123
        )
        (export "testfunc1" (func $testfunc1))
    )
    "#
        .as_bytes(),
    )
    .unwrap();
    let module2 = Module::new(
        &engine,
        r#"
    (module
        (import "module1" "testfunc1" (func $testfunc1 (result i32) ) )
        (func $testfunc2 (result i32)
            call $testfunc1
        )
        (export "testfunc2" (func $testfunc2))
    )
    "#
        .as_bytes(),
    )
    .unwrap();
    linker.module(&mut store, "module1", &module1).unwrap();
    linker.module(&mut store, "module2", &module2).unwrap();
}


Last updated: Nov 22 2024 at 16:03 UTC