{"id":13489650,"url":"https://github.com/wasmerio/wasmer-go","last_synced_at":"2025-05-13T16:09:53.512Z","repository":{"id":37421835,"uuid":"184419299","full_name":"wasmerio/wasmer-go","owner":"wasmerio","description":"🐹🕸️ WebAssembly runtime for Go","archived":false,"fork":false,"pushed_at":"2025-02-01T18:39:34.000Z","size":122823,"stargazers_count":2878,"open_issues_count":79,"forks_count":165,"subscribers_count":48,"default_branch":"master","last_synced_at":"2025-04-23T20:53:25.219Z","etag":null,"topics":["golang","golang-library","rust","wasm","webassembly"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/wasmerio/wasmer-go","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wasmerio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-01T13:21:28.000Z","updated_at":"2025-04-18T06:09:01.000Z","dependencies_parsed_at":"2024-04-16T23:41:49.899Z","dependency_job_id":"caa6d93b-ff38-419d-b460-95e3adfbf531","html_url":"https://github.com/wasmerio/wasmer-go","commit_stats":{"total_commits":535,"total_committers":24,"mean_commits":"22.291666666666668","dds":0.5588785046728972,"last_synced_commit":"ca60a4524acf4fc518ced3bfd818d960804a0bee"},"previous_names":["wasmerio/go-ext-wasm"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Fwasmer-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Fwasmer-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Fwasmer-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Fwasmer-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wasmerio","download_url":"https://codeload.github.com/wasmerio/wasmer-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250514767,"owners_count":21443208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","golang-library","rust","wasm","webassembly"],"created_at":"2024-07-31T19:00:32.537Z","updated_at":"2025-04-23T20:53:50.653Z","avatar_url":"https://github.com/wasmerio.png","language":"Go","funding_links":[],"categories":["Go Runtimes","Go"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://wasmer.io\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\n    \u003cimg width=\"300\" src=\"https://raw.githubusercontent.com/wasmerio/wasmer/master/assets/logo.png\" alt=\"Wasmer logo\"\u003e\n  \u003c/a\u003e\n  \n  \u003ch1\u003eWasmer Go\u003c/h1\u003e\n  \n  \u003cp\u003e\n    \u003ca href=\"https://github.com/wasmerio/wasmer-go/actions?query=workflow%3A%22Build+and+Test%22\"\u003e\n      \u003cimg src=\"https://github.com/wasmerio/wasmer-go/workflows/Build%20and%20Test/badge.svg\" alt=\"Build Status\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/wasmerio/wasmer-go/blob/master/LICENSE\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/license/wasmerio/wasmer-go.svg\" alt=\"License\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/go.dev-package-f06\" alt=\"Go Package\"\u003e\n    \u003c/a\u003e \n    \u003ca href=\"https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer?tab=doc\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/documentation-API-f06\" alt=\"API Documentation\"\u003e\n    \u003c/a\u003e \n  \u003c/p\u003e\n\n  \u003ch3\u003e\n    \u003ca href=\"https://wasmer.io/\"\u003eWebsite\u003c/a\u003e\n    \u003cspan\u003e • \u003c/span\u003e\n    \u003ca href=\"https://docs.wasmer.io\"\u003eDocs\u003c/a\u003e\n    \u003cspan\u003e • \u003c/span\u003e\n    \u003ca href=\"https://slack.wasmer.io/\"\u003eSlack Channel\u003c/a\u003e\n  \u003c/h3\u003e\n\n\u003c/div\u003e\n\n\u003chr/\u003e\n\nA complete and mature WebAssembly runtime for Go based on\n[Wasmer](https://github.com/wasmerio/wasmer).\n\nFeatures\n\n  * **Easy to use**: The `wasmer` API mimics the standard WebAssembly API,\n  * **Fast**: `wasmer` executes the WebAssembly modules as fast as\n    possible, close to **native speed**,\n  * **Safe**: All calls to WebAssembly will be fast, but more\n    importantly, completely safe and sandboxed.\n    \n**Documentation**: [browse the detailed API\ndocumentation](https://pkg.go.dev/github.com/wasmerio/wasmer-go/wasmer)\nfull of examples.\n\n**Examples** as tutorials: [browse the `examples/`\ndirectory](https://github.com/wasmerio/wasmer-go/tree/master/examples),\nit's the best place for a complete introduction!\n\n# Install\n\nTo install the library, follow the classical:\n\n```sh\n$ go get github.com/wasmerio/wasmer-go/wasmer\n```\n\nAnd you're ready to get fun!\n\n## Supported platforms\n\nThis library embeds the Wasmer runtime compiled as shared library\nobjects, and so uses [`cgo`](https://golang.org/cmd/cgo/) to consume\nit. A set of precompiled shared library objects are provided. Thus\nthis library works (and is tested) on the following platforms:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003ePlatform\u003c/th\u003e\n      \u003cth\u003eArchitecture\u003c/th\u003e\n      \u003cth\u003eTriple\u003c/th\u003e\n      \u003cth\u003eStatus\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd rowspan=\"2\"\u003eLinux\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003eamd64\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003ex86_64-unknown-linux-gnu\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e✅\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003eaarch64\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003eaarch64-unknown-linux-gnu\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e✅\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd rowspan=\"2\"\u003eDarwin\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003eamd64\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003ex86_64-apple-darwin\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e✅\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003eaarch64\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003eaarch64-apple-darwin\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e⏳\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eWindows\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003eamd64\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003ex86_64-pc-windows-msvc\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e⏳\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eWhat to do if your platform is missing?\u003c/summary\u003e\n  \n  Up to now, there is no script to automate that process. [We are\n  working on it](https://github.com/wasmerio/wasmer-go/issues/191).\n\n  Here are the steps to do that manually:\n  \n  ```sh\n  $ # Build the new Wasmer C API shared object library.\n  $ cargo build --release\n  $\n  $ # Configure cgo.\n  $ export CGO_CFLAGS=\"-I$(pwd)/wasmer/packaged/include/\"\n  $ export CGO_LDFLAGS=\"-Wl,-rpath,$(pwd)/target/release/ -L$(pwd)/target/release/ -lwasmer_go\"\n  $\n  $ # Run the tests.\n  $ just test -tags custom_wasmer_runtime\n  ```\n\u003c/details\u003e\n\n# Examples\n\nWe highly recommend to read the\n[`examples/`](https://github.com/wasmerio/wasmer-go/tree/master/examples)\ndirectory, which contains a sequence of examples/tutorials. It's the\nbest place to learn by reading examples.\n\nBut for the most eager of you, there is a quick toy program in\n`examples/appendices/simple.go`, written in Rust:\n\n```rust\n#[no_mangle]\npub extern \"C\" fn sum(x: i32, y: i32) -\u003e i32 {\n    x + y\n}\n```\n\nA compiled WebAssembly binary is included in\n[`examples/appendices/simple.wasm`]((https://github.com/wasmerio/wasmer-go/blob/master/examples/appendices/simple.wasm)).\n\nThen, we can execute it in Go:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\twasmer \"github.com/wasmerio/wasmer-go/wasmer\"\n)\n\nfunc main() {\n    wasmBytes, _ := os.ReadFile(\"simple.wasm\")\n\n    engine := wasmer.NewEngine()\n    store := wasmer.NewStore(engine)\n\n    // Compiles the module\n    module, _ := wasmer.NewModule(store, wasmBytes)\n\n    // Instantiates the module\n    importObject := wasmer.NewImportObject()\n    instance, _ := wasmer.NewInstance(module, importObject)\n\n    // Gets the `sum` exported function from the WebAssembly instance.\n    sum, _ := instance.Exports.GetFunction(\"sum\")\n\n    // Calls that exported function with Go standard values. The WebAssembly\n    // types are inferred and values are casted automatically.\n    result, _ := sum(5, 37)\n\n    fmt.Println(result) // 42!\n}\n```\n\nAnd then, finally, enjoy by running:\n\n```sh\n$ cd examples/appendices/\n$ go run simple.go\n42\n```\n\n# Testing\n\nRun the tests with the following command:\n\n```sh\n$ just test\n```\n\n# What is WebAssembly?\n\nQuoting [the WebAssembly site](https://webassembly.org/):\n\n\u003e WebAssembly (abbreviated Wasm) is a binary instruction format for a\n\u003e stack-based virtual machine. Wasm is designed as a portable target\n\u003e for compilation of high-level languages like C/C++/Rust, enabling\n\u003e deployment on the web for client and server applications.\n\nAbout speed:\n\n\u003e WebAssembly aims to execute at native speed by taking advantage of\n\u003e [common hardware\n\u003e capabilities](https://webassembly.org/docs/portability/#assumptions-for-efficient-execution)\n\u003e available on a wide range of platforms.\n\nAbout safety:\n\n\u003e WebAssembly describes a memory-safe, sandboxed [execution\n\u003e environment](https://webassembly.org/docs/semantics/#linear-memory) […].\n\n# License\n\nThe entire project is under the MIT License. Please read [the\n`LICENSE` file][license].\n\n\n[license]: https://github.com/wasmerio/wasmer/blob/master/LICENSE\n\n# FAQ\n\n## How to run Go programs compiled to WebAssembly modules with `wasmer-go`?\n\nLet's start by emphasing that `wasmer-go` is a WebAssembly runtime. It\nallows to _run_ WebAssembly inside Go. It's not a tool to _compile_ a\nGo program into WebAssembly. Nonetheless, many people are reporting\nissues when compiling Go programs to WebAssembly, and then trying to\nrun them with `wasmer-go` (or in another hosts, like\n[Python](https://github.com/wasmerio/wasmer-python),\n[C](https://github.com/wasmerio/wasmer/tree/master/lib/c-api),\n[PHP](https://github.com/wasmerio/wasmer-php),\n[Ruby](https://github.com/wasmerio/wasmer-ruby),\n[Rust](https://github.com/wasmerio/wasmer)…).\n\nThe major problem is that, whilst the Go compiler supports\nWebAssembly, [it does not support\nWASI](https://github.com/golang/go/issues/31105) (WebAssembly System\nInterface). It generates an ABI that is deeply tied to JavaScript, and\none needs to use the `wasm_exec.js` file provided by the Go toolchain,\nwhich doesn't work outside a JavaScript host.\n\nFortunately, there are two solutions to this problem:\n\n1. Use [TinyGo](https://tinygo.org) to compile your Go program to\n   WebAssembly with the `-target wasi` option, e.g.:\n   \n   ```sh\n   $ tinygo build -o module.wasm -target wasi .\n   ```\n   \n   The generated WebAssembly module will be portable across all\n   WebAssembly runtimes that support WASI.\n\n2. Use the Go compiler with adapters. Let's see how to compile:\n\n   ```sh\n   $ GOOS=js GOARCH=wasm go build -o module.wasm .\n   ```\n   \n   (the `GOOS=js` is the sign that JavaScript is targeted, not a surprise).\n   \n   Then pick one adapter (they are written by the community):\n   \n   * [`mattn/gowasmer`](https://github.com/mattn/gowasmer/),\n   * [`go-wasm-adapter/go-wasm`](https://github.com/go-wasm-adapter/go-wasm/),\n\n   and follow their documentation.\n\nWe highly recommend the first solution (with TinyGo) if it works for\nyou as the WebAssembly module will be portable across all WebAssembly\nruntimes. It's not a hacky solution based on adapters; it's the right\nway to… go.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasmerio%2Fwasmer-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwasmerio%2Fwasmer-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasmerio%2Fwasmer-go/lists"}