Skip to content

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

Merged
alexcrichton merged 4 commits intobytecodealliance:mainfrom
kvcache:manifest
Mar 16, 2026
Merged

[rust] bindgen path supports env!() macro#1569
alexcrichton merged 4 commits intobytecodealliance:mainfrom
kvcache:manifest

Conversation

@kvcache
Copy link
Contributor

@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
Contributor 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
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Would it be ok to place this behind a Cargo feature as well since it's an optional dependency. Perhaps an on-by-default optional feature?

gates the macro-string dependency on the new default feature macro-string.
@kvcache
Copy link
Contributor Author

kvcache commented Mar 16, 2026

Thanks! Would it be ok to place this behind a Cargo feature as well since it's an optional dependency. Perhaps an on-by-default optional feature?

Thanks @alexcrichton, I added this as a default-on feature. I'm not sure why someone would disable it but the affordance is there now!

@kvcache kvcache requested a review from alexcrichton March 16, 2026 19:20
@alexcrichton
Copy link
Member

Thanks! Can you also edit this dependency to disable default features, and then also configure the default features on the wit-bindgen crate as well? Most users don't depend on the macro crate directly but instead only indirectly though the wit-bindgen crate.

@kvcache
Copy link
Contributor Author

kvcache commented Mar 16, 2026

@alexcrichton I think I got the feature lifted to wit-bindgen now, but I'm not the most experienced with cargo features. I also merged main, because github couldn't automatically figure out the line diff in cargo.toml with the 0.54.0 update.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@alexcrichton alexcrichton added this pull request to the merge queue Mar 16, 2026
Merged via the queue into bytecodealliance:main with commit ffbf78c Mar 16, 2026
28 checks passed
@kvcache kvcache deleted the manifest branch March 16, 2026 21:45
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.

2 participants