Last active
April 11, 2020 00:35
-
-
Save shiningjason/ddb9502a5d238f6c2838ffcfcb991f2f to your computer and use it in GitHub Desktop.
Build WebAssembly with LLVM/Clang/binaryen/wabt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ======================= | |
| # 1. Clone and build LLVM | |
| # ======================= | |
| # /> | |
| gcc -v | |
| make -v | |
| cmake --version | |
| brew install cmake | |
| xcode-select --install | |
| git clone https://github.com/llvm-mirror/llvm.git | |
| cd ./llvm/tools | |
| # /llvm/tools> | |
| git clone https://github.com/llvm-mirror/clang.git | |
| mkdir ../../llvm-build | |
| cd ../../llvm-build | |
| # /llvm-build> | |
| cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=../llvm-wasm \ | |
| -DLLVM_TARGETS_TO_BUILD= \ | |
| -DLLVM_TARGET_ARCH=wasm32 \ | |
| -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly \ | |
| ../llvm | |
| make -j8 && make install | |
| # =========================== | |
| # 2. Clone and build binaryen | |
| # =========================== | |
| # /> | |
| git clone https://github.com/WebAssembly/binaryen.git | |
| cd ./binaryen | |
| # /binaryen> | |
| cmake . && make | |
| # ======================= | |
| # 3. Clone and build wabt | |
| # ======================= | |
| # /> | |
| git clone https://github.com/WebAssembly/wabt.git --recursive | |
| cd wabt | |
| # /wabt> | |
| make | |
| # ======================== | |
| # 4. Compile C/C++ to wasm | |
| # ======================== | |
| # /project> | |
| /llvm-build/bin/clang -S -O3 --target=wasm32 -c module.cpp -o module.s | |
| # ps. use https://github.com/guybedford/wasm-stdlib-hack to import stdlib | |
| /binaryen/bin/s2wasm module.s -s 524288 -o module.wast | |
| # ps. use --import-memory options to share memory from js to wabt | |
| /wabt/out/clang/Debug/wast2wasm module.wast -o module.wasm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment