wasmer icon indicating copy to clipboard operation
wasmer copied to clipboard

Auto-generate wasi-types from .wit files

Open fschutt opened this issue 2 years ago • 2 comments

Fixes #2972.

Supersedes #3150.

fschutt avatar Sep 07 '22 11:09 fschutt

Instead of doing your code generation as part of a build.rs script, you might want to consider moving it elsewhere so you don't impact build times. It's also generally considered bad manners for build scripts to change files outside of $OUT_DIR (I think cargo will warn you about this when you try to publish).

The rust-analyzer project uses a pattern where they'll generate the code in-memory during a test and compare that to whatever is on disk. If the generated code has changed, the files are immediately updated and the test is failed with a message like "generated.rs was out of date. Please commit the updated files and re-run this test". That way you can't accidentally merge outdated files because CI will fail.

Here is an example where I use the pattern in one of my projects:

https://github.com/Michael-F-Bryan/scad-rs/blob/4dbff0c30ce991105f1e649e678d68c2767e894b/crates/codegen/src/syntax/mod.rs#L15-L32

Michael-F-Bryan avatar Sep 08 '22 06:09 Michael-F-Bryan

@syrusakbary okay, tests are finally passing, but I wouldn't merge it just yet because I'd need to review whether the old types are the same as the new ones esp. for ones marked #[repr(u16)]

fschutt avatar Sep 15 '22 19:09 fschutt

Currently we can't merge this because of https://github.com/bytecodealliance/wit-bindgen/issues/323

@syrusakbary There are only a few types that are repr(u16), I'll just backport them, so that we can merge this PR.

EDIT: This is fixed now.

fschutt avatar Sep 26 '22 11:09 fschutt