Skip to content

swiftwasm/WasmKit

Repository files navigation

WasmKit Icon

WasmKit

WasmKit is a standalone and embeddable WebAssembly runtime (virtual machine) implementation and related tooling written in Swift. Starting with Swift 6.2, WasmKit CLI executable is included in Swift toolchains distributed at swift.org for Linux and macOS.

Usage

You can find introductory examples and API documentation on the Swift Package Index documentation page.

Command Line Tool

WasmKit provides a command line tool to run WebAssembly binaries compatible with WASI.

$ git clone https://github.com/swiftwasm/WasmKit.git
$ cd WasmKit
$ swift run wasmkit-cli run ./Examples/wasm/hello.wasm
Hello, World!

As a Library

Swift Package Manager

To use WasmKit in your package, add it as a Swift Package Manager dependency.

Run the following commands in the same directory as your Package.swift manifest to add the dependency:

swift package add-dependency https://github.com/swiftwasm/WasmKit --up-to-next-minor-from 0.1.6
swift package add-target-dependency WasmKit <your-package-target-name> --package WasmKit

You can also add the following snippet manually instead to your Package.swift file:

dependencies: [
    // ...other dependencies
    .package(url: "https://github.com/swiftwasm/WasmKit.git", .upToNextMinor(from: "0.1.6")),
],
// ...other package configuration
targets: [
    // ...other targets
    .target(
        name: "<your-package-target-name>",
        dependencies: [.product(name: "WasmKit", package: "WasmKit")],
    )
]

Features

  • Reasonably fast
  • Minimal dependencies
    • The core runtime engine depends only on swift-system.
    • No Foundation dependency
  • Compact and embeddable
    • Debug build complete in 5 seconds1
  • Batteries included
    • WASI support, WAT (WebAssembly text format) parser/assembler, etc.

Supported Platforms

WasmKit engine works on all major platforms supported by Swift. It is continuously tested on macOS, Ubuntu, Amazon Linux 2, Android, and Windows, and should work on the following platforms:

  • macOS 10.13+, iOS 12.0+, tvOS 12.0+, watchOS 6.0+
  • Amazon Linux 2, Debian 12, Ubuntu 22.04+, Fedora 39+
  • Android API Level 30
  • Windows 10+

Implementation Status

Category Feature Status
WebAssembly MVP Parsing binary format ✅ Implemented
Parsing text format (WAT) ✅ Implemented
Execution ✅ Implemented
Validation ✅ Implemented
WebAssembly Proposal Reference types ✅ Implemented
Bulk memory operations ✅ Implemented
Mutable globals ✅ Implemented
Sign-extension operators ✅ Implemented
Non-trapping float-to-int conversions ✅ Implemented
Memory64 ✅ Implemented
Tail call ✅ Implemented
Threads and atomics 🚧 Parser implemented
WASI WASI Preview 1 🚧 Majority of syscalls implemented

Minimum Supported Swift Version

The minimum supported version is Swift 6.0, which is the version used to bootstrap the Swift toolchain on ci.swift.org.

Testing

To run the WasmKit test suite, you need to checkout the test suite repositories first.

# Checkout test suite repositories
$ ./Vendor/checkout-dependency
# Run tests
$ swift test

Acknowledgement

This project was originally developed by @akkyie, and is now maintained by the community.

License

WasmKit runtime modules are licensed under MIT License. See LICENSE file for license information.

GDB Remote Protocol support (GDBRemoteProtocol and WasmKitGDBHandler modules) is licensed separately under Apache License v2.0 with Runtime Library Exception, Copyright 2025 Apple Inc. and the Swift project authors.

See https://swift.org/LICENSE.txt for license information.

See https://swift.org/CONTRIBUTORS.txt for Swift project authors.

Footnotes

  1. On a 2020 Mac mini (M1, 16GB RAM) with Swift 5.10. Measured by swift package resolve && swift package clean && time swift build --product PrintAdd. License