Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: Support a more terse form of with-based remapping #840

Open
alexcrichton opened this issue Feb 14, 2024 · 4 comments
Open

rust: Support a more terse form of with-based remapping #840

alexcrichton opened this issue Feb 14, 2024 · 4 comments
Labels
gen-rust Related to bindings for Rust-compiled-to-WebAssembly

Comments

@alexcrichton
Copy link
Member

Currently with works by operating at the interface level, requiring a specification such as:

generate!({
    with: {
        "pkg:foo/bar": path::to::module,
    }
});

This can get cumbersome for a suite of packages, however:

generate!({
    with: {
        "pkg:a/b1": ...,
        "pkg:a/b2": ...,
        "pkg:a/b3": ...,
        "pkg:b/b1": ...,
        "pkg:b/b2": ...,
        "pkg:c/b1": ...,
        ...
    }
});

I've seen this come up in the context of WASI where a bunch of WASI interfaces are referenced but the types to use should come from somewhere else. Especially with the wasi crate nowadays I think it should be easier to use the wasi crate wholesale. I'm imagining something like:

generate!({
    with: {
        "wasi": wasi, // refers to `wasi`-the-crate
    }
});

I'm also thinking you could do:

generate!({
    with: {
        "wasi:cli": wasi::cli,
        "wasi:io": wasi::io,
    }
});

Where the general idea is that of the "path" that's pkg:a/b you could start chopping off pieces from the right and generate pkg:a and pkg. Both cases would be considered as covering all "children" of those namespaces, meaning that if pkg:a were specified then any interface in the pkg:a package would use the with key for pkg:a. The projections from that key would use the standard naming scheme that wit-bindgen already uses.

Ideally I'd like to see this ported to the wasmtime::component::bindgen! macro eventually too.

@alexcrichton alexcrichton added the gen-rust Related to bindings for Rust-compiled-to-WebAssembly label Feb 14, 2024
@sehz
Copy link

sehz commented Feb 15, 2024

It would be good if component:bindgen and maybe wasmtime would allow pass-thru configuration to wit-bindgen

@alexcrichton
Copy link
Member Author

Could you clarify what you mean @sehz? I'm not sure I understand what you mean by pass-thru. Do you mean that the same configuration of wasmtime::component::bindgen! whould work for wit_bindgen::generate!?

@sehz
Copy link

sehz commented Feb 16, 2024

I guess what I am looking for is parity between component:bindgen and wit_bindgen:generate.

@alexcrichton
Copy link
Member Author

Ah ok makes sense! I definitely agree that this work should go into Wasmtime as well when completed

alexcrichton added a commit to alexcrichton/wasmtime that referenced this issue Mar 12, 2024
This commit implements bytecodealliance/wit-bindgen#840 for Wasmtime.
Currently `with` keys to bindgen only support either mapping resources
or interfaces. Now they additionally support mapping entire packages or
entire namespaces. This can help clean up some references to interfaces
through our own bindings to avoid listing all of them.
alexcrichton added a commit to alexcrichton/wasmtime that referenced this issue Mar 12, 2024
This commit implements bytecodealliance/wit-bindgen#840 for Wasmtime.
Currently `with` keys to bindgen only support either mapping resources
or interfaces. Now they additionally support mapping entire packages or
entire namespaces. This can help clean up some references to interfaces
through our own bindings to avoid listing all of them.
github-merge-queue bot pushed a commit to bytecodealliance/wasmtime that referenced this issue Mar 12, 2024
This commit implements bytecodealliance/wit-bindgen#840 for Wasmtime.
Currently `with` keys to bindgen only support either mapping resources
or interfaces. Now they additionally support mapping entire packages or
entire namespaces. This can help clean up some references to interfaces
through our own bindings to avoid listing all of them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gen-rust Related to bindings for Rust-compiled-to-WebAssembly
Projects
None yet
Development

No branches or pull requests

2 participants