Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Load WebAssembly modules from Swift

License

Notifications You must be signed in to change notification settings

therealbnut/SwiftWebAssembly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftWebAssembly GitHub license GitHub release Carthage compatible Carthage compatible

SwiftWebAssembly has one purpose, to load WebAssembly compiled modules and exposes them to Swift.

Example

import SwiftWebAssembly
import JavaScriptCore

let context = JSContext()
let file = URL(fileURLWithPath: "example.wasm")
let data = try! Data(contentsOf: file)

context.loadWebAssemblyModule(data: data, success: { exports in
    let result = exports?["add"]?.call(withArguments: [1, 2])
    print("result: \(result)") // result: 3
})

Integration

Swift Package Manager

The package can be installed through SwiftPM.

  .package(url: "[email protected]:therealbnut/SwiftWebAssembly.git", from: "0.2.0"),

A more complete example:

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "MyPackage",
    products: [
        .library(name: "MyProduct", targets: ["MyTarget"]),
    ],
    dependencies: [
        .package(url: "[email protected]:therealbnut/SwiftWebAssembly.git", from: "0.2.0"),
    ],
    targets: [
        .target(name: "MyTarget", dependencies: ["SwiftWebAssembly"])
    ]
)

Carthage

Add SwiftWebAssembly to your Cartfile.

About

Load WebAssembly modules from Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages