4 ms·
If someone is interested in running golang projects on niche hardware perhaps, one pro tip I can suggest but there is way to convert golang 100% into wasm (no j
by Imustaskforhelp 10mo ago
If someone is interested in running golang projects on niche hardware perhaps, one pro tip I can suggest but there is way to convert golang 100% into wasm (no js shim or anything required) and the only thing you would need is a wasm library
You have to use golang from source (see the stackoverflow page https://stackoverflow.com/questions/76087007/golang-to-wasm-compilation https://stackoverflow.com/questions/76087007/golang-to-wasm-... )
go install golang.org/dl/gotip@latest
gotip download
GOOS=wasip1 GOARCH=wasm gotip build -o main.wasm
Although the way I did it is going into the gotip folder and then the binary folder which would contain the go compiler binary and then just use that path with
GOOS=wasip1 GOARCH=wasm ~/sdk/gotip/bin/go build -o main.wasm
Note that I forgot the exact path but it was similar to this but the point being that its super easy and simple :)
I tried to do it and I can tell you that it works and it works for even the most latest versions of golang, all you need is a wasmengine which I suppose can be ubiquitous.
I have built a solution where golang code gets converted to wasm and then we run a ssh server which then runs that wasm all in sandbox to create sandboxed mini golang servers :p I really love it although its a more so prototype than anything
- gothink 10mo agoLooks like this is available (since Go 1.21 [0]), so no need to build from source anymore. Just did a quick 'hello world' test to verify and it worked: GOOS=wasip1 GOARCH=wasm go build -o main.wasm main.go wasmtime main.wasm If you're interested in wasm/wasi and niche hardware with Go, you should check out TinyGo [1] if you haven't already. [0] https://go.dev/blog/wasi https://go.dev/blog/wasi [1] https://tinygo.org/docs/guides/webassembly/wasi/ https://tinygo.org/docs/guides/webassembly/wasi/
- Imustaskforhelp 10mo agoOh wow thanks for telling me, looks like I was using gotip/ source go for no reason but thanks for telling me this, this actually really simplifies a lot of things :p Tinygo is really awesome but I have heard that it has its differences so software written for golang won't really work ootb on tinygo and tinygo is really fascinating project too! I have a question but is it possible to create golang compiler itself within wasm itself. I tried doing it but it didn't really work out but I am curious if someone has thought of doing something like this or has already done it?