Goal: built mlir-opt through emscripten to run it interactively from documentation websites.
References:
- Install
emsdk
: https://emscripten.org/docs/getting_started/downloads.html - Read https://emscripten.org/docs/compiling/Building-Projects.html
- LLVM cross compilation: https://llvm.org/docs/HowToCrossCompileLLVM.html
- LLVM CMake options: https://llvm.org/docs/CMake.html
Notes:
- All commands are run from
llvm-project
root directory (~/code/llvm-project/
on my Linux machine) - Tested with LLVM at https://github.com/llvm/llvm-project/commit/fcc57558783b12de7a7d2cea809f72705ea849b4
- Tested with emsdk at https://github.com/emscripten-core/emsdk/commit/2e7eaf7233144e5e25b1c1338890bbab5d011815
- Tested with
cmake version 3.18.4
with clang 11 on Linux (Debian) after first trying on Windows with MSVC
Set up emsdk
following those docs (run source ./emsdk_env.sh
)
Build host tools to ./build/
:
cmake -G Ninja -B ./build/ -DLLVM_ENABLE_PROJECTS=mlir -DCMAKE_BUILD_TYPE=Release llvm/.
cmake --build ./build/ --target mlir-opt
(Could also build without --target
)
Configure for emscripten to ./build-emscripten/
.
Note: we want to use the host tablegen and other tools throughout the build. Emscripten or LLVM creates a NATIVE/
folder
and tries to run tools from there... but the "executable binaries" in that directory are JavaScript files... which obviously can't be executed in a shell environment.
emcmake cmake -G Ninja -B ./build-emscripten/ -DLLVM_ENABLE_PROJECTS=mlir -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./install-emscripten/ -DLLVM_TABLEGEN=$PWD/build/bin/llvm-tblgen -DMLIR_TABLEGEN_EXE=$PWD/build/bin/mlir-tblgen -DLLVM_TOOLS_BINARY_DIR=$PWD/build/bin/ -Wno-dev llvm/.
** weird stuff happens here **
try building:
cmake --build ./build-emscripten --target mlir-opt
see errors about llvm-tblgen, mlir-tblgen, etc.
copy from host build to NATIVE/
folder:
cp ./build/bin/llvm-tblgen ./build-emscripten/NATIVE/bin && chmod +x build-emscripten/NATIVE/bin/llvm-tblgen
cp ./build/bin/mlir-tblgen ./build-emscripten/NATIVE/bin && chmod +x build-emscripten/NATIVE/bin/mlir-tblgen
cp ./build/bin/mlir-linalg-ods-gen ./build-emscripten/NATIVE/bin && chmod +x build-emscripten/NATIVE/bin/mlir-linalg-ods-gen
cp ./build/bin/mlir-linalg-ods-yaml-gen ./build-emscripten/NATIVE/bin && chmod +x build-emscripten/NATIVE/bin/mlir-linalg-ods-yaml-gen
try building again:
cmake --build ./build-emscripten --target mlir-opt
success ?
ls -la build-emscripten/bin
(should have mlir-opt.js and mlir-opt.wasm, among other files)