Skip to content

cc,wasi: support WASI reactors via -mexec-model flag#8978

Closed
mathetake wants to merge 11 commits intoziglang:cc-wasm32-wasi-emulationsfrom
mathetake:cc-wasi-execmodel
Closed

cc,wasi: support WASI reactors via -mexec-model flag#8978
mathetake wants to merge 11 commits intoziglang:cc-wasm32-wasi-emulationsfrom
mathetake:cc-wasi-execmodel

Conversation

@mathetake
Copy link
Copy Markdown

@mathetake mathetake commented Jun 3, 2021

Based on this patch to LLVM (https://reviews.llvm.org/D62922). This partially resolves (only for zig cc) #6757

@mathetake mathetake mentioned this pull request Jun 3, 2021
@mathetake mathetake force-pushed the cc-wasi-execmodel branch from a3b05d4 to de2875e Compare June 4, 2021 06:19
@kubkon kubkon added arch-wasm 32-bit and 64-bit WebAssembly os-wasi WebAssembly System Interface zig cc Zig as a drop-in C compiler feature enhancement Solving this issue will likely involve adding new logic or components to the codebase. labels Jun 7, 2021
@kubkon kubkon added this to the 0.9.0 milestone Jun 7, 2021
Copy link
Copy Markdown
Member

@kubkon kubkon left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I've got a couple of suggestions that when we address, I'm sure we'll be able to merge this change no problem.

Comment thread src/Compilation.zig Outdated
Comment thread src/wasi_libc.zig Outdated
@mathetake mathetake changed the title [wip] cc,wasi: support WASI reactors via -mexec-model flag cc,wasi: support WASI reactors via -mexec-model flag Jun 7, 2021
@mathetake mathetake marked this pull request as ready for review June 7, 2021 14:01
@mathetake
Copy link
Copy Markdown
Author

OK so I verified this works as expected locally.

@mathetake mathetake requested a review from kubkon June 7, 2021 14:01
kubkon and others added 8 commits June 7, 2021 16:38
This commit includes emulated libc sublibs that were not included
in the compilation and caching of WASI libc that ships with Zig.
The libs include (emulated): process clocks, getpid, mman, and signal.

With this change, it is now possible to successfully cross-compile
`wasm3` engine to WASI with `zig cc`.

For the future though, it might be worth considering splitting WASI
libc into libc-proper and modularised emulated libs as it is done
in upstream, and then have them included only if the user specifically
requests emulation/parts of it.
This replicates the expected behavior when using `clang` with
upstream `wasi-libc` sysroot: linking emulated subcomponents
such as process clocks or signals requires an explicit link flag
in the compiler invocation, for example:

```
zig cc -target wasm32-wasi -lwasi-emulated-process-clocks main.c -o main.wasm
```
Move parsing of system libs into `main.zig` next to where we decide
if we should link libC, and, if targeting WASI, if the specified
libname equals one of the emulated components, save it on the side
and remove it from the system libs. Then, build *only* those parts
of WASI libc that were preserved in the previous step.

This also fixes building of different crt1 bits needed to support
reactors and commands.
Do not try to link WASI libc or emulated subcomponents when not
targeting WASI; e.g., when targeting `wasm32-freestanding`.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
@mathetake mathetake force-pushed the cc-wasi-execmodel branch from e32a1a0 to 7d37709 Compare June 8, 2021 00:17
@mathetake mathetake changed the base branch from master to cc-wasm32-wasi-emulations June 8, 2021 00:17
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
@mathetake
Copy link
Copy Markdown
Author

@kubkon ok now rebased and added a necessary commit for checking in command/reactor crt (a2b2044). PTAL!

Comment thread src/Compilation.zig Outdated
Comment thread src/link.zig
Comment thread src/Compilation.zig
Comment thread src/main.zig Outdated
Comment thread src/link/Wasm.zig Outdated
mathetake added 2 commits June 8, 2021 13:41
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Copy link
Copy Markdown
Member

@kubkon kubkon left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for working on this @mathetake!

@kubkon
Copy link
Copy Markdown
Member

kubkon commented Jun 8, 2021

BTW once #8992 lands, I'll merge this one next.

@mathetake
Copy link
Copy Markdown
Author

@kubkon Thanks for the review! Much appreciated, and I learned a lot from your suggestions:)

@kubkon kubkon force-pushed the cc-wasm32-wasi-emulations branch from 910b6f4 to 2ee1f78 Compare June 8, 2021 23:26
@kubkon kubkon closed this Jun 9, 2021
@kubkon kubkon deleted the branch ziglang:cc-wasm32-wasi-emulations June 9, 2021 07:52
@kubkon
Copy link
Copy Markdown
Member

kubkon commented Jun 9, 2021

OK Github, why the heck did you close this PR?!

@kubkon
Copy link
Copy Markdown
Member

kubkon commented Jun 9, 2021

@mathetake would you mind reopening the PR?

@kubkon
Copy link
Copy Markdown
Member

kubkon commented Jun 9, 2021

Or I can try merging your branch manually on the command line, let's see...

@mathetake
Copy link
Copy Markdown
Author

OK, let me reopen!

@kubkon
Copy link
Copy Markdown
Member

kubkon commented Jun 9, 2021

OK, let me reopen!

Don't worry about conflicts, I'll take care of them while merging.

@mathetake
Copy link
Copy Markdown
Author

#9052 here you go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm 32-bit and 64-bit WebAssembly enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-wasi WebAssembly System Interface zig cc Zig as a drop-in C compiler feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants