Generate the WASI interface from witx.#136
Generate the WASI interface from witx.#136sunfishcode merged 13 commits intowasi_snapshot_preview1from
Conversation
This replaces the hand-maintained <wasi/core.h> header with a <wasi/api.h> generated from witx. Most of the churn here is caused by upstream WASI renamings; hopefully in the future ABI updates will be less noisy.
|
Would it make sense to include a submodule and/or reference to the wasi repo, and then check that the generated code matches the reference on CI? (to ensure that if the reference is changed and/or the generator the generated code is updated as well) |
sbc100
left a comment
There was a problem hiding this comment.
In general looks great! Very excited to see this.
I'm not totally convinced the tool for generating the header should live in this repo. Although I don't have any great ideas for a better place for it. At least maybe we can discuses that separately? How would you feel about splitting this change such that tool is a separate PR that we can discuses. The actual libc change LGTM as is so no need to block that.
| #include <fcntl.h> | ||
| #include <string.h> | ||
|
|
||
| #ifdef __wasilibc_unmodified_upstream // fstat |
There was a problem hiding this comment.
This doesn't seem to make sense.. surly __WASI maros don't belong in the "unmodified" section?
There was a problem hiding this comment.
It's a special case, and I agree it's confusing. The policy is documented at the bottom of this README.md. The idea was, we'd allow CLOUDABI_ -> __WASI_ renaming without #ifdef markers, because that's super common, and a mechanical change, so it's not interesting to track.
But, now that the witx file renamed a lot of things, it's becoming less obvious that this whole #ifdef scheme is still worthwhile. We dropped it for libpreopen; it may soon make sense to drop it for cloudlibc too.
| if (event->error == __WASI_EBADF) { | ||
| #else | ||
| if (event->error == __WASI_ERRNO_BADF) { | ||
| #endif |
There was a problem hiding this comment.
Yeah I guess what happen is that these blocks must have be modified without being tagged. So mabye the "unmodified" blocmk should still have clound abi macros (presumably that is what the original had)?
There was a problem hiding this comment.
Yeah, see my answer above.
| @@ -0,0 +1,2569 @@ | |||
| /** | |||
| * THIS FILE IS AUTO-GENERATED! | |||
There was a problem hiding this comment.
By whom? Where I go if I want to modify it?
There was a problem hiding this comment.
I've now added a patch to add more information here.
I agree, but I also don't have great ideas for a better place for it in its current form. It's specific to wasi-libc, and still pretty experimental. What would you think of leaving it here for now, but re-evaluating it after it's settled into its role a little? |
|
Isn't it C-specific rather then wasi-libc specific? i.e. wasi-libc is just one way to build something useful on C on top of this C header file? But I guess this is will at least the primary consumer. I can maybe see this living in |
|
The <wasi/api.h> header is hard-wired into the tool right now, plus |
|
I agree that this repo seems like the best place for this tool to live for now. We will want a bit of flexibility about merging changes into the I like Alex's suggestion to point to |
|
@alexcrichton @pchickey git submodules are pinned to a specific revision, so I'm unclear on the purpose of setting them up with scripts to check that the generated files are unchanged. |
|
I guess the idea would be that you would roll the wasi submodule and in the same PR see the updated headers files and also ensure the header generator is in sync the the witx parser.. although actually it looks like you are pinning that dependency via crates.io and via submodule. |
|
I'm not gonna block this PR if you guys think this is the right place for it. We can revisit later if needed. I'm not huge fan of having rust tooling spread everywhere like this (mostly because its not my personal lingua fanca, but also because its also not the lingua fanca of C toolchain maintainers in general). But I'm not offering any alternatives right now. |
|
@sunfishcode I was thinking of something like https://github.com/bytecodealliance/wasi/tree/master/crates/generate-raw where with a submodule here we'd get benefits like:
This isn't really critical, though, just something I've seen that's a good way to head off future headaches. Not really a blocker at all though. I haven't though too much how this fits into the general versioning story for wasi in general (and its evolving interfaces over time). |
Also, add the witx filenames to the generated output, and just have `cargo run` auto-generate the api.h header, rather than using clap.
a156442 to
07355b4
Compare
|
@alexcrichton That's a good idea. I've now added a WASI submodule, which isn't needed unless you want to re-generate the header, and running |
|
👍 The only other thing I'd do here is to hook this up to CI to fail CI if the generated code in the repository is different than what the generator generates, but that's pretty minor. |
| [dependencies] | ||
| clap = "2" | ||
| heck = "0.3.1" | ||
| witx = "0.5.0" |
There was a problem hiding this comment.
A path dependency to witx is appropriate now that we're tracking WASI as a submodule, imo.
pchickey
left a comment
There was a problem hiding this comment.
Good to go once CI is passing
Most editors these days can deal with eof=lf files, even on Windows, and this avoids trouble with headers and other generated files differing in line endings.
029de46 to
e984164
Compare
|
The CI is now passing, at the cost of making git checkout text files with unix-style line endings on Windows. It would also be possible to make the diff ignore line-ending differences, but with text=lf, we don't need that, we avoid trouble with people running the generator tool on Windows and getting crlf/lf diffs, and we eliminate some line-ending differences in the generated sysroot too. |
* Add the WASI repo as a submodule. Also, add the witx filenames to the generated output, and just have `cargo run` auto-generate the api.h header, rather than using clap. * Switch witx to a path dependency. * Add a test. * Add a test that the generated file is in sync with the generator. * Enable CI testing with Github Actions. * Fix the name of the wasi-headers directory. * Enable submodules. * Add a diff mechanism to help explain failures. * Sort the inputs for display. * More debugging. * More debugging. * Add a .gitattributes file forcing text files to be eol=lf. Most editors these days can deal with eof=lf files, even on Windows, and this avoids trouble with headers and other generated files differing in line endings.
This replaces the hand-maintained <wasi/core.h> header with a
<wasi/api.h> generated from witx.
Most of the churn here is caused by upstream WASI renamings; hopefully
in the future ABI updates will be less noisy.
@cjihrig This obviates #135, and I hope it'll be a more robust approach as the API continues to evolve.
@pchickey