https://github.com/rigtorp/go-pikchr
Pikchr wrapped for Go using WebAssembly. No cgo required.
https://github.com/rigtorp/go-pikchr
Last synced: 11 months ago
JSON representation
Pikchr wrapped for Go using WebAssembly. No cgo required.
- Host: GitHub
- URL: https://github.com/rigtorp/go-pikchr
- Owner: rigtorp
- License: 0bsd
- Created: 2023-01-04T00:50:06.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-04T03:23:22.000Z (over 3 years ago)
- Last Synced: 2024-12-16T22:23:38.766Z (over 1 year ago)
- Language: Go
- Size: 51.8 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pikchr for Go
This package wraps [Pikchr](https://pikchr.org) as a Go package. It doesn't rely
on cgo or an external binary, instead using the [wazero](https://wazero.io/)
WebAssembly runtime to embed Pikchr.
Wazero is configured to sandbox Pikchr such that Pikchr only has access to the
input and output data.
## Performance
For a small Pikchr figure, go-pikchr takes about 7.5ms:
```shell
$ go test -test.bench .
goos: linux
goarch: amd64
pkg: github.com/rigtorp/go-pikchr
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
BenchmarkPikchr-8 142 7520289 ns/op
PASS
ok github.com/rigtorp/go-pikchr 1.471s
```
## Building Pikchr for WASM
Download [wasi-sdk](https://github.com/WebAssembly/wasi-sdk) and extract it
somewhere.
Next build Pikchr:
```shell
export WASI_SDK_PATH=/path/to/wasi/sdk
$WASI_SDK_PATH/bin/clang pikchr.c -o pikchr.wasm -DPIKCHR_SHELL -Os -DNDEBUG -s
```
## Acknowledgements
I got the idea for this approach of embedding an external program in Go using
WebAssembly from the blog post [The carcinization of Go
programs](https://xeiaso.net/blog/carcinization-golang).