Skip to content

Latest commit

 

History

History
907 lines (615 loc) · 56.2 KB

build_wamr.md

File metadata and controls

907 lines (615 loc) · 56.2 KB

Build WAMR vmcore

WAMR vmcore is the runtime library set that loads and runs Wasm modules. This guide walks you through building the WAMR vmcore.

References:

building configurations

Include the script runtime_lib.cmake from build-scripts into your CMakeLists.txt to pull vmcore into your build:

include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})

Then make three decisions, in this order:

  1. The running mode. The WAMR Interpreter and AOT must be enabled at least one of them: WAMR_BUILD_INTERP for the interpreter (add WAMR_BUILD_FAST_INTERP to use the fast interpreter instead of the classic one), WAMR_BUILD_AOT for AOT, and WAMR_BUILD_FAST_JIT / WAMR_BUILD_JIT for the JIT modes. See Configure interpreters, Configure AOT, Configure Fast JIT and Configure LLVM JIT. The platform comes along with it: set WAMR_BUILD_PLATFORM when it cannot be derived from the host.

  2. The feature switches. All switches are listed in All compilation flags below, and each switch has its own section.

  3. The order. Every WAMR_BUILD_xxx assignment must come before include (runtime_lib.cmake), and that includes the running mode and the platform. runtime_lib.cmake includes config_common.cmake at its end, and that file fills in the defaults, derives the dependent switches and turns the switches into the -DWASM_ENABLE_xxx compiler macros. A switch that is assigned after the include is not seen by any of that logic.

Here is a minimum workable example that shows the order:

cmake_minimum_required (VERSION 3.14)
project (iwasm_embed LANGUAGES C)

set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wamr)

# 1. The running mode, and the platform if it is not the default
set (WAMR_BUILD_PLATFORM "linux")
set (WAMR_BUILD_INTERP 1)

# 2. Any other switch, still before the include
set (WAMR_BUILD_SIMD 1)

# 3. Pull the vmcore in
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
add_library (vmlib ${WAMR_RUNTIME_LIB_SOURCE})
# Wrong: the assignment happens after config_common.cmake already ran, so
# WASM_ENABLE_SIMD is not defined by this value
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
set (WAMR_BUILD_SIMD 1)

The same rule applies to the product-mini platform files and to the top-level CMakeLists.txt: a switch that a platform assigns after its runtime_lib.cmake include overrides the derived value without going through the defaults, the derived switches or the unsupported_combination.cmake checks. The Wasm specification presets WAMR_BUILD_WASM_SPEC1/2/3 are ordinary switches in this respect. The switches can also be passed on the cmake command line instead of a CMakeLists.txt.

All compilation flags

Compilation flags Description
WAMR_APP_THREAD_STACK_SIZE_MAX Maximum stack size for app threads
WAMR_BH_LOG Host defined logging
WAMR_BH_VPRINTF Host defined vprintf
WAMR_BUILD_ALLOC_WITH_USAGE Allocation with usage tracking
WAMR_BUILD_ALLOC_WITH_USER_DATA Allocation with user data
WAMR_BUILD_AOT AoT compilation(wamrc)
WAMR_BUILD_AOT AoT runtime
WAMR_BUILD_AOT_INTRINSICS AoT intrinsics
WAMR_BUILD_APP_FRAMEWORK legacy app framework
WAMR_BUILD_AOT_STACK_FRAME AoT stack frame
WAMR_BUILD_AOT_VALIDATOR AoT validator
WAMR_BUILD_BASE_LIB legacy base lib
WAMR_BUILD_BULK_MEMORY bulk memory
WAMR_BUILD_COPY_CALL_STACK copy call stack
WAMR_BUILD_CUSTOM_NAME_SECTION name section
WAMR_BUILD_DEBUG_AOT debug AoT
WAMR_BUILD_DEBUG_INTERP debug interpreter
WAMR_BUILD_DUMP_CALL_STACK dump call stack
WAMR_BUILD_DYNAMIC_AOT_DEBUG dynamic AoT debugging
WAMR_BUILD_EXCE_HANDLING exception handling
WAMR_BUILD_EXTENDED_CONST_EXPR extended constant expressions
WAMR_BUILD_FAST_INTERP fast interpreter
WAMR_BUILD_FAST_JIT fast JIT
WAMR_BUILD_FAST_JIT_DUMP fast JIT dump
WAMR_BUILD_GC garbage collection
WAMR_BUILD_GC_HEAP_VERIFY garbage collection heap verification
WAMR_BUILD_GC_HEAP_SIZE_DEFAULT default garbage collection heap size
WAMR_BUILD_GLOBAL_HEAP_POOL global heap pool
WAMR_BUILD_GLOBAL_HEAP_SIZE global heap size
WAMR_BUILD_INSTRUCTION_METERING instruction metering
WAMR_BUILD_INTERP interpreter
WAMR_BUILD_INVOKE_NATIVE_GENERAL FFI general
WAMR_BUILD_JIT JIT compilation
WAMR_BUILD_LAZY_JIT lazy JIT compilation
WAMR_BUILD_LIBC_BUILTIN libc builtin functions
WAMR_BUILD_LIBC_EMCC libc emcc compatibility
WAMR_BUILD_LIBC_UVWASI libc uvwasi compatibility
WAMR_BUILD_LIBC_WASI wasi libc
WAMR_BUILD_LIB_PTHREAD pthread library
WAMR_BUILD_LIB_PTHREAD_SEMAPHORE pthread semaphore support
WAMR_BUILD_LIB_RATS RATS library
WAMR_BUILD_LIB_WASI_THREADS wasi threads
WAMR_BUILD_LINUX_PERF Linux performance counters
WAMR_BUILD_LIME1 LIME1 runtime
WAMR_BUILD_LOAD_CUSTOM_SECTION loading custom sections
WAMR_BUILD_LOG log system
WAMR_BUILD_MEMORY64 memory64 support
WAMR_BUILD_MEMORY_PROFILING memory profiling
WAMR_BUILD_MEMORY_TRACING memory tracing
WAMR_BUILD_MINI_LOADER ⚠️ ❗ mini loader
WAMR_BUILD_MODULE_INST_CONTEXT module instance context
WAMR_BUILD_MULTI_MEMORY multi-memory support
WAMR_BUILD_MULTI_MODULE multi-module support
WAMR_BUILD_OPCODE_COUNTER opcode counter
WAMR_BUILD_PERF_PROFILING performance profiling
WAMR_BUILD_PLATFORM Default platform
WAMR_BUILD_QUICK_AOT_ENTRY quick AOT entry
WAMR_BUILD_REF_TYPES reference types
WAMR_BUILD_SANITIZER sanitizer
WAMR_BUILD_SGX_IPFS Intel Protected File System support
WAMR_BUILD_SHARED_HEAP shared heap
WAMR_BUILD_SHARED_MEMORY shared memory
WAMR_BUILD_SHRUNK_MEMORY shrunk memory
WAMR_BUILD_SIMD SIMD support
WAMR_BUILD_SIMDE SIMD E extensions
WAMR_BUILD_FUZZ_TEST fuzz test mode
WAMR_BUILD_SPEC_TEST spec test
WAMR_BUILD_WORD_ALIGN_READ word aligned read
WAMR_BUILD_STACK_GUARD_SIZE Stack guard size
WAMR_BUILD_STATIC_PGO Static PGO
WAMR_BUILD_STRINGREF String reference support
WAMR_BUILD_TAIL_CALL Tail call optimization
WAMR_BUILD_TARGET Default target architecture
WAMR_BUILD_THREAD_MGR Thread manager
WAMR_BUILD_WAMR_COMPILER WAMR compiler
WAMR_BUILD_WASI_EPHEMERAL_NN WASI ephemeral NN
WAMR_BUILD_WASI_NN WASI NN
WAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH External delegate path for WASI NN
WAMR_BUILD_WASI_NN_ENABLE_GPU GPU support for WASI NN
WAMR_BUILD_WASI_NN_LLAMACPP LLAMA CPP for WASI NN
WAMR_BUILD_WASI_NN_ONNX ONNX for WASI NN
WAMR_BUILD_WASI_NN_OPENVINO OpenVINO for WASI NN
WAMR_BUILD_WASI_NN_TFLITE TFLite for WASI NN
WAMR_BUILD_WASM_CACHE WASM cache
WAMR_BUILD_WASM_SPEC1 Wasm 1.0 spec preset
WAMR_BUILD_WASM_SPEC2 Wasm 2.0 spec preset
WAMR_BUILD_WASM_SPEC3 Wasm 3.0 spec preset (unsupported)
WAMR_CONFIGURABLE_BOUNDS_CHECKS ⚠️ ❗ Configurable bounds checks
WAMR_DISABLE_APP_ENTRY Disable app entry
WAMR_DISABLE_HW_BOUND_CHECK Disable hardware bound check
WAMR_DISABLE_STACK_HW_BOUND_CHECK Disable stack hardware bound check
WAMR_DISABLE_WAKEUP_BLOCKING_OP Disable wakeup blocking operation
WAMR_DISABLE_WRITE_GS_BASE Disable write GS base
WAMR_TEST_GC Test garbage collection

Privileged Features ⚠️ ❗

Privileged Features are powerful options that can boost performance or add capabilities but lower security by compromising isolation. Use them with care and test thoroughly.

The compilation flags (WAMR_* CMake variables) are resolved in two steps. The top-level CMakeLists.txt of each build entry (and each product-mini platform file) sets each flag for its platform, including that entry's default; cmake -D changes the value it gives. config_common.cmake then applies the flag's own default when it is undefined, handles dependencies and derived values, and translates each flag into a compiler macro (-DWASM_ENABLE_*=1 or =0). For example, WAMR_BUILD_AOT turns on WASM_ENABLE_AOT, and enabling WAMR_BUILD_MEMORY64 also turns on WASM_DISABLE_HW_BOUND_CHECK/WASM_DISABLE_STACK_HW_BOUND_CHECK. config.h gives each macro a fallback default with #ifndef, for builds that do not go through build-scripts (for example NuttX wamr.mk, esp-idf, Zephyr). Every macro needs a default there, and code tests it with #if <MACRO> != 0. #ifdef, #ifndef and defined() are always true for a macro that is defined as 0, so code guarded that way never turns off. -Wundef reports a macro used in #if without a value.

Features enabled by default (platform-independent)

The defaults below are guaranteed by build-scripts itself (config_common.cmake and runtime_lib.cmake) when the vmcore is built through runtime_lib.cmake, regardless of platform — as long as the option is not explicitly set by the user. Defaults supplied by the top-level build entry (the repository root CMakeLists.txt or the product-mini platform files) are out of scope here and are covered by the note below.

On by default (unless disabled):

Compilation flag Corresponding macro Description
WAMR_BUILD_BULK_MEMORY WASM_ENABLE_BULK_MEMORY Bulk memory operations
WAMR_BUILD_SHRUNK_MEMORY WASM_ENABLE_SHRUNK_MEMORY Shrunk linear memory usage
WAMR_BUILD_BULK_MEMORY_OPT WASM_ENABLE_BULK_MEMORY_OPT Bulk-memory-opt; linked: auto-enabled via bulk memory (WAMR_BUILD_BULK_MEMORY, on by default)

Conditional defaults (auto-on only when the listed prerequisite is enabled; the prerequisites themselves are usually set by the top-level build entry):

Compilation flag Prerequisite Corresponding macro
WAMR_BUILD_CALL_INDIRECT_OVERLONG Reference types enabled (linked; WAMR_BUILD_REF_TYPES has no default inside build-scripts) WASM_ENABLE_CALL_INDIRECT_OVERLONG
WAMR_BUILD_LAZY_JIT LLVM JIT or fast JIT enabled WASM_ENABLE_LAZY_JIT
WAMR_BUILD_QUICK_AOT_ENTRY AOT or LLVM JIT enabled WASM_ENABLE_QUICK_AOT_ENTRY
WAMR_BUILD_AOT_INTRINSICS AOT enabled (LLVM JIT enables AOT implicitly) WASM_ENABLE_AOT_INTRINSICS
WAMR_BUILD_MODULE_INST_CONTEXT WASI libc (WAMR_BUILD_LIBC_WASI/WAMR_BUILD_LIBC_UVWASI) or WAMR_BUILD_WASI_NN enabled WASM_ENABLE_MODULE_INST_CONTEXT
WAMR_BUILD_WASI_EPHEMERAL_NN WAMR_BUILD_WASI_NN enabled WASM_ENABLE_WASI_EPHEMERAL_NN

Note

Feature flags without defaults inside build-scripts — for example WAMR_BUILD_INTERP, WAMR_BUILD_AOT, WAMR_BUILD_LIBC_BUILTIN, WAMR_BUILD_LIBC_WASI, WAMR_BUILD_SIMD, WAMR_BUILD_REF_TYPES (usually on), and WAMR_BUILD_JIT, WAMR_BUILD_FAST_JIT, WAMR_BUILD_MULTI_MODULE and friends (usually off) — get their defaults from the top-level build entry, such as the repository root CMakeLists.txt or the product-mini platform files. runtime_lib.cmake only forces some of them when the engine options require it: LLVM JIT forces AOT on, LLVM JIT/fast JIT force the classic interpreter on (WAMR_BUILD_INTERP=1, WAMR_BUILD_FAST_INTERP=0), and GC forces reference types on. Inside build-scripts itself, WAMR_BUILD_GC, WAMR_BUILD_MEMORY64, WAMR_BUILD_MULTI_MEMORY, WAMR_BUILD_SHARED_MEMORY, WAMR_BUILD_FAST_INTERP, WAMR_BUILD_TAIL_CALL, WAMR_BUILD_EXCE_HANDLING, WAMR_BUILD_EXTENDED_CONST_EXPR, and WAMR_BUILD_LIME1 default to off. Individual product-mini platforms may still override any of the defaults above.

A version preset does not track what an entry point ships: it turns off the switches its feature set excludes, even when an entry point enables them by default; see Wasm specification version preset. Fix such a default in the entry point that ships it, not in build-scripts.

Configure platform and architecture

  • WAMR_BUILD_PLATFORM: set the target platform. Match the platform folder name under core/shared/platform.

  • WAMR_BUILD_TARGET: set the target CPU architecture. Supported targets: X86_64, X86_32, AARCH64, ARM, THUMB, XTENSA, ARC, RISCV32, RISCV64, and MIPS.

    • For ARM and THUMB, use <arch>[<sub-arch>][_VFP]. <sub-arch> is the ARM sub-architecture. _VFP means arguments and returns use VFP coprocessor registers s0-s15 (d0-d7). Both are optional, for example ARMV7, ARMV7_VFP, THUMBV7, or THUMBV7_VFP.
    • For AARCH64, use <arch>[<sub-arch>]. VFP is on by default. <sub-arch> is optional, for example AARCH64, AARCH64V8, or AARCH64V8.1.
    • For RISCV64, use <arch>[_abi]. _abi is optional. Supported: RISCV64, RISCV64_LP64D, and RISCV64_LP64. RISCV64 and RISCV64_LP64D both use LP64D (LP64 with hardware floating-point for FLEN=64). RISCV64_LP64 uses LP64 (integer calling convention only; no hardware floating-point calling convention).
    • For RISCV32, use <arch>[_abi]. _abi is optional. Supported: RISCV32, RISCV32_ILP32D, RISCV32_ILP32F, and RISCV32_ILP32. RISCV32 and RISCV32_ILP32D both use ILP32D (ILP32 with hardware floating-point for FLEN=64). RISCV32_ILP32F uses ILP32F (ILP32 with hardware floating-point for FLEN=32). RISCV32_ILP32 uses ILP32 (integer calling convention only).
cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM

Configure interpreters

  • WAMR_BUILD_INTERP=1/0: turn the WASM interpreter on or off.

  • WAMR_BUILD_FAST_INTERP=1/0: pick the fast or the classic interpreter. build-scripts defaults it to 0, the classic interpreter; most build entries, including every product-mini platform, set it to 1.

Note

The fast interpreter runs ~2X faster than classic interpreter, but consumes about 2X memory to hold the pre-compiled code.

Enabling LLVM JIT or fast JIT, or the interpreter debugger (WAMR_BUILD_DEBUG_INTERP), forces the classic interpreter: WAMR_BUILD_FAST_INTERP is set to 0 automatically.

Configure AOT

  • WAMR_BUILD_AOT=1/0: turn AOT on or off. Defaults to on.
  • WAMR_BUILD_WAMR_COMPILER=1/0. It is used to wasm loader and compilation to indictate compiler mode.

Configure LLVM JIT

Comparing with fast JIT, LLVM JIT covers more architectures and produces better optimized code, but takes longer on cold start.

  • WAMR_BUILD_JIT=1/0: turn LLVM JIT on or off. Defaults to off.
  • WAMR_BUILD_LAZY_JIT=1/0: turn lazy JIT on or off. Derived from the running mode: on when LLVM JIT or fast JIT is enabled, off otherwise. Setting it explicitly overrides the derived value. With lazy JIT, functions are compiled in background threads before they are called, which can reduce startup time for large modules.

Configure Fast JIT

The fast JIT is a lightweight JIT that emits code quickly and tunes hot functions.

  • WAMR_BUILD_FAST_JIT=1/0: turn Fast JIT on or off. Defaults to off.
  • WAMR_BUILD_FAST_JIT_DUMP=1/0: dump fast JIT compiled code to stdout for debugging. Defaults to off.

Warning

It currently covers only a few architectures (x86_64).

Configure Multi-tier JIT

Use fast jit as the first tier and LLVM JIT as the second tier.

  • With WAMR_BUILD_FAST_JIT=1 and WAMR_BUILD_JIT=1, you get multi-tier JIT. Defaults to off.

Warning

It currently covers only a few architectures (x86_64).

Configure LIBC

  • WAMR_BUILD_LIBC_BUILTIN=1/0: build the built-in libc subset for WASM apps. Defaults to on.

  • WAMR_BUILD_LIBC_WASI=1/0: build the WASI libc subset for WASM apps. Defaults to on.

  • WAMR_BUILD_LIBC_UVWASI=1/0 (Experiment): build the WASI libc subset for WASM apps using uvwasi. Defaults to off.

  • WAMR_BUILD_LIBC_EMCC=1/0: build the emcc-compatible libc subset for WASM apps. Defaults to off.

Warning

WAMR is not a secure sandbox on every platform. On platforms where WAMR_BUILD_LIBC_WASI is unsupported (for example Windows), you can try the uvwasi-based WASI via WAMR_BUILD_LIBC_UVWASI, but it is unsafe.

Multi-Module feature

  • WAMR_BUILD_MULTI_MODULE=1/0, default to off.

Note

See Multiple Modules as Dependencies for details.

Warning

The multi-module feature is not supported in fast-jit or llvm-jit modes.

WASM mini loader

  • WAMR_BUILD_MINI_LOADER=1/0, default to off.

Note

The mini loader skips integrity checks on the WASM binary. Make sure the file is valid yourself.

Warning

This is a privileged feature that compromises security. Use it only when you trust the WASM binary source.

shared memory feature

  • WAMR_BUILD_SHARED_MEMORY=1/0, default to off.

bulk memory feature

  • WAMR_BUILD_BULK_MEMORY=1/0, default to on.

Note

Enabling bulk memory also turns on bulk-memory-opt (WAMR_BUILD_BULK_MEMORY_OPT).

memory64 feature

  • WAMR_BUILD_MEMORY64=1/0, default to off.

Warning

Supported only in classic interpreter mode and AOT mode. It requires a 64-bit target (the build configuration errors out otherwise) and automatically disables hardware-trap boundary checks (WAMR_DISABLE_HW_BOUND_CHECK).

thread manager

  • WAMR_BUILD_THREAD_MGR=1/0, default to off.

lib-pthread

  • WAMR_BUILD_LIB_PTHREAD=1/0, default to off.

Note

When you enable lib pthread, required features such as shared memory and thread manager are enabled automatically. See WAMR pthread library for details.

lib-pthread-semaphore

  • WAMR_BUILD_LIB_PTHREAD_SEMAPHORE=1/0, default to off.

Note

This depends on lib-pthread and turns it on automatically.

lib wasi-threads

  • WAMR_BUILD_LIB_WASI_THREADS=1/0, default to off.

Note

Enabling lib wasi-threads also enables its dependencies shared memory and thread manager. See wasi-threads and Introduction to WAMR WASI threads for details.

lib wasi-nn

  • WAMR_BUILD_WASI_NN=1/0, default to off.
  • WAMR_BUILD_WASI_NN_LLAMACPP=1/0, default to off.
  • WAMR_BUILD_WASI_NN_ONNX=1/0, default to off.
  • WAMR_BUILD_WASI_NN_OPENVINO=1/0, default to off.
  • WAMR_BUILD_WASI_NN_TFLITE=1/0, default to off.

Note

Using WAMR_BUILD_WASI_NN without WAMR_BUILD_WASI_EPHEMERAL_NN is deprecated and may be removed later. Please enable WAMR_BUILD_WASI_EPHEMERAL_NN too. See WASI-NN for details.

lib wasi-nn GPU mode

  • WAMR_BUILD_WASI_NN_ENABLE_GPU=1/0, default to off.

lib wasi-nn external delegate mode

  • WAMR_BUILD_WASI_NN_ENABLE_EXTERNAL_DELEGATE=1/0, default to off.

  • WAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH=Path to the external delegate shared library (for example libedgetpu.so.1.0 for Coral USB).

lib wasi-nn with wasi_ephemeral_nn module support

  • WAMR_BUILD_WASI_EPHEMERAL_NN=1/0, default to on.

Disable boundary check with hardware trap

  • WAMR_DISABLE_HW_BOUND_CHECK=1/0, default to on if the platform supports it. Otherwise, software boundary checks are used.

Note

By default only linux/darwin/android/windows/vxworks 64-bit platforms enable this hardware trap boundary check. On 32-bit platforms it is off even if the flag is 0. The wamrc tool omits boundary check instructions in AOT code for all 64-bit targets except SGX to improve speed. The boundary check covers linear memory access and native stack access unless WAMR_DISABLE_STACK_HW_BOUND_CHECK is set.

Disable native stack boundary check with hardware trap

  • WAMR_DISABLE_STACK_HW_BOUND_CHECK=1/0, default to on if the platform supports it; same rule as WAMR_DISABLE_HW_BOUND_CHECK. Otherwise, software boundary checks are used.

Note

If hardware trap boundary checks are off (or WAMR_DISABLE_HW_BOUND_CHECK is 1), native stack boundary checks are also off regardless of WAMR_DISABLE_STACK_HW_BOUND_CHECK. If hardware trap boundary checks are on, this setting decides whether the native stack check is on.

Disable async wakeup of blocking operation

  • WAMR_DISABLE_WAKEUP_BLOCKING_OP=1/0, default to on when the platform supports it.

Note

This feature lets blocking threads terminate asynchronously. If you disable it, blocking threads may never finish when asked to exit.

tail call feature

  • WAMR_BUILD_TAIL_CALL=1/0, default to off. Supported in classic-interpreter, fast-interpreter, AOT and LLVM JIT modes.

128-bit SIMD feature

  • WAMR_BUILD_SIMD=1/0, default to on.

SIMD is supported in AOT, LLVM JIT, and fast-interpreter modes. In fast-interpreter mode, SIMD operations are implemented with the SIMDe (SIMD Everywhere) library, which is fetched and enabled automatically — no extra flag is needed.

Warning

SIMD is not supported together with fast JIT, or with a classic-interpreter-only build (interpreter on, fast interpreter off, and no AOT/LLVM JIT); those combinations fail at configuration time. On RISCV64 targets SIMD is silently disabled.

SIMDe library for SIMD in fast interpreter

The SIMDe library is pulled in automatically when both WAMR_BUILD_SIMD and WAMR_BUILD_FAST_INTERP are enabled (except on Windows, where SIMDe is not supported). WAMR_BUILD_SIMDE/WAMR_BUILD_LIB_SIMDE are not user switches and do not need to be set.

Exception Handling

  • WAMR_BUILD_EXCE_HANDLING=1/0, default to off.

Note

Current implementation supports only Legacy Wasm exception handling proposal, not the latest version.

Warning

Exception handling currently works only in classic interpreter mode.

Garbage Collection

  • WAMR_BUILD_GC=1/0, default to off.
  • WAMR_BUILD_GC_HEAP_VERIFY=1/0, default to off. When enabled, verifies the heap during free.

Note

WAMR_BUILD_GC_VERIFY is a deprecated alias of this option. It still works and prints a cmake deprecation warning; use WAMR_BUILD_GC_HEAP_VERIFY instead.

  • WAMR_BUILD_STRINGREF=1/0, defaults to whatever WAMR_BUILD_GC is.
  • WAMR_STRINGREF_IMPL_SOURCE=STUB/<path>: the stringref implementation to link against, STUB for the builtin one. Defaults to STUB when stringref is on.

Note

GC, stringref and the stringref implementation are one chain: WAMR_BUILD_GC=1 is enough to get all three, and GC also enables reference types.

Each link can be turned off on its own (-DWAMR_BUILD_GC=1 -DWAMR_BUILD_STRINGREF=0 builds GC without stringref), but asking for a later link without its predecessor fails the configure step rather than silently turning the predecessor on: WAMR_BUILD_STRINGREF=1 with WAMR_BUILD_GC=0, or WAMR_STRINGREF_IMPL_SOURCE with WAMR_BUILD_STRINGREF=0.

Warning

Current implentation of Garbage Collection(GC) is not fully compliant with the Wasm GC proposal and Wasm 3.0 specification. There are still few known limitations:

  • exn and noexn types are not supported.
  • nested structs and arrays are not fully supported.

Garbage collection is not supported in fast-jit mode and multi-tier-jit mode.

Set the Garbage Collection heap size

  • WAMR_BUILD_GC_HEAP_SIZE_DEFAULT=n, default to 128 kB (131072).

Multi Memory

  • WAMR_BUILD_MULTI_MEMORY=1/0, default to off.

Warning

Multi memory is supported only in classic interpreter mode.

Name Section

  • WAMR_BUILD_CUSTOM_NAME_SECTION=1/0: load function names from the custom name section. Default is off.

AOT stack frame feature

  • WAMR_BUILD_AOT_STACK_FRAME=1/0, default to off.

Note

When enabled, AOT or JIT stack frames (similar to classic interpreter frames but storing only what is needed) are built during calls. Add --enable-dump-call-stack to wamrc when compiling AOT modules.

dump call stack feature

  • WAMR_BUILD_DUMP_CALL_STACK=1/0, default to off.

Note

When enabled, the runtime dumps the call stack on exceptions.

  • In interpreter mode, names come first from the custom name section. If that section is absent or disabled, names come from import/export sections.
  • In AOT/JIT mode, names come from the import/export section. Export as many functions as possible (for wasi-sdk you can use -Wl,--export-all) when compiling the wasm module, and add --enable-dump-call-stack --emit-custom-sections=name to wamrc when compiling the AOT module.

memory profiling (Experiment)

  • WAMR_BUILD_MEMORY_PROFILING=1/0, default to off.

Note

When enabled, call void wasm_runtime_dump_mem_consumption(wasm_exec_env_t exec_env) to dump memory usage. Currently only module, module_instance, and exec_env memory are measured; other components such as wasi-ctx, multi-module, and thread-manager are not included. See Memory usage estimation for a module.

memory tracing

  • WAMR_BUILD_MEMORY_TRACING=1/0, default to off.

Note

When enabled, detailed memory allocation and deallocation traces are printed at runtime, which is useful for debugging memory issues.

performance profiling (Experiment)

  • WAMR_BUILD_PERF_PROFILING=1/0, default to off.

Note

When enabled, call void wasm_runtime_dump_perf_profiling(wasm_module_inst_t module_inst) to dump per-function performance. Function name lookup follows the same order as the dump call stack feature. See Tune the performance of running wasm/aot file.

A pre-allocation for runtime and wasm apps

  • WAMR_BUILD_GLOBAL_HEAP_POOL=1/0, default to off for iwasm apps except on Alios and Zephyr.
  • WAMR_BUILD_GLOBAL_HEAP_SIZE=n, default to 10 MB (10485760) for iwasm apps, except Alios (256 kB), Riot (256 kB), and Zephyr (128 kB).

Note

When enabled, WAMR uses a big global heap for runtime and wasm apps instead of allocating memory from the system directly. This can reduce memory fragmentation and improve performance when many small allocations happen. The global heap is allocated at startup. WAMR_BUILD_GLOBAL_HEAP_POOL applies to iwasm apps in product-mini. For your own host app, set mem_alloc_type to Alloc_With_Pool if you want to use a global heap. The global heap is described in Memory model and memory usage tunning. WAMR_BUILD_GLOBAL_HEAP_SIZE applies to iwasm apps in product-mini. For your host app, set mem_alloc_option.pool with the size you want for the global heap. The global heap is described in Memory model and memory usage tunning.

Set maximum app thread stack size

  • WAMR_APP_THREAD_STACK_SIZE_MAX=n, default to 8 MB (8388608).

Note

AOT boundary checks with hardware traps may use large stacks because the OS can grow stacks lazily when a guard page is hit. Use this setting to cap total stack use, for example -DWAMR_APP_THREAD_STACK_SIZE_MAX=131072 (128 KB).

Host defined vprintf

  • WAMR_BH_VPRINTF=<vprintf_callback>, default to off.

Note

If you provide vprintf_callback, os_printf() and os_vprintf() on Linux, Darwin, Windows, VxWorks, Android, and esp-idf, plus WASI libc output, call your callback instead of libc vprintf(). Example outside the runtime lib:

int my_vprintf(const char *format, va_list ap)
{
    /* output to pre-opened file stream */
    FILE *my_file = ...;
    return vfprintf(my_file, format, ap);
    /* or output to pre-opened file descriptor */
    int my_fd = ...;
    return vdprintf(my_fd, format, ap);
    /* or output to string buffer and print the string */
    char buf[128];
    vsnprintf(buf, sizeof(buf), format, ap);
    return my_printf("%s", buf);
}

Then run cmake -DWAMR_BH_VPRINTF=my_vprintf .., or add the compiler macro BH_VPRINTF=my_vprintf (for example add_definitions(-DBH_VPRINTF=my_vprintf) in CMakeLists.txt). See basic sample for an example.

WAMR_BH_VPRINTF and WAMR_BH_LOG are the two options whose value is a function name rather than 0 or 1, so BH_VPRINTF and BH_LOG are the only macros the runtime tests with #ifndef instead of #if. Leaving them unset and setting them both have to build.

WAMR_BH_LOG=<log_callback>, default to off.

Note

If you provide log_callback, WAMR logs go there. Example:

void my_log(uint32 log_level, const char *file, int line, const char *fmt, ...)
{
    /* Usage of custom logger */
}

See basic sample for an example.

reference types feature

  • WAMR_BUILD_REF_TYPES=1/0, default to on.

Exclude WAMR application entry functions

  • WAMR_DISABLE_APP_ENTRY=1/0, default to off.

Note

The WAMR application entry (core/iwasm/common/wasm_application.c) wraps common steps to instantiate and run wasm functions and print results. These use platform APIs. this flag to skip the file if your platform lacks those APIs. Do not enable this flag when building product-mini.

source debugging features

  • WAMR_BUILD_DEBUG_INTERP=1/0, default to off.
  • WAMR_BUILD_DEBUG_AOT=1/0, default to off.
  • WAMR_BUILD_DYNAMIC_AOT_DEBUG=1/0, default to off.

Note

Source debugging needs extra setup. See source_debugging.md and WAMR source debugging basic.

load wasm custom sections

  • WAMR_BUILD_LOAD_CUSTOM_SECTION=1/0, default to off.

Note

By default, custom sections are ignored. WAMR_BUILD_LOAD_CUSTOM_SECTION so the embedder can read them via wasm_runtime_get_custom_section. If WAMR_BUILD_CUSTOM_NAME_SECTION is on, the custom name section is consumed by the runtime and unavailable to the embedder. For AoT files, pass --emit-custom-sections to wamrc to keep the sections; otherwise they are dropped.

Stack guard size

  • WAMR_BUILD_STACK_GUARD_SIZE=n, default to N/A when not set.

Note

By default, stack guard size is 1K (1024) or 24K when uvwasi is enabled.

Disable writing the linear memory base address to x86 GS segment register

  • WAMR_DISABLE_WRITE_GS_BASE=1/0, default to on if the platform supports it.

Note

By default only linux x86-64 enables this. On 32-bit platforms it stays off even if set to 0. On linux x86-64, writing the linear memory base to the GS segment can speed up linear memory access for LLVM AOT/JIT when --enable-segue=[<flags>] is passed to wamrc or iwasm.

See segue optimization for wamrc when generating the aot file for details.

User defined linear memory allocator

  • WAMR_BUILD_ALLOC_WITH_USAGE=1/0, default to off.
  • WAMR_BUILD_ALLOC_WITH_USER_DATA=1/0, default to off.

Note

By default, the system allocates linear memory. With this on and Alloc_With_Allocator selected, you can provide your own allocator.

running PGO(Profile-Guided Optimization) instrumented AOT file

  • WAMR_BUILD_STATIC_PGO=1/0, default to off.

linux perf support

  • WAMR_BUILD_LINUX_PERF=1/0: enable linux perf support to generate flamegraphs for wasm app performance. Default is off.

Note

See Use linux-perf.

module instance context APIs

  • WAMR_BUILD_MODULE_INST_CONTEXT=1/0: enable module instance context APIs so the embedder can set one or more contexts for a wasm module instance. Default is off, but it is turned on automatically when WASI libc (WAMR_BUILD_LIBC_WASI/WAMR_BUILD_LIBC_UVWASI) or WAMR_BUILD_WASI_NN is enabled (so it is on in default iwasm builds).
    wasm_runtime_create_context_key
    wasm_runtime_destroy_context_key
    wasm_runtime_set_context
    wasm_runtime_set_context_spread
    wasm_runtime_get_context

Note

See wasm_export.h for details.

quick AOT/JTI entries

  • WAMR_BUILD_QUICK_AOT_ENTRY=1/0: register quick call entries to speed up AOT/JIT function calls. Derived from the running mode: on when AOT or LLVM JIT is enabled, off otherwise. Setting it explicitly overrides the derived value. Non-CMake builds say it in their own build files, next to their AOT sources: product-mini/platforms/alios-things/aos.mk, the CONFIG_INTERPRETERS_WAMR_AOT_QUICK_ENTRY option of product-mini/platforms/nuttx/wamr.mk, and build-scripts/SConscript_config (rt-thread).

AOT intrinsics

  • WAMR_BUILD_AOT_INTRINSICS=1/0: turn on AOT intrinsic functions. Derived from the running mode: on when AOT is enabled, off otherwise. Setting it explicitly overrides the derived value. AOT code can call these when wamrc uses --disable-llvm-intrinsics or --enable-builtin-intrinsics=<intr1,intr2,...>. Non-CMake builds say it in their own build files, next to their AOT sources: product-mini/platforms/alios-things/aos.mk, the CONFIG_INTERPRETERS_WAMR_AOT block of product-mini/platforms/nuttx/wamr.mk, and build-scripts/SConscript_config (rt-thread).

extended constant expression

  • WAMR_BUILD_EXTENDED_CONST_EXPR=1/0, default to off. It is also enabled automatically when WAMR_BUILD_LIME1 is on.

bulk-memory-opt

  • WAMR_BUILD_BULK_MEMORY_OPT=1/0, default to off. Enabled automatically when WAMR_BUILD_BULK_MEMORY or WAMR_BUILD_LIME1 is on.

Note

See bulk-memory-opt.

call-indirect-overlong

  • WAMR_BUILD_CALL_INDIRECT_OVERLONG=1/0, default to off, but it is enabled automatically when reference types (WAMR_BUILD_REF_TYPES, default on) are on. The minimal Lime1 feature set also enables it.

Lime1 target

  • WAMR_BUILD_LIME1=1/0, default to off.

Note

Enabling LIME1 automatically turns on bulk-memory-opt, call-indirect-overlong, and extended constant expressions. See Lime1.

Lime1 is a complete profile, so it also turns off WAMR_BUILD_BULK_MEMORY, WAMR_BUILD_REF_TYPES and WAMR_BUILD_SIMD, warning whenever that overrides a value that was set. The older -DWAMR_BUILD_LIME1=1 -DWAMR_BUILD_BULK_MEMORY=0 -DWAMR_BUILD_REF_TYPES=0 -DWAMR_BUILD_SIMD=0 form keeps working; its three =0 are redundant now and do not warn.

WAMR_BUILD_LIME1 and the Wasm specification version presets are mutually exclusive: they describe two different feature sets, so setting WAMR_BUILD_LIME1 together with any WAMR_BUILD_WASM_SPEC<N> fails the configure step.

Wasm specification version preset

  • WAMR_BUILD_WASM_SPEC1=1/0, default to off. Wasm 1.0 preset.
  • WAMR_BUILD_WASM_SPEC2=1/0, default to off. Wasm 2.0 preset.
  • WAMR_BUILD_WASM_SPEC3=1/0, default to off. Not supported yet, see below.

The three switches turn one Wasm specification version into a single option.

A preset states which proposals a version requires and which ones it excludes. It owns the switches it turns on, and it turns off the excluded ones ahead of the compatibility defaults, so a version is a version no matter what the build entry point ships by default (see features enabled by default).

effect note
WAMR_BUILD_WASM_SPEC1 turns WAMR_BUILD_BULK_MEMORY, WAMR_BUILD_REF_TYPES and WAMR_BUILD_SIMD off a Wasm 1.0 runtime has no post-1.0 proposal. Every Wasm 1.0 proposal is always on in WAMR and has no switch; bulk memory defaults to on inside build-scripts and reference types and SIMD default to on in the build entry points, so all three are turned back off
WAMR_BUILD_WASM_SPEC2 WAMR_BUILD_BULK_MEMORY, WAMR_BUILD_REF_TYPES, WAMR_BUILD_SIMD the only configurable Wasm 2.0 proposals; Multi-value, Non-trapping float-to-int Conversions and Sign-extension Operators are always on

A preset describes a complete feature set, so it has two directions:

  • a feature the preset does not exclude, asked for on top of it, is kept: -DWAMR_BUILD_WASM_SPEC2=1 -DWAMR_BUILD_TAIL_CALL=1 builds Wasm 2.0 plus tail call;
  • a feature the preset excludes is turned off even when the caller turned it on, and configure prints a warning saying whether that value came from -D/a CMake preset or from an entry point's own default. Wasm 1.0 and Lime1 exclude bulk memory, reference types and SIMD.

Drop the preset if you want to be sure nothing else is on, or check the "About Wasm Proposals" status that config_common.cmake prints.

WAMR_BUILD_WASM_SPEC2 does not imply WAMR_BUILD_WASM_SPEC1, and setting both fails the configure step: each one is a complete feature set rather than a layer on top of the other.

  • WAMR_BUILD_WASM_SPEC3 is not supported yet. WAMR does not implement Wasm 3.0 completely, so a Wasm 3.0 preset would not be a Wasm 3.0 runtime. Setting WAMR_BUILD_WASM_SPEC3=1 is a configuration error: it fails the configure step with the list of missing and limited Wasm 3.0 proposals, and applies no preset at all. Setting it to 0 does nothing and configure continues as usual. Build the Wasm 3.0 features you need individually on top of WAMR_BUILD_WASM_SPEC2=1, for example -DWAMR_BUILD_TAIL_CALL=1; each one has its own section below that documents its running mode support.

A preset and WAMR_BUILD_LIME1 are mutually exclusive: LIME1 is a profile of its own, so setting any WAMR_BUILD_WASM_SPEC<N> together with WAMR_BUILD_LIME1 fails the configure step.

WAMR_BUILD_WASM_SPEC2=1 is also rejected by unsupported_combination.cmake in the running modes that SIMD does not support:

cmake .. -DWAMR_BUILD_WASM_SPEC2=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_AOT=0
# Unsupported build configuration: SIMD + CLASSIC_INTERP

Note

Set the switches before include (runtime_lib.cmake), like every other WAMR_BUILD_* switch. See building configurations.

Configurable memory access boundary check

  • WAMR_CONFIGURABLE_BOUNDS_CHECKS=1/0, default to off.

Warning

When enabled, you can run iwasm --disable-bounds-checks to turn off memory access boundary checks in interpreter mode. This is a privileged feature; use it carefully.

Shared heap among wasm apps and host native

  • WAMR_BUILD_SHARED_HEAP=1/0, default to off.

Note

When enabled, you can create and attach shared heaps, and the following APIs become available:

   wasm_runtime_create_shared_heap
   wasm_runtime_attach_shared_heap
   wasm_runtime_detach_shared_heap
   wasm_runtime_shared_heap_malloc
   wasm_runtime_shared_heap_free

A wasm app can call these to use the shared heap attached to its module instance:

   void *shared_heap_malloc();
   void shared_heap_free(void *ptr);

Warning

The shared-heap feature is not supported in fast-jit mode.

Shrunk the memory usage

  • WAMR_BUILD_SHRUNK_MEMORY=1/0, default to on.

Note

When enabled, this reduces memory by shrinking linear memory, especially when memory.grow is unused and memory needs are predictable.

Instruction metering

  • WAMR_BUILD_INSTRUCTION_METERING=1/0, default to off.

Note

This limits the number of instructions a wasm module instance can run. Call wasm_runtime_set_instruction_count_limit(...) before wasm_runtime_call_*(...) to enforce the cap.

Warning

This is only supported by the interpreter (classic and fast interpreter). It does not apply to AOT or the JITs.

Branch hints

  • WAMR_BUILD_BRANCH_HINTS=1/0, default to disable if not set

Note

Enabling this feature allows the runtime to utilize branch hints for better performance during aot/jit execution.

Combination of configurations:

Invoke general FFI

  • WAMR_BUILD_INVOKE_NATIVE_GENERAL=1/0, default to off.

By default, WAMR uses architecture-specific calling conventions to call native functions from WASM modules. When this feature is enabled, WAMR uses a general calling convention that works on all architectures but is slower. The details are in iwasm_common.cmake

Host defined log

  • WAMR_BH_LOG=<log_callback>, default to off.

AOT Validator

  • WAMR_BUILD_AOT_VALIDATOR=1/0, default to off.

Note

By default, WAMR believes AOT files are valid and unforged.

Copy Call Stack

  • WAMR_BUILD_COPY_CALL_STACK=1/0, default to off.

Note

Unlike dump call stack, which prints the call stack on exceptions, this feature lets the embedder copy the call stack programmatically via wasm_runtime_dump_call_stack_to_buf().

Librats

  • WAMR_BUILD_LIB_RATS=1/0, default to off.

librats is a C library designed to facilitate remote attestation for secure computing environments. It provides a framework for attesting the integrity of computing environments remotely, enabling trust establishment between different Trusted Execution Environments (TEEs).

Warning

This is for Intel SGX platforms only.

Sanitizer

  • WAMR_BUILD_SANITIZER=[ubsan|asan|tsan|posan], default is empty

Use one or more of the following sanitizers when building WAMR with sanitizer support: AddressSanitizer, UndefinedBehaviorSanitizer, ThreadSanitizer, or Pointer-Overflow Sanitizer.

Note

tsan and asan cannot be combined. asan is skipped with a warning in LLVM JIT mode. Unsupported names fail the configuration.

Intel Protected File System

  • WAMR_BUILD_SGX_IPFS=1/0, default to off.

Warning

This is for Intel SGX platforms only.

Support spec test

  • WAMR_BUILD_SPEC_TEST=1/0, default to off.

WASM Cache

  • WAMR_BUILD_WASM_CACHE=1/0, default to off.

Test Garbage Collection

  • WAMR_TEST_GC=1/0, default to off.

It is used to test garbage collection related APIs and features. Refer to iwasm_gc.cmake for details.

It is used to cache loaded wasm modules in memory to speed up module instantiation only in wasm-c-api.

Combination of configurations

You can mix settings. For example, to disable the interpreter, enable AOT and WASI, run:

cmake .. -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_LIBC_WASI=1 -DWAMR_BUILD_PLATFORM=linux

To enable the interpreter, disable AOT and WASI, and target X86_32, run:

cmake .. -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_AOT=0 -DWAMR_BUILD_LIBC_WASI=0 -DWAMR_BUILD_TARGET=X86_32

When enabling SIMD for fast interpreter mode, turn on both SIMD and the SIMDe library:

cmake .. -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=1 -DWAMR_BUILD_SIMD=1 -DWAMR_BUILD_LIB_SIMDE=1

For Valgrind, start with these and add more as needed:

  #...
  -DCMAKE_BUILD_TYPE=Debug \
  -DWAMR_DISABLE_HW_BOUND_CHECK=0 \
  -DWAMR_DISABLE_WRITE_GS_BASE=0
  #...

To build the minimal Lime1 feature set, just ask for it: LIME1 turns on bulk-memory-opt, call-indirect-overlong and extended constant expressions, and turns off bulk memory, reference types and SIMD. Naming the three =0 explicitly is still accepted and does not warn:

cmake .. -DWAMR_BUILD_LIME1=1

To build for a whole Wasm specification version, use the preset switches. A preset turns the excluded switches off ahead of the compatibility defaults, so the command below is a Wasm 1.0 build whatever the entry point ships by default.

# Wasm 1.0
cmake .. -DWAMR_BUILD_WASM_SPEC1=1

# Wasm 2.0 (the interpreter mode must be a mode that supports SIMD)
cmake .. -DWAMR_BUILD_WASM_SPEC2=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=1

# Wasm 3.0 has no preset yet: WAMR_BUILD_WASM_SPEC3=1 fails the configure step.
# Ask for the individual Wasm 3.0 features instead, for example:
cmake .. -DWAMR_BUILD_WASM_SPEC2=1 -DWAMR_BUILD_TAIL_CALL=1 -DWAMR_BUILD_GC=1

See Wasm specification version preset for what each version enables and for the parts of Wasm 3.0 that WAMR does not implement.

Log system

  • WAMR_BUILD_LOG=1/0, default to on. Turns the runtime log system (WASM_ENABLE_LOG) on or off. The macro is read by the product-mini executables rather than by the vmcore, so turning it off mainly shrinks iwasm itself.

Opcode counter

  • WAMR_BUILD_OPCODE_COUNTER=1/0, default to off. Counts the executed opcodes. Only has an effect when WAMR_BUILD_FAST_INTERP is on, which is the only place the macro is read.

Word aligned read

  • WAMR_BUILD_WORD_ALIGN_READ=1/0, default to off. Reads the AOT file through word aligned accesses, for targets that fault on unaligned loads.

Legacy app framework

  • WAMR_BUILD_BASE_LIB=1/0, default to off.
  • WAMR_BUILD_APP_FRAMEWORK=1/0, default to off.

Note

These two belong to the legacy application framework. They are kept configurable because the loaders and wasm_native.c still read the corresponding macros; new applications should not need them.

Fuzz test mode

  • WAMR_BUILD_FUZZ_TEST=1/0, default to off. Caps the memory allocator so the runtime stays inside the memory budget of a fuzzing host. Only meant for the fuzzing targets under tests/fuzz.