3 ms·
>This package uses the novel (at least, novel to me) method of embedding a small C program (Trealla Prolog) through WASM/WASI and exposing it as a regular Go li
by brokenkebab2 4y ago
>This package uses the novel (at least, novel to me) method of embedding a small C program (Trealla Prolog) through WASM/WASI and exposing it as a regular Go library
Could you please expand this with more details?
- speps 4y agoUsing a WASI runtime in Go you can run any code compiled to WASM. That also means you can wrap a C (or other) library compiled to WASM into a Go library.
- grose 4y agoI plan on writing a blog post soon to explain it better. The quick summary is that it uses WASI to execute a C program not entirely unlike oldschool CGI, but now it's inside of a WebAssembly runtime instead of an OS process. It uses command line arguments to send the query and standard output to grab the results. This may become fancier in the future. You can see the relevant code here: https://github.com/guregu/trealla-go/blob/333645147df083dd26f72518cc9903b1ce9c1721/trealla.go#L119 https://github.com/guregu/trealla-go/blob/333645147df083dd26... that builds up the command line arguments for tpl (the Trealla binary, shoved into the repo as tpl.wasm). The rest of the package is mostly shuffling data around.