WebAssembly runtime for wasmer-go

gowasmer

gowasmer

When compiling Go to WebAssembly, the Go compiler assumes the WebAssembly is going to run in a JavaScript environment. Hence a wasm_exec.js file is provided by the Go compiler and must be used. However, WebAssembly can actually run everywhere. So we need to use some hacks to make WebAssembly modules generated by the Go compiler runnable everywhere. And that's where gowasmer is useful.

gowasmer is a port of the wasm_exec.js file, for Go. It assumes the WebAssembly runtime is wasmer-go.

Alternatively, to avoid using gowasmer, you can compile your Go program to WebAssembly with TinyGo as follows:

$ tinygo build -o module.wasm -target wasi .

Usage

See _example directory.

Installation

$ go get github.com/mattn/gowasmer

License

MIT

Author

Yasuhiro Matsumoto (a.k.a. mattn)

Owner
mattn
Long-time Golang user&contributor, Google Dev Expert for Go, and author of many Go tools, Vim plugin author. Windows hacker C#/Java/C/C++
mattn
Similar Resources

Tiny, blazing fast WebAssembly compute

Sat, the tiny WebAssembly compute module Sat (as in satellite) is an experiment, and isn't ready for production use. Please try it out and give feedba

Jan 5, 2023

WebAssembly Lightweight Javascript Framework in Go (AngularJS Inspired)

Tango Lightweight WASM HTML / Javascript Framework Intro WebAssembly is nice, Go on the web is nice, so I ported Tangu to Go and WebAssembly. Tangu is

Dec 20, 2022

Running a Command line tool written in Go on browser with WebAssembly

Running a command line tool written in Go on browser with WebAssembly This repo contains code/assets from the article Files: . ├── article.md

Dec 30, 2022

This library provides WebAssembly capability for goja Javascript engine

This module provides WebAssembly functions into goja javascript engine.

Jan 10, 2022

A Brainfuck to WebAssembly compiler written in Go.

brainfuck2wasm A Brainfuck to WebAssembly compiler written in Go. I am writing this compiler for a Medium article. When I complete the compiler, I'll

Jun 6, 2022

Dom - A Go API for different Web APIs for WebAssembly target

Go DOM binding (and more) for WebAssembly This library provides a Go API for dif

Jan 7, 2023

🐹🕸️ WebAssembly runtime for Go

🐹🕸️ WebAssembly runtime for Go

Wasmer Go Website • Docs • Slack Channel A complete and mature WebAssembly runtime for Go based on Wasmer. Features Easy to use: The wasmer API mimics

Jan 2, 2023

🐹🕸️ WebAssembly runtime for Go

🐹🕸️ WebAssembly runtime for Go

Wasmer Go Website • Docs • Slack Channel A complete and mature WebAssembly runtime for Go based on Wasmer. Features Easy to use: The wasmer API mimics

Dec 29, 2022

wazero: the zero dependency WebAssembly runtime for Go developers

wazero: the zero dependency WebAssembly runtime for Go developers WebAssembly is a way to safely run code compiled in other languages. Runtimes execut

Jan 2, 2023

Identify containers at runtime and observe them. No container runtime required. Read only access to the kernel.

Linux Telemetry The Double Slit Experiment Taken from an interesting physics anomaly where the behavior of a physical system mutates simply by being o

Sep 18, 2022

golang-runtime-di is a framework for runtime dependency injection in go

golang-runtime-di description golang-runtime-di is a framework for runtime dependency injection in go. usage quickstart add it to your go.mod: go get

Aug 1, 2022

A package to build progressive web apps with Go programming language and WebAssembly.

A package to build progressive web apps with Go programming language and WebAssembly.

go-app is a package to build progressive web apps (PWA) with Go programming language and WebAssembly. It uses a declarative syntax that allows creatin

Dec 28, 2022

Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly

Introduction Qt is a free and open-source widget toolkit for creating graphical user interfaces as well as cross-platform applications that run on var

Jan 2, 2023

Go compiler for small places. Microcontrollers, WebAssembly, and command-line tools. Based on LLVM.

TinyGo - Go compiler for small places TinyGo is a Go compiler intended for use in small places such as microcontrollers, WebAssembly (Wasm), and comma

Dec 30, 2022

WebAssembly interop between Go and JS values.

vert Package vert provides WebAssembly interop between Go and JS values. Install GOOS=js GOARCH=wasm go get github.com/norunners/vert Examples Hello W

Dec 28, 2022

WebAssembly for Proxies (Golang host implementation)

WebAssembly for Proxies (GoLang host implementation) The GoLang implementation for proxy-wasm, enabling developer to run proxy-wasm extensions in Go.

Dec 29, 2022

Go compiler for small places. Microcontrollers, WebAssembly, and command-line tools. Based on LLVM.

TinyGo - Go compiler for small places TinyGo is a Go compiler intended for use in small places such as microcontrollers, WebAssembly (Wasm), and comma

Jan 4, 2023

wagon, a WebAssembly-based Go interpreter, for Go.

wagon wagon is a WebAssembly-based interpreter in Go, for Go. As of 2020/05/11 Wagon is in read-only mode, and looking for a maintainer. You may want

Dec 6, 2022

Golang-WASM provides a simple idiomatic, and comprehensive API and bindings for working with WebAssembly for Go and JavaScript developers

Golang-WASM provides a simple idiomatic, and comprehensive API and bindings for working with WebAssembly for Go and JavaScript developers

A bridge and bindings for JS DOM API with Go WebAssembly. Written by Team Ortix - Hamza Ali and Chan Wen Xu. GOOS=js GOARCH=wasm go get -u github.com/

Dec 22, 2022
Comments
  • doc(readme) Propose a better introduction

    doc(readme) Propose a better introduction

    This patch is a proposal for a new introduction, which I find better: It exposes the problem, and explains the need for gowasmer.

    By the way, good job with the project!

  • why wasm response empty string ?

    why wasm response empty string ?

    question

    wasm

    I build the code to wasm file.

    package main
    
    import (
    	"syscall/js"
    
    	"github.com/mattn/gowasmer/wasmutil"
    )
    
    func Add(a, b int) int {
    	return a + b
    }
    
    func String(a string) string {
    	println(a)
    	return a
    }
    
    func MultiString(a, b string) string {
    	return a + b
    }
    
    func main() {
    	c := make(chan struct{})
    	js.Global().Set("String", js.FuncOf(wasmutil.Wrap(String)))
    	js.Global().Set("Add", js.FuncOf(wasmutil.Wrap(Add)))
    	js.Global().Set("MultiString", js.FuncOf(wasmutil.Wrap(MultiString)))
    	<-c
    }
    

    golang code

    go run the code. but the function add in wasm is ok, but String and MultiString response emtpy string ?

    package main
    
    import (
    	"fmt"
    	"io/ioutil"
    	"log"
    
    	gowasmer "github.com/mattn/gowasmer"
    )
    
    func main() {
    	b, err := ioutil.ReadFile("wasm-example")
    	if err != nil {
    		log.Fatal(err)
    	}
    
    	inst, err := gowasmer.NewInstance(b)
    	if err != nil {
    		log.Fatal(err)
    	}
    
    	m := inst.Get("Add")
    	r := m.(func([]interface{}) interface{})([]interface{}{1, 3})
    	fmt.Printf("1 + 3 = %v\n", r)
    
    	m = inst.Get("String")
    	r = m.(func([]interface{}) interface{})([]interface{}{"haha"})
    	fmt.Printf("String = %v\n", r)
    
    	m = inst.Get("MultiString")
    	r = m.(func([]interface{}) interface{})([]interface{}{"aaa", "bbb"})
    	fmt.Printf("MultiString = %v\n", r)
    }
    

    run stdout:

    1 + 3 = 4
    
    String =
    MultiString = 
    

    please provide more example, thank u.

    😁

  • How do I support 'json.Marshal' 'time.now' 'fmt.xxx' in wasm writen in go

    How do I support 'json.Marshal' 'time.now' 'fmt.xxx' in wasm writen in go

    I add some code in example like bellow:

    package main
    
    import (
    	"encoding/json"
    	"github.com/mattn/gowasmer/wasmutil"
    	"syscall/js"
    )
    
    func Add(a, b int) int {
    	json.Marshal(123)
    	//or time.Now()
    	//or fmt.Println()
    	return a + b
    }
    
    func main() {
    	c := make(chan struct{})
    	js.Global().Set("Add", js.FuncOf(wasmutil.Wrap(Add)))
    	<-c
    }
    

    When I run the example , it panics:

    panic: syscall/js: call of Value.Get on undefined
    
    goroutine 1 [running]:
    syscall/js.Value.Get({{}, 0x0, 0x0}, {0x22f97, 0x9})
    /home/wanghh/workspace/go1.17.7/src/syscall/js/js.go:299 +0xc
    syscall.init()
    /home/wanghh/workspace/go1.17.7/src/syscall/fs_js.go:21 +0x12
    
    Process finished with the exit code 2
    

    So, how do I support 'json.Marshal' 'time.now' 'fmt.xxx' in wasm writen in go ?

Related tags
🐹🕸️ WebAssembly runtime for Go
🐹🕸️ WebAssembly runtime for Go

Wasmer Go Website • Docs • Slack Channel A complete and mature WebAssembly runtime for Go based on Wasmer. Features Easy to use: The wasmer API mimics

Dec 29, 2022
wazero: the zero dependency WebAssembly runtime for Go developers

wazero: the zero dependency WebAssembly runtime for Go developers WebAssembly is a way to safely run code compiled in other languages. Runtimes execut

Jan 2, 2023
Go compiler for small places. Microcontrollers, WebAssembly, and command-line tools. Based on LLVM.

TinyGo - Go compiler for small places TinyGo is a Go compiler intended for use in small places such as microcontrollers, WebAssembly (Wasm), and comma

Dec 30, 2022
WebAssembly interop between Go and JS values.

vert Package vert provides WebAssembly interop between Go and JS values. Install GOOS=js GOARCH=wasm go get github.com/norunners/vert Examples Hello W

Dec 28, 2022
WebAssembly for Proxies (Golang host implementation)

WebAssembly for Proxies (GoLang host implementation) The GoLang implementation for proxy-wasm, enabling developer to run proxy-wasm extensions in Go.

Dec 29, 2022
Golang-WASM provides a simple idiomatic, and comprehensive API and bindings for working with WebAssembly for Go and JavaScript developers
Golang-WASM provides a simple idiomatic, and comprehensive API and bindings for working with WebAssembly for Go and JavaScript developers

A bridge and bindings for JS DOM API with Go WebAssembly. Written by Team Ortix - Hamza Ali and Chan Wen Xu. GOOS=js GOARCH=wasm go get -u github.com/

Dec 22, 2022
A package to build progressive web apps with Go programming language and WebAssembly.
A package to build progressive web apps with Go programming language and WebAssembly.

Go-app is a package for building progressive web apps (PWA) with the Go programming language (Golang) and WebAssembly (Wasm). Shaping a UI is done by

Dec 30, 2022
A package to build progressive web apps with Go programming language and WebAssembly.
A package to build progressive web apps with Go programming language and WebAssembly.

Go-app is a package for building progressive web apps (PWA) with the Go programming language (Golang) and WebAssembly (Wasm). Shaping a UI is done by

Jan 2, 2023
Vugu: A modern UI library for Go+WebAssembly (experimental)

Vugu: A modern UI library for Go+WebAssembly (experimental)

Jan 3, 2023
A template project to demonstrate how to run WebAssembly functions as sidecar microservices in dapr
A template project to demonstrate how to run WebAssembly functions as sidecar microservices in dapr

Live Demo 1. Introduction DAPR is a portable, event-driven runtime that makes it easy for any developer to build resilient, stateless and stateful app

Jan 3, 2023