A Swift API for the Wasmer WebAssembly Runtime.
SwiftyWasmer packages the
Wasmer C API
for the Swift programming language,
i.e. it provides CWasmer
system library with a proper module map
and a Wasmer
module with a nice Swift style API for Wasmer.
Note: This is for embedding/running WebAssembly (Wasm) modules from within a Swift host program. It is not about compiling Swift to WebAssembly (there is the SwiftWasm effort for this).
What does it look like? Like this:
import Wasmer
// Just load a file into memory
let wasmFile = URL(fileURLWithPath: "sum.wasm")
let wasmData = try Data(contentsOf: wasmFile)
// Compile the Data into a module, and instantiate that
let module = try WebAssembly.Module (wasmData)
let instance = try WebAssembly.Instance(module)
// Run a function exported by the Module
let results = try instance.exports.sum(.i32(7), .i32(8))
This package contains the tests for SwiftyWasmer. It is in a separate package because it contains some precompiled Wasm test data that tends to be rather big.
SwiftyWasmer is brought to you by the Always Right Institute and ZeeZide. We like feedback, GitHub stars, cool contract work, presumably any form of praise you can think of.