Skip to content

Rust-import/Wasmtime-export: Examples of using multiple modules together #292

Closed
@philpax

Description

@philpax

If I have a common.wit:

record entity-id {
    namespace: u8,
    id: u64,
    gen: s32,
}

record vec3 {
    x: float32,
    y: float32,
    z: float32,
}

and an entity.wit:

use { entity-id, vec3 } from common

entity-spawn: func(object-ref: string, position: vec3) -> option<entity-id>

What is the correct way to consume these? The naive approach of

wit_bindgen_rust::import!("src/common.wit");
wit_bindgen_rust::import!("src/entity.wit");

results in entity::EntityId being a different type to common::EntityId. Looking around, I think I have to do something with Opts, but I'm not sure how to drive that.

With that being said, I've had a look around the repository, and found these issues:

which suggest that the use system is still very much a work in progress. Based on that, I've just rolled all of my definitions into a single wit and am modularising them manually within the guest. Should I continue doing that for the meantime?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions