Skip to main content

Build Guide

Please follow this guide to build and test WasmEdge from the source code.

note

For a development build, download the artifact for your platform from a successful Core workflow run on master.

What Will Be Built​

WasmEdge provides various tools for enabling different runtime environments for optimal performance. You can find that there are several wasmedge related tools:

  1. wasmedge is the general wasm runtime.

    • wasmedge executes a WASM file in the interpreter mode or a compiled WASM file in the ahead-of-time compilation mode.
    • To disable building all tools, you can set the CMake option WASMEDGE_BUILD_TOOLS to OFF.
  2. wasmedgec is the ahead-of-time WASM compiler.

    • wasmedgec compiles a general WASM file into a compiled WASM file.
    • Set WASMEDGE_USE_LLVM=OFF to omit wasmedgec and disable LLVM-based AOT and JIT compilation.
    note

    The usage of wasmedgec is equal to wasmedge compile. We decide to deprecate wasmedgec in the future.

  3. libwasmedge.so is the WasmEdge C API shared library. (libwasmedge.dylib on MacOS and wasmedge.dll on Windows)

    • libwasmedge.so, libwasmedge.dylib, or wasmedge.dll provides the C API for the ahead-of-time compiler and the WASM runtime.
    • With WASMEDGE_USE_LLVM=OFF, WasmEdge_CompilerCreate() returns NULL.
    • To omit the shared library, set WASMEDGE_BUILD_SHARED_LIB=OFF and either disable the tools or enable WASMEDGE_LINK_TOOLS_STATIC.

CMake Building Options​

Developers can set the CMake options to customize the WasmEdge building.

  1. WASMEDGE_BUILD_TESTS: build the WasmEdge tests. Default is OFF.
  2. WASMEDGE_USE_LLVM: build with LLVM-based runtime for supporting Ahead-of-Time and Just-In-Time compiler. Default is ON.
  3. WASMEDGE_BUILD_SHARED_LIB: build the WasmEdge shared library (libwasmedge.so, libwasmedge.dylib, or wasmedge.dll). Default is ON.
    • By default, the WasmEdge shared library will link to the LLVM shared library.
  4. WASMEDGE_BUILD_STATIC_LIB: build the WasmEdge static library (libwasmedge.a, Linux and MacOS platforms, experimental). Default is OFF.
    • If this option is set as ON, the option WASMEDGE_FORCE_DISABLE_LTO will forcefully be set as ON.
    • If this option is set as ON, the libz and libtinfo on Linux platforms will be statically linked.
    • For linking with libwasmedge.a, developers should also add the -ldl, -pthread, -lm, and -lstdc++ linker options on both Linux and MacOS platforms, and -lrt on Linux platforms.
  5. WASMEDGE_BUILD_TOOLS: build the wasmedge and wasmedgec tools. Default is ON.
    • The wasmedge and wasmedgec tools will link to the WasmEdge shared library by default.
    • If this option is set as ON and WASMEDGE_USE_LLVM is set as OFF, the wasmedgec tool for the AOT compiler will not be built.
    • If this option is set as ON but the option WASMEDGE_LINK_TOOLS_STATIC is set as OFF, the option WASMEDGE_BUILD_SHARED_LIB will forcefully be set as ON.
    • If this option and the option WASMEDGE_LINK_TOOLS_STATIC are both set as ON, the WASMEDGE_LINK_LLVM_STATIC and WASMEDGE_BUILD_STATIC_LIB will both be set as ON, and the wasmedge and wasmedgec tools will link to the WasmEdge static library instead. In this case, the plug-ins will not work in tools.
  6. WASMEDGE_BUILD_PLUGINS: build the WasmEdge plug-ins. Default is ON.
  7. WASMEDGE_BUILD_EXAMPLE: build the WasmEdge examples. Default is OFF.
  8. WASMEDGE_FORCE_DISABLE_LTO: forcefully turn off the link time optimization. Default is OFF.
  9. WASMEDGE_LINK_LLVM_STATIC: link the LLVM and lld libraries statically (Linux and MacOS platforms only). Default is OFF.
  10. WASMEDGE_LINK_TOOLS_STATIC: make the wasmedge and wasmedgec tools to link the WasmEdge library and LLVM libraries statically (Linux and MacOS platforms only). Default is OFF.
    • If the option WASMEDGE_BUILD_TOOLS and this option are both set as ON, the WASMEDGE_LINK_LLVM_STATIC will be set as ON.
  11. WASMEDGE_ENABLE_UB_SANITIZER: enable the undefined behavior sanitizer. Default is OFF.
  12. WASMEDGE_PLUGIN_WASI_NN_BACKEND: build the WasmEdge WASI-NN plug-in with the selected backends. Supported platforms depend on the backend. Default is empty.
    • This option is useless if the option WASMEDGE_BUILD_PLUGINS is set as OFF.
    • To build the WASI-NN plug-in with backend, please use -DWASMEDGE_PLUGIN_WASI_NN_BACKEND=<backend_name>.
    • For multiple backends, pass a quoted CMake list, for example -DWASMEDGE_PLUGIN_WASI_NN_BACKEND="GGML;Whisper".
  13. WASMEDGE_PLUGIN_WASI_CRYPTO: build the WasmEdge WASI-Crypto plug-in (Linux and MacOS platforms only). Default is OFF.
    • This option is useless if the option WASMEDGE_BUILD_PLUGINS is set as OFF.
  14. WASMEDGE_PLUGIN_WASI_LOGGING: reserved CMake option. WASI-Logging is built into the WasmEdge library.
  15. WASMEDGE_PLUGIN_WASM_BPF: build the WasmEdge wasm_bpf plugin (Linux platforms only). Default is OFF.
    • This option is useless if the option WASMEDGE_BUILD_PLUGINS is set as OFF.
  16. WASMEDGE_PLUGIN_IMAGE: build the WasmEdge image plugin (Linux and MacOS platforms only). Default is OFF.
    • This option is useless if the option WASMEDGE_BUILD_PLUGINS is set as OFF.
  17. WASMEDGE_PLUGIN_TENSORFLOW: build the WasmEdge TensorFlow plugin (Linux and MacOS platforms only). Default is OFF.
    • This option is useless if the option WASMEDGE_BUILD_PLUGINS is set as OFF.
  18. WASMEDGE_PLUGIN_TENSORFLOWLITE: build the WasmEdge TensorFlow-Lite plug-in (Linux and MacOS platforms only). Default is OFF.
    • This option is useless if the option WASMEDGE_BUILD_PLUGINS is set as OFF.
note

The build uses the system blake3 library when it is available, and falls back to the vendored copy otherwise. Developers can set -DCMAKE_DISABLE_FIND_PACKAGE_blake3=ON to force the vendored copy. When the option WASMEDGE_BUILD_STATIC_LIB is set as ON, the vendored copy is always used.

Build WasmEdge with Plug-ins​

Developers can follow the steps to build WasmEdge with plug-ins from source.

Run Tests​

The tests are only available when the build option WASMEDGE_BUILD_TESTS is set to ON.

Users can use these tests to verify the correctness of WasmEdge binaries built.

cd <path/to/wasmedge/build_folder>
LD_LIBRARY_PATH=$(pwd)/lib/api ctest