-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Go language support #32
Comments
Your demo is slick! I don't use Go yet, but would love to see this supported! |
How does using this compare to something like https://github.com/tinygo-org/tinygo? |
The main thing that compelled me to bring up goscript is that it is an interpreter so the Go code doesn't have to be compiled. If you try the tiny-go playground and open the network tab its compiling the code on a server and sending back the wasm for the client to run. This can be very appealing since it means getting Go to work with the library is painless. That being said, goscript is missing a lot from Go's standard lib. Like I think at this point it would only be maybe viable for an introductory Go course on Slip for example. Obviously, tiny-go is a much more mature project supporting more features so it comes down to how much we value supporting a larger feature set at this time and if we don't mind the users of the library to have to setup a server to compile the Go code. Or we could go halfway and have users of the library by default use goscript and can opt in to tiny-go + server side compilation if their needs demand it. What do you guys think? |
Hmm that's weird, think it's just vague wording on the docs, I poked around the TinyGo playground's source code and I see that they setup an Here's the network tab of Chrome devtools where I see the wasm being spit out: Think to get TinyGo working solely in the browser we would have to compile the TinyGo compiler to wasm so we can compile Go to wasm inside wasm 🤯 If we choose the TinyGo server-side compilation route I guess it wouldn't be too difficult to pull some of the code from the playground to get it working |
Why not have the actual go compiler compile to wasm? Go does have wasm support! |
TinyGo is preferred because it strips some of the runtime bloat since go wasm binaries are known to be c h o n k y, but none of these can be used if we want to only run Go in the browser without any server-side compilation. For that we would need a Go interpreter (goscript), or some Go compiler that can be compiled to wasm so we can compile the Go code on the client side in the browser. |
I think we just ship goscript and then long term experiment on figuring out a way to either add more libs or find support for tinygo! Ship and iterate is the move 🥷 |
Sounds like a good plan 🚢 ♻️ I can port over some of my existing code from my demonstration, any specific way you want me to do it? Perhaps we should setup a monorepo multiple-package type structure, I think it would be good to have each of these languages in its own package because wasm binaries can be a bit big |
Yeah that's a good question. I think having a common api across languages is good but that shipping the whole binary for every language is a little unnecessary for folks who want to only execute Python for example. Maybe we should make the user load the binaries via cdn on the front end and they can choose which they want to import? Or we could look at patterns that other similar libraries do this (similar in that they have heavy dependencies and let a user choose which to use). Could you explain your option a bit more? Would it still be one npm library? Or multiple? I'd prefer one, with an option to reduce the total size based on a users preference somehow |
So what I was thinking is we have Then when using the library you do something like this: import RunWasm from `@slip/run-wasm`
import ts from `@slip/run-run-wasm-ts`
const Code = () => {
const [code, setCode] = useState('const fn = () => console.log("hello wasm!")')
return (
<RunWasm language={ts} code={code} />
)
} What do you guys think about this? |
Yeah I'm down with this approach! |
OOh, found this on the Gopher slack: https://github.com/open2b/scriggo Do you think that could come in handy? |
Amazing find @quackduck !! Scriggo has far more complete support for Go's stdlib. Scriggo's playground is already using wasm so I'll definitely try taking a look at that and getting it working 👍 |
Is anyone working on this? |
I dont think so @ntindle, feel free to tackle it! |
Is there any docs on integration of new langs or should I play it by ear? |
RE: the above Go ships with a wasm runner that we should use independent of the compiler (unless the compiler ships their own). It can be found at This means that we only need to set up a Go -> WASM compiler. Based on the above discussions and my own research, I found a few things. There are two options above and one I found:
I would prefer to use wasm-go-playground due to it using the go compiler itself, not a reimplementation. I opened an issue to address some of the concerns I had. If we can't get wasm-go-playground, I would recommend having a Github action that periodically runs the Scriggo compile from the Playground and updates it in the repo. We would then be able to use Scriggo in a very similar way as wasm-go-playground without using the official go compiler. If we wanted to support running pre-compiled Go wasm blobs, it would be trivial to get up. The compilation is the difficult part. Nicholas |
Hey, I recently found the goscript package which is a Go interpreter written in Rust which can be compiled to wasm and used to interpret and run Go code in the browser. I whipped up a quick demo you can try out here.
There are some considerations though:
fmt
package from the Go std lib is supported at this time, this is kind of a big deal but the project maintainer now seems to be focused on completing the rest of the packagesgoscript
uses the filesystem which means it must be compiled to the wasm32-wasi target, which requires a wasm runtime that supports WASI (most browser's dont support it right now). However it's a trivial process to setup wasmer.js which supports WASI (I used this for the demo I linked above)What is everyone's thoughts on this? If there is interest I would be happy to make a PR to implement this 👍
The text was updated successfully, but these errors were encountered: