All Projects → bytecodealliance → Wasmtime Go

bytecodealliance / Wasmtime Go

Licence: apache-2.0
Go WebAssembly runtime powered by Wasmtime

Programming Languages

go
31211 projects - #10 most used programming language
rust
11053 projects
golang
3204 projects

Projects that are alternatives of or similar to Wasmtime Go

Lunatic
Lunatic is an Erlang-inspired runtime for WebAssembly
Stars: ✭ 2,074 (+767.78%)
Mutual labels:  webassembly, wasm, runtime
Wasmtime
Standalone JIT-style runtime for WebAssembly, using Cranelift
Stars: ✭ 6,413 (+2583.26%)
Mutual labels:  webassembly, wasm, runtime
cabasa
Haxe Framework for WebAssembly
Stars: ✭ 30 (-87.45%)
Mutual labels:  runtime, webassembly, wasm
Wasm Micro Runtime
WebAssembly Micro Runtime (WAMR)
Stars: ✭ 2,440 (+920.92%)
Mutual labels:  webassembly, wasm, runtime
Awesome Wasm Langs
😎 A curated list of languages that compile directly to or have their VMs in WebAssembly
Stars: ✭ 2,966 (+1141%)
Mutual labels:  webassembly, wasm
Prototype
(deprecated) The journey continues at ASNEXT: https://github.com/AssemblyScript/assemblyscript
Stars: ✭ 2,114 (+784.52%)
Mutual labels:  webassembly, wasm
Wasm Worker
Move a WebAssembly module into its own thread
Stars: ✭ 215 (-10.04%)
Mutual labels:  webassembly, wasm
Wasm Examples
WebAssembly Examples
Stars: ✭ 191 (-20.08%)
Mutual labels:  webassembly, wasm
Webassembly Examples
From Simple To Complex. A complete collection of webassembly examples.
Stars: ✭ 177 (-25.94%)
Mutual labels:  webassembly, wasm
Uno.playground
Source code for the Uno Gallery apps and Uno Playground (made in Wasm)
Stars: ✭ 184 (-23.01%)
Mutual labels:  webassembly, wasm
Wasm By Example
Wasm By Example is a website with a set of hands-on introduction examples and tutorials for WebAssembly (Wasm)
Stars: ✭ 226 (-5.44%)
Mutual labels:  webassembly, wasm
Raw Wasm
Raw WebAssembly demos
Stars: ✭ 183 (-23.43%)
Mutual labels:  webassembly, wasm
Lam
🚀 a lightweight, universal actor-model vm for writing scalable and reliable applications that run natively and on WebAssembly
Stars: ✭ 176 (-26.36%)
Mutual labels:  webassembly, wasm
Pont
An online board game in Rust and WebAssembly
Stars: ✭ 218 (-8.79%)
Mutual labels:  webassembly, wasm
Wag
WebAssembly compiler implemented in Go
Stars: ✭ 177 (-25.94%)
Mutual labels:  webassembly, wasm
Go Wasm
The in-browser IDE for Go
Stars: ✭ 186 (-22.18%)
Mutual labels:  webassembly, wasm
Sandspiel
Creative cellular automata browser game
Stars: ✭ 2,476 (+935.98%)
Mutual labels:  webassembly, wasm
Argon2 Browser
Argon2 library compiled for browser runtime
Stars: ✭ 197 (-17.57%)
Mutual labels:  webassembly, wasm
Asm Dom
A minimal WebAssembly virtual DOM to build C++ SPA (Single page applications)
Stars: ✭ 2,604 (+989.54%)
Mutual labels:  webassembly, wasm
Vue
The progressive framework for WebAssembly applications.
Stars: ✭ 211 (-11.72%)
Mutual labels:  webassembly, wasm

wasmtime-go

Go embedding of Wasmtime

A Bytecode Alliance project

CI status Documentation Code Coverage

Installation

go get -u github.com/bytecodealliance/[email protected]

Be sure to check out the API documentation!

This Go library uses CGO to consume the C API of the Wasmtime project which is written in Rust. Precompiled binaries of Wasmtime are checked into this repository on tagged releases so you won't have to install Wasmtime locally, but it means that this project only works on Linux x86_64, macOS x86_64 , and Windows x86_64 currently. Building on other platforms will need to arrange to build Wasmtime and use CGO_* env vars to compile correctly.

This project has been tested with Go 1.13 or later. It is not recommended to use Go 1.14 earlier than Go 1.14.11 on macOS due to a bug in the Go runtime.

If you are a bazel user, add following to your WORKSPACE file:

go_repository(
    name = "com_github_bytecodealliance_wasmtime_go",
    importpath = "github.com/bytecodealliance/wasmtime-go",
    version = "v0.25.0",
)

Usage

A "Hello, world!" example of using this package looks like:

package main

import (
    "fmt"
    "github.com/bytecodealliance/wasmtime-go"
)

func main() {
    // Almost all operations in wasmtime require a contextual `store`
    // argument to share, so create that first
    store := wasmtime.NewStore(wasmtime.NewEngine())

    // Compiling modules requires WebAssembly binary input, but the wasmtime
    // package also supports converting the WebAssembly text format to the
    // binary format.
    wasm, err := wasmtime.Wat2Wasm(`
      (module
        (import "" "hello" (func $hello))
        (func (export "run")
          (call $hello))
      )
    `)
    check(err)

    // Once we have our binary `wasm` we can compile that into a `*Module`
    // which represents compiled JIT code.
    module, err := wasmtime.NewModule(store.Engine, wasm)
    check(err)

    // Our `hello.wat` file imports one item, so we create that function
    // here.
    item := wasmtime.WrapFunc(store, func() {
        fmt.Println("Hello from Go!")
    })

    // Next up we instantiate a module which is where we link in all our
    // imports. We've got one import so we pass that in here.
    instance, err := wasmtime.NewInstance(store,module, []*wasmtime.Extern{item.AsExtern()})
    check(err)

    // After we've instantiated we can lookup our `run` function and call
    // it.
    run := instance.GetExport("run").Func()
    _, err = run.Call()
    check(err)
}

func check(e error) {
    if e != nil {
        panic(e)
    }
}

Contributing

So far this extension has been written by folks who are primarily Rust programmers, so it's highly likely that there's some faux pas in terms of Go idioms. Feel free to send a PR to help make things more idiomatic if you see something!

To work on this extension locally you'll first want to clone the project:

$ git clone https://github.com/bytecodealliance/wasmtime-go

Next up you'll want to have a local Wasmtime build available.

You'll need to build at least the wasmtime-c-api crate, which, at the time of this writing, would be:

$ cargo build -p wasmtime-c-api

Once you've got that you can set up the environment of this library with:

$ ./ci/local.sh /path/to/wasmtime

This will create a build directory which has the compiled libraries and header files. Next up you can run normal commands such as:

$ go test

And after that you should be good to go!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].