Skip to content

Allow path expansion/modification for the deps directory in generate! #1675

Open

Description

@mkatychev

Feature

allow wit_bindgen::generate! (and wasmtime::bindgen!) to link a dependency tree that is not a sibling path to the root WIT package to be generated:

bindgen!({
    world: "foo",
    path: "other/path/to/wit",
    deps: "path/to/foo/dir/deps", // behaves as "other/path/to/wit/dir"
    // ...
});

Benefit

This would allow aggregation of dependency trees for multiple packages that share different directories

Implementation

Likely u directory association inside of bindgen! wasmtime::Config

Alternatives

Symlinking, this is not supported on windows 😢

Activity

  1. nonik0 commented on Jul 30, 2026

    @nonik0

    Also additionally allowing the provided path and/or potentially deps paths to expand to allow the use of env vars to encapsulate the "path expansion" part of this issue. This would make referencing shared deps between components more robust through the use of env vars in the provided paths, rather than relying on relative paths that could break or absolute paths that are not portable.

  2. added
    gen-rustRelated to bindings for Rust-compiled-to-WebAssembly
    on Jul 30, 2026
  3. celarye commented on Sep 21, 2026

    @celarye

    My first instinct was for a feature like this as well, but what if you have multiple packages across different directories where:

    1. They require one or more shared dependencies.
    2. Each require their own unique dependencies alongside the shared ones.

    I can think of two ways to solve this use case:

    1. Support pointing to multiple deps directories.
    2. Support pointing to specific paths for specific dependencies.

    Either way, I am willing to start with implementing mkatychev's feature request for now. Both for wit-bindgen and wasmtime's bindgen!.

  4. celarye commented on Sep 22, 2026

    @celarye

    I've managed to get something working, it's used as:

    wit_bindgen::generate!({ path: "../wit", deps: "../wit-deps" });

    I made it so the deps path is not relative to the WIT path.


    I had to go and update the wit-parser crate (hosted in the wasm-tools repo) for this as the deps subdirectory was hardcoded there. Afterwards I updated wit-bindgen's rust and rust-guest crates to add a deps option to the macro and use the updated wit-parser crate. I have not yet looked into adding support to other wit-bindgen crates or wasmtime.

    In the end the required changes seem to be minimal but the size/depth of these crates is quite large so I am not sure which dependents all would need to change. I'll look into making a PR in the wasm-tools repo first and will go from there.

  5. mkatychev commented on Sep 22, 2026

    @mkatychev
    MemberAuthor

    Thanks for taking a crack at this!

    1. They require one or more shared dependencies.
    2. Each require their own unique dependencies alongside the shared ones.

    Ideally this should be solved my a package manager like wkg to allow it to deal with this. Ideally I'd like the generated deps to live in OUT_DIR so that the dependency tree can be resolved in an isolated space for each possible union/disjoint case.

  6. celarye commented on Sep 23, 2026

    @celarye

    As in a single global shared dependency directory?

    Iirc wkg only auto downloads and writes to {wit_path}/deps at this moment. I guess having that support a deps directory parameter would be nice as well.

  7. mkatychev commented on Sep 23, 2026

    @mkatychev
    MemberAuthor

    @celarye it's a bit more flexible now; disclaimer: I'm a wkg maintainer. With the addition of wkg workspaces in the last release, I am looking at having a shared deps directory for one or more wit files.

    This will involve resolving version conflicts between separate packages in a workspace but ultimately I want to avoid duplicating dependency trees each time bindgen! or generate! is called.

  8. celarye commented on Sep 23, 2026

    @celarye

    … but ultimately I want to avoid duplicating dependency trees each time bindgen! or generate! is called.

    That’s the reason I want this as well yeah.

    Nice that you’re a wkg maintainer, I use wasm-pkg-client in my own project and should probably get around to making some feature requests for it 😁.

  9. celarye commented on Sep 24, 2026

    @celarye
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    gen-rustRelated to bindings for Rust-compiled-to-WebAssembly

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions