Skip to content

Pikchr wrapped for Go using WebAssembly. No cgo required.

License

Notifications You must be signed in to change notification settings

rigtorp/go-pikchr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pikchr for Go

This package wraps Pikchr as a Go package. It doesn't rely on cgo or an external binary, instead using the wazero 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:

$ 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 and extract it somewhere.

Next build Pikchr:

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.

About

Pikchr wrapped for Go using WebAssembly. No cgo required.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages