Bug 1571559 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

This task tracks the progress of including the clang compiler toolchain to build wasm libraries in the Firefox build system. This task will enable allow the compilation of components to produce a wasm file compatible with wasi.

There are 2 approaches to do this
1. Include a prebuilt release of clang+wasm+wasi released as part of cranelift work [here](https://github.com/CraneStation/wasi-sdk/releases). I believe this clang defaults to wasm target and the wasi libc by default, so this clang with no additional flags or arguments.
2. Build from source. The details to build are provided below. When built from source, we have to pass some extra flags (listed below) as part of the command line invocation of clang.

** Building from source **
1. Get source code for stock clang and llvm 8 (needed for wasm backend). 
2. Get the llvm lld linker from [here](https://github.com/llvm-mirror/lld.git) and include it in the tools folder of llvm. lld will now be built along with clang.
3. clang would have to be configured with the CMAKE flag `LLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly`  to enable the wasm backend (as clang does not include this by default).
4. Build clang
5. Get the wasi sysroot - i.e. libc implementation that is wasm compatible from [here](https://github.com/CraneStation/wasi-libc)
6. Build the wasi sysroot with the clang that was compiled in step 4 (more details available on the sysroot readme).

Files can now be compiled with 
```
clang -B$(PATH_TO_LLD) --target=wasm32-wasi --sysroot $(PATH_TO_WASI_SYSROOT) -Wl,--export-all <normal args to clang...>
```
This task tracks the progress of including the clang compiler toolchain to build wasm libraries in the Firefox build system. This task will enable allow the compilation of components to produce a wasm file compatible with wasi.

There are 2 approaches to do this
1. Include a prebuilt release of clang+wasm+wasi released as part of cranelift work [here](https://github.com/CraneStation/wasi-sdk/releases). I believe this clang defaults to wasm target and the wasi libc by default, so this clang with no additional flags or arguments.
2. Build from source. The details to build are provided below. When built from source, we have to pass some extra flags (listed below) as part of the command line invocation of clang.

**Building from source**
1. Get source code for stock clang and llvm 8 (needed for wasm backend). 
2. Get the llvm lld linker from [here](https://github.com/llvm-mirror/lld.git) and include it in the tools folder of llvm. lld will now be built along with clang.
3. clang would have to be configured with the CMAKE flag `LLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly`  to enable the wasm backend (as clang does not include this by default).
4. Build clang
5. Get the wasi sysroot - i.e. libc implementation that is wasm compatible from [here](https://github.com/CraneStation/wasi-libc)
6. Build the wasi sysroot with the clang that was compiled in step 4 (more details available on the sysroot readme).

Files can now be compiled with 
```
clang -B$(PATH_TO_LLD) --target=wasm32-wasi --sysroot $(PATH_TO_WASI_SYSROOT) <normal args to clang...>
```
This task tracks the progress of including the clang compiler toolchain to build wasm libraries in the Firefox build system. This task will enable allow the compilation of components to produce a wasm file compatible with wasi.

There are 2 approaches to do this
1. Include a prebuilt release of clang+wasm+wasi released as part of cranelift work [here](https://github.com/CraneStation/wasi-sdk/releases). I believe this clang defaults to wasm target and the wasi libc by default, so this clang can be used as normal, requiring no additional flags or arguments.
2. Build from source. The details to build are provided below. When built from source, we have to pass some extra flags (listed below) as part of the command line invocation of clang.

**Building from source**
1. Get source code for stock clang and llvm 8 (needed for wasm backend). 
2. Get the llvm lld linker from [here](https://github.com/llvm-mirror/lld.git) and include it in the tools folder of llvm. lld will now be built along with clang.
3. clang would have to be configured with the CMAKE flag `LLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly`  to enable the wasm backend (as clang does not include this by default).
4. Build clang
5. Get the wasi sysroot - i.e. libc implementation that is wasm compatible from [here](https://github.com/CraneStation/wasi-libc)
6. Build the wasi sysroot with the clang that was compiled in step 4 (more details available on the sysroot readme).

Files can now be compiled with 
```
clang -B$(PATH_TO_LLD) --target=wasm32-wasi --sysroot $(PATH_TO_WASI_SYSROOT) <normal args to clang...>
```

Back to Bug 1571559 Comment 0