-
Notifications
You must be signed in to change notification settings - Fork 932
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
WebAssembly support #45
Conversation
2415138
to
5d87aed
Compare
For the "write to stdout (how?)" item, @Xe has been developing a runtime environment for Wasm, so might be useful for implementation ideas/direction. 😄 |
Oh hey! I'd love to collaborate on this using https://github.com/Xe/olin as the runtime for server-side tinygo binaries. The host functions its tool (module
;; import functions from env
(func $getStdio (import "cwa" "io_get_stdout") (result i32))
(func $write (import "cwa" "resource_write") (param i32 i32 i32) (result i32))
(func $close (import "cwa" "resource_close") (param i32))
;; memory
(memory $mem 1)
;; constants
(data (i32.const 230) "Hello, world!\n")
(func $main (result i32)
;; $fd is the file descriptor of the file we're gonna open
(local $fd i32)
;; $fd = $getStdio();
(set_local $fd
(call $getStdio))
;; $write($fd, "Hello, World!\n", 14);
(call $write
(get_local $fd)
(i32.const 230)
(i32.const 14))
(drop)
;; $close($fd);
(call $close
(get_local $fd))
(i32.const 0))
(export "cwa_main" (func $main))) This also has time. I am more than willing to work with you for more runtime support, please just name what you want. |
Looks like olin could be very useful for testing! The only missing thing I see so far is support for sleeping for a given duration, e.g. |
Out of curiosity, what's the file size of that minimal working example of WebAssembly? With mainline Go... minimum file size of generated Wasm (so far) is ~2MB. 😉 |
Very small.
(Not sure why debug info affects file size, I should investigate that one). |
Holy crap. Whooo!!!!! Again, you rock! 😄 |
@aykevl This is a super exciting development. Would you be interested in joining the Go WASM discussion on the Gophers Slack #webassembly channel? https://invite.slack.golangbridge.org/. |
Thanks for letting me know! I've joined #webassembly. Also, just fixed a tiny missed optimization in 3babdfd reducing .wasm size to 174 bytes (160 when compressed). But please note that this small file size is only because the entire runtime gets optimized away by LLVM as it isn't used - an equivalent C program compiled with Clang will probably end up with about the same filesize. A program that actually does something useful and needs some runtime support will probably end up in the range of a few kilobytes. A hello world perhaps half a kilobyte. The scheduler costs something like 2kB on ARM. |
Yeah, this is pretty incredibly awesome. |
@aykevl With the wasm.html example, it might be better to remove the |
That's a standard DOCTYPE. If it screws up WebAssembly in Firefox, that's a bug in Firefox. Can you give some more details on what exactly goes wrong and when? |
Almost finished, I only need to get the tests to pass.
|
Yeah, fully agree. I came across it when adding the files here: That basic WebGL triangle (and it's counterpart rotating cube) seem like good intro examples for WebGL + Wasm. So I took a bit of time to get the needed bits in place to have GitHub pages serve them directly. With my Firefox (60.2.x esr version) running on CentOS 7... the Wasm would 100% never be displayed when that doctype line was in the file, but would work fine with it removed. Was 100% repeatable every time (served locally via Caddy when developing), so I just removed it and made a mental note of the problem. Haven't investigated it any further, and wouldn't really know where to start. (nor all that interested really, I'm focused on other stuff 😉) |
Oh as a data point, I'm pretty sure no error message was displayed on the javascript console either when it didn't work. That's the usual place to watch out for Wasm errors when executing in a browser. |
Maybe leaving out the DOCTYPE triggers quirks mode which fixes a problem with the HTML or CSS? I strongly prefer avoiding anything non-standard unless I know exactly why that is necessary - and currently I don't. |
Yeah, not sure. I just noticed it at the time, and it was completely reproducible. So I made the alteration and moved on. If it crops up again, we can look into it then. 😉 |
Is there any way to set func import names? Example //go:import _some_func
func someFunc() |
Yes: //go:linkname someFunc _some_func
func someFunc() |
It seems that the import would be prefixed by the package name (ex: Additionally, what about changing the import namespace? |
Work-in-progress (totally unfinished) branch for WebAssembly support.
TODO:
time.Sleep
/time.Now
to workruntime.alloc
fixes #44