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

Use clang + wasi-sdk instead of emcc to compile to WASM #1235

Closed
paulcadman opened this issue May 13, 2022 · 0 comments
Closed

Use clang + wasi-sdk instead of emcc to compile to WASM #1235

paulcadman opened this issue May 13, 2022 · 0 comments
Assignees
Labels
Milestone

Comments

@paulcadman
Copy link
Collaborator

paulcadman commented May 13, 2022

clang supports wasm{32,64}-unknown-unknown and wasm{32,64}-unknown-wasi compilation targets. And the WebAssembly project provides a C toolchain that provides a libc for things like malloc, free, io etc..

For our use-case this seems like a better approach than emscripten (which is a project more focused on generating WASM/JS for browser runtime).

The goal of this issue is to get the minic tests running in CI with clang compiler.

Setup WASM cross compilation toolchain

wasi-sdk publishes precompiled releases of the wasm toolchain. The libclang_rt.builtins-wasm32-wasi-15.0.tar.gz archive should be extracted in the clang installation root (e.g /usr/lib/clang/14 on Ubuntu). And the wasi-sysroot-15.0.tar.gz archive can be extracted anywhere locally.

Clang can then be used as follows:

clang-14 -nodefaultlibs -lc --target=wasm32-wasi --sysroot /home/ubuntu/wasi-sysroot hello.c -o hello.wasm

Where /home/ubuntu/wasi-sysroot is the path where the sysroot archive was extracted to.

-nodefaultlibs -lc is important here because (on ubuntu, perhaps other linux systems) clang passes -lc -lgcc to the linker by default (and gcc lib is not available in the wasm sysroot).

@paulcadman paulcadman self-assigned this May 13, 2022
@cwgoes cwgoes transferred this issue from another repository Jul 13, 2022
@janmasrovira janmasrovira added this to the 0.1.4 milestone Jul 14, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants