Skip to content

Commit 859a7ea

Browse files
authored
Parse wit folder in generate! with inline (#1356)
* Parse `wit` folder in `generate!` with `inline` This commit updates handling of the `inline` attribute in the `generate!` macro of the Rust bindings generator. Previously if `inline` was specified it would by default lookup nothing on the filesystem unless `path` was specified. This contradicts the documentation though that `./wit` is the default lookup path. To resolve this this commit adds a check to see if `./wit` exists, and if so parses it. This keeps the default search path behavior without requiring its existence when using `inline`. * Fix compile
1 parent 92cca96 commit 859a7ea

File tree

1 file changed

+13
-3
lines changed
  • crates/guest-rust/macro/src

1 file changed

+13
-3
lines changed

crates/guest-rust/macro/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,25 @@ fn parse_source(
251251
}
252252
Ok(())
253253
};
254+
let default = root.join("wit");
254255
match source {
255256
Some(Source::Inline(s, path)) => {
256-
if let Some(p) = path {
257-
parse(p)?;
257+
match path {
258+
Some(p) => parse(p)?,
259+
// If no `path` is explicitly specified still parse the default
260+
// `wit` directory if it exists. Don't require its existence,
261+
// however, as `inline` can be used in lieu of a folder. Test
262+
// whether it exists and only if there is it parsed.
263+
None => {
264+
if default.exists() {
265+
parse(&[default])?;
266+
}
267+
}
258268
}
259269
pkgs.push(resolve.push_group(UnresolvedPackageGroup::parse("macro-input", s)?)?);
260270
}
261271
Some(Source::Paths(p)) => parse(p)?,
262-
None => parse(&vec![root.join("wit")])?,
272+
None => parse(&[default])?,
263273
};
264274

265275
Ok((resolve, pkgs, files))

0 commit comments

Comments
 (0)