[rust] bindgen path supports env!() macro#1569
[rust] bindgen path supports env!() macro#1569alexcrichton merged 4 commits intobytecodealliance:mainfrom
Conversation
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.
|
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") ],
}); |
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
alexcrichton
left a comment
There was a problem hiding this comment.
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.
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! |
|
Thanks! Can you also edit this dependency to disable default features, and then also configure the default features on the |
|
@alexcrichton I think I got the feature lifted to |
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 symlinkshave difficulties between git and cargo.
Using macro-string, this replaces the
pathoption'ssyn::LitStrwith MacroString.See the example
crates/guest-rust/src/examples/_5_import_directory.rsforhow 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 literalAfter: Example 5 compiles.