Stream: general

Topic: ✔ Import from other .wit file


view this post on Zulip Xe Iaso (May 19 2025 at 15:04):

Oh, my expectation was that .wit files were kinda like protobuf files in that you can just have them mutually import eachother and have a "bank" of shared APIs, each with different packages.

EG:

wit
└── techaro
    ├── logger.wit // package techaro:logger
    └── wasm-checker.wit // package techaro:wasm-checker

Is this not really designed for the monorepo case where you have a big generic library full of stuff and then your components reach into and pull from part of that?

Your example for simple WIT reuse is something I wish was in the docs because I didn't know where to put the files in order to make things Just Work:tm:. Is there a way to do this that doesn't involve having to make symlink farms for deps folders?

view this post on Zulip Ramon Klass (May 19 2025 at 15:10):

if you have a monorepo with lots of separate packages, a wit/ directory that has no wit files but only a deps/ directory with all named packages is fine too, then everything in your repo can refer to worlds by their package names

view this post on Zulip Xe Iaso (May 19 2025 at 15:13):

you can refer to the world by the full legal package name?

view this post on Zulip Xe Iaso (May 19 2025 at 15:14):

reading https://docs.rs/wit-bindgen/latest/wit_bindgen/macro.generate.html#options-to-generate doesn't give me the impression you can do that

view this post on Zulip Xe Iaso (May 19 2025 at 15:15):

putting in techaro:wasm-checker/checker works

view this post on Zulip Ramon Klass (May 19 2025 at 15:16):

yes you can refer to worlds with their full path for your use case :)

view this post on Zulip Xe Iaso (May 19 2025 at 15:17):

moving everything to a deps folder makes wit-bindgen break:

wit
└── deps
    ├── techaro:logger
       └── logger.wit
    └── techaro:wasm-checker
        └── wasm-checker.wit
$ cargo build --target wasm32-unknown-unknown --release
   Compiling is-modern-browser v0.1.0 (/Users/cadey/Code/Techaro/hivemind/wasm/is-modern-browser)
error: failed to resolve directory while parsing WIT for path [/Users/cadey/Code/Techaro/hivemind/wit]

       Caused by:
         failed to parse package: /Users/cadey/Code/Techaro/hivemind/wit

       Caused by:
         no `package` header was found in any WIT file for this package
 --> wasm/is-modern-browser/src/lib.rs:5:1
  |
5 | / wit_bindgen::generate!({
6 | |     world: "techaro:wasm-checker/checker",
7 | |     path: "../../wit",
8 | |     generate_all,
9 | | });
  | |__^

view this post on Zulip Ramon Klass (May 19 2025 at 15:18):

oh I thought that was fixed, your wit/ needs to define a package name which can just be package unused:unused; which is not intended, a wit directory purely with deps in it is supposed to be fine

view this post on Zulip Xe Iaso (May 19 2025 at 15:19):

ah, i see, that makes it work

view this post on Zulip Notification Bot (May 19 2025 at 15:26):

Xe Iaso has marked this topic as resolved.

view this post on Zulip Xe Iaso (May 19 2025 at 15:42):

https://github.com/bytecodealliance/wit-bindgen/pull/1299 filed a docs PR

This nudge would have saved me some time in trying to figure out how to share .wit interfaces between components in a monorepo.

Last updated: Dec 06 2025 at 05:03 UTC