This is an experimental POC for deploying a canister written in Go on the IC. It contains an hello world example that works, but there are likely to be problems using any libraries.
-
Install Tinygo from source(https://tinygo.org/docs/guides/build/) with the following patch:
diff --git a/targets/wasm-unknown.json b/targets/wasm-unknown.json index 903afa49..55ca4c70 100644 --- a/targets/wasm-unknown.json +++ b/targets/wasm-unknown.json @@ -1,7 +1,7 @@ { "llvm-target": "wasm32-unknown-unknown", "cpu": "generic", - "features": "+mutable-globals,+nontrapping-fptoint,+sign-ext,-bulk-memory", + "features": "+mutable-globals,+nontrapping-fptoint,+sign-ext,+bulk-memory", "build-tags": ["tinygo.wasm", "wasm_unknown"], "goos": "linux", "goarch": "arm", @@ -11,18 +11,17 @@ "gc": "leaking", "default-stack-size": 4096, "cflags": [ - "-mno-bulk-memory", "-mnontrapping-fptoint", "-msign-ext" ], "ldflags": [ "--stack-first", "--no-demangle", - "--no-entry", - "--import-memory" + "--no-entry" ], "extra-files": [ "src/runtime/asm_tinygowasm.S" ], "emulator": "wasmtime --dir={tmpDir}::/tmp {}" }
(I used commit https://github.com/tinygo-org/tinygo/commit/377415a6c3158d5cefe8cd46c592b144053593aa)
This patch will enable the bulk memory operations Wasm feature and define a memory instead of importing one.
-
Install
dfx
(recommended using dfxvm).
- Start a local
dfx
subnet.dfx start --clean --background
- Build, deploy and send a message to the canister by executing
run.sh
. This assumestinygo
was installed to~/go/bin/tinygo
.