Skip to content

Generate the WASI interface from witx.#136

Merged
sunfishcode merged 13 commits intowasi_snapshot_preview1from
sunfish_snapshot_1
Nov 22, 2019
Merged

Generate the WASI interface from witx.#136
sunfishcode merged 13 commits intowasi_snapshot_preview1from
sunfish_snapshot_1

Conversation

@sunfishcode
Copy link
Copy Markdown
Member

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

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.
@alexcrichton
Copy link
Copy Markdown
Collaborator

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)

Copy link
Copy Markdown
Member

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to make sense.. surly __WASI maros don't belong in the "unmodified" section?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, see my answer above.

@@ -0,0 +1,2569 @@
/**
* THIS FILE IS AUTO-GENERATED!
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By whom? Where I go if I want to modify it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now added a patch to add more information here.

@sunfishcode
Copy link
Copy Markdown
Member Author

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.

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?

@sbc100
Copy link
Copy Markdown
Member

sbc100 commented Nov 20, 2019

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 WebAssembly/wasi .. one can imagine generators for many different languages in there, as we already have a president of rust tooling in that repo.

@sunfishcode
Copy link
Copy Markdown
Member Author

The <wasi/api.h> header is hard-wired into the tool right now, plus __WASI_ names, and some workarounds for WASI-specific issues. Witx will also actively evolving and will require this tool to change to better support eg. modularity, which will also require coordination with libc code. In the future it'll be a more general tool, but there's work to do before we get there.

@pchickey
Copy link
Copy Markdown
Collaborator

pchickey commented Nov 20, 2019

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 witx crate in the WebAssembly/wasi repo, versus consuming those changes over here.

I like Alex's suggestion to point to WebAssembly/wasi as a submodule, and have scripts that re-generate these headers and check that they are unchanged in CI. If we do that, it would make sense to depend on witx by path.

@sunfishcode
Copy link
Copy Markdown
Member Author

@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.

@sbc100
Copy link
Copy Markdown
Member

sbc100 commented Nov 20, 2019

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.

@sbc100
Copy link
Copy Markdown
Member

sbc100 commented Nov 20, 2019

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.

@alexcrichton
Copy link
Copy Markdown
Collaborator

@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:

  • If you're only changing the generator, a PR shows that
  • If all you're doing is updating the submodule, a PR shows that
  • It's always clear where the header file is being generated from
  • CI can be used to ensure that the generated code is, well, always generated

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.
@sunfishcode
Copy link
Copy Markdown
Member Author

@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 cargo run auto-regenerates the header`.

@alexcrichton
Copy link
Copy Markdown
Collaborator

👍

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.

Comment thread tools/wasi-headers/Cargo.toml Outdated
[dependencies]
clap = "2"
heck = "0.3.1"
witx = "0.5.0"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A path dependency to witx is appropriate now that we're tracking WASI as a submodule, imo.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense; done.

Copy link
Copy Markdown
Collaborator

@pchickey pchickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@sunfishcode
Copy link
Copy Markdown
Member Author

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.

@sunfishcode sunfishcode merged commit 31bea9c into wasi_snapshot_preview1 Nov 22, 2019
@sunfishcode sunfishcode deleted the sunfish_snapshot_1 branch November 22, 2019 03:46
@sunfishcode sunfishcode restored the sunfish_snapshot_1 branch November 22, 2019 04:38
sunfishcode added a commit that referenced this pull request Nov 22, 2019
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants