Skip to content

Instantly share code, notes, and snippets.

@kuuote
Last active July 19, 2021 13:25
Show Gist options
  • Save kuuote/e025f42c34746d9a72cfb890eed9838b to your computer and use it in GitHub Desktop.
Save kuuote/e025f42c34746d9a72cfb890eed9838b to your computer and use it in GitHub Desktop.
denopsでGoのwasm読めるぞ
#!/bin/bash -u
go mod init hoge
GOOS=js GOARCH=wasm go build -v -o main.wasm
package main
import "fmt"
func main() {
fmt.Println("Hello from go")
}
import { Denops } from "https://deno.land/x/denops_std@v1.0.0/mod.ts";
import "./wasm_exec.js";
declare const global: any;
export async function main(denops: Denops) {
const go = new global.Go();
// https://github.com/denoland/deno/issues/1286#issuecomment-616613844
const f = await Deno.readFile(new URL("main.wasm", import.meta.url).pathname);
const inst = await WebAssembly.instantiate(f, go.importObject);
go.run(inst.instance);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment