Skip to content
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

[NativeAOT-LLVM] Enable support for WASI SDK #1850

Closed
wants to merge 18 commits into from

Conversation

yowl
Copy link
Contributor

@yowl yowl commented Feb 8, 2022

This PR adds support for linking with the WASI SDK to enable opening of files on WASI hosts, e.g. wasmtime.

I'm changing the build property EmccExtraArgs to WasmExtraLinkerArgs as it only applies at the linking step and now applies to both Emscripten and Wasi SDK.

Adding build property WasmWasi to indicate that the build is for WASI, this turns off some unsupported Emscripten features, exceptions mainly.

Adding build property WasiSdkPath (which implies WasmWasi). This causes the linking to be done by the Wasi SDK, and hence links the WASI SDK libc which has good support for WASI.

Added a hack to get around the fact that we compile the runtime with emscripten's headers, but use libc from the WASI SDK where some constants are different. I'm using the FileOptions to set a bit to indicate "when opening files, use the WASI SDK constants". I did think about adding new enum values to other parameters to new FileStream but that breaks the ABI checks. To use this hack, the user code would be:

            using (var fs = new FileStream("/tmp/direction", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 4096, (FileOptions)0x20000000))

WIP as not sure this is a good idea. wasi-libc originates from cloudlibc which has the different constants: Emscripten and musl are the same. The alternative fix here would be to not use the libc file operations at all, but to straight to the wasi calls. That would mean that running in Emscripten would not work as WASI in Emscripten is a WIP.

Updated the documentation.

Follows #1848

@jkotas jkotas added the area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly) label Nov 14, 2022
@ChristianWeyer
Copy link

Do you know what the current state of this effort is @yowl ? Thanks!

@yowl
Copy link
Contributor Author

yowl commented Dec 16, 2022

What I did here was a hack really to workaround different c header constants in the different libc(s).

There's maybe at least 2 ways to go forward with this

  1. Create a package that continues to use libc, but built against the libc in the WASI SDK (as opposed to emscripten)
  2. Do not use libc where WASI itself supplies the ABI, go straight to the WASI call (This is the recommendation I got from the Wasi SDK people - https://groups.google.com/g/emscripten-discuss/c/a97HaictQLo last comment). Also requires another package.

So the state of the effort is that the IT problem is understood (I think!) , but the human time problem is harder to solve!

@yowl
Copy link
Contributor Author

yowl commented May 6, 2023

Closing this one in favour of #2268

@yowl yowl closed this May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants