Wasmtime C API

This documentation is an overview and API reference for the C API of Wasmtime. The C API is spread between three different header files:

The wasmtime.h header file includes all the other header files and is the main header file you'll likely be using. The wasm.h header file comes directly from the WebAssembly/wasm-c-api repository, and at this time the upstream header file does not have documentation so Wasmtime provides documentation here. It should be noted some semantics may be Wasmtime-specific and may not be portable to other engines.

Installing the C API

To install the C API from precompiled binaries you can download the appropriate binary from the releases page of Wasmtime. Artifacts for the C API all end in "-c-api" for the filename.

Each archive contains an include directory with necessary headers, as well as a lib directory with both a static archive and a dynamic library of Wasmtime. You can link to either of them as you see fit.

Installing the C API through CMake

CMake can be used to make the process of linking and compiling easier. An example of this if you have wasmtime as a git submodule at third_party/wasmtime:

target_include_directories(YourProject PUBLIC wasmtime)
target_link_libraries(YourProject PUBLIC wasmtime)

BUILD_SHARED_LIBS is provided as a define if you would like to build a shared library instead. You must distribute the appropriate shared library for your platform if you do this.

Linking against the C API

You'll want to arrange the include directory of the C API to be in your compiler's header path (e.g. the -I flag). If you're compiling for Windows and you're using the static library then you'll also need to pass -DWASM_API_EXTERN= and -DWASI_API_EXTERN= to disable dllimport.

Your final artifact can then be linked with -lwasmtime. If you're linking against the static library you may need to pass other system libraries depending on your platform:

  • Linux - -lpthread -ldl -lm
  • macOS - no extra flags needed
  • Windows - ws2_32.lib advapi32.lib userenv.lib ntdll.lib shell32.lib ole32.lib bcrypt.lib

Building from Source

The C API is located in the crates/c-api directory of the Wasmtime repository. To build from source you'll need a Rust compiler and a checkout of the wasmtime project. Afterwards you can execute:

$ cargo build --release -p wasmtime-c-api

This will place the final artifacts in target/release, with names depending on what platform you're compiling for.

Other resources

Some other handy resources you might find useful when exploring the C API documentation are: