-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support to parse WIT files from multiple paths #1003
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
crates/guest-rust/src/lib.rs
Outdated
/// // Usually used in testing, our test suite may want to generate code | ||
/// // from wit files located in multiple paths within a single mod, and we | ||
/// // don't want to copy these files again. | ||
/// paths: ["../path/to/wit1", "../path/to/wit2"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a new key for this could this syntax be folded into the previous key? For example path: "..."
or path: [...]
would be supported
tests/runtime/paths/wasm.rs
Outdated
@@ -0,0 +1,12 @@ | |||
wit_bindgen::generate!({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a runtime test for this is pretty heavyweight and not much runtime functionality is tested here, so could this be added to crates/rust/tests/*
instead?
crates/guest-rust/macro/src/lib.rs
Outdated
let (pkg, sources) = resolve.push_path(normalized_path)?; | ||
files.extend(sources); | ||
Ok(pkg) | ||
let mut parse = |paths: &Vec<String>| -> anyhow::Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be &[PathBuf]
instead of &Vec<String>
? That keeps the type-level annotation that these are paths and additionally avoids the dance of into_os_string().into_string().unwrap()
below too
Thanks for the review, All comments addressed, PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Background information reference: bytecodealliance/wasmtime#8939 (comment)
This patch allows us to parse WIT files from multiple paths, which is often useful in testing. We can unify all the generated code into a single mod. For example, for Wasmtime's case, we can do it like this:
before:
after:
I am not familiar with the whole process of wit parsing, so I am not sure if there will be any side effects of doing this. I have tested the wasmtime case locally and it does work.
cc @alexcrichton