Last active
July 19, 2021 13:25
-
-
Save kuuote/e025f42c34746d9a72cfb890eed9838b to your computer and use it in GitHub Desktop.
denopsでGoのwasm読めるぞ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -u | |
go mod init hoge | |
GOOS=js GOARCH=wasm go build -v -o main.wasm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
fmt.Println("Hello from go") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Denops } from "https://deno.land/x/[email protected]/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