Skip to content

[rust] bindgen path supports env!() macro#1569

Open
kvcache wants to merge 1 commit intobytecodealliance:mainfrom
kvcache:manifest
Open

[rust] bindgen path supports env!() macro#1569
kvcache wants to merge 1 commit intobytecodealliance:mainfrom
kvcache:manifest

Conversation

@kvcache
Copy link

@kvcache kvcache commented Mar 13, 2026

This makes it possible to refer to a wit path by a path that includes
things like OUT_DIR or CARGO_MANIFEST_DIR. Relative paths that navigate
up, like ../wit/, don't work well with cargo publish, and symlinks
have difficulties between git and cargo.

Using macro-string, this replaces the path option's syn::LitStr with MacroString.

See the example crates/guest-rust/src/examples/_5_import_directory.rs for
how this can be used. I need this capability so I can write separate crates for
a partially inter-related set of WIT's without having to copy/paste the whole
WIT tree for each package.

Before: error: expected string literal
After: Example 5 compiles.

This makes it possible to refer to a wit path by a path that includes
things like OUT_DIR or CARGO_MANIFEST_DIR. Relative paths that navigate
up, like `../wit/`, don't work well with cargo publish, and symlinks
have difficulties between git and cargo.

Using [macro-string](https://github.com/dtolnay/macro-string), this
replaces the `path` option's `syn::LitStr` with MacroString.
@kvcache
Copy link
Author

kvcache commented Mar 14, 2026

For context, this is the expression I'm able to compile locally with this change:

wit_bindgen::generate!({
    world: "momento:bytes/imports",
    path: [ concat!(env!("OUT_DIR"), "/wit/host") ],
});

kvcache added a commit to kvcache/functions that referenced this pull request Mar 14, 2026
The workspace folders aren't accessible at publish or docs.rs time.
Pulling the wits into OUT_DIR makes them accessible to bindgen
during those build phases.

Depends on: bytecodealliance/wit-bindgen#1569
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant