Closed mehmetg closed 7 years ago
Hi, this package wraps the C/C++ implementation of Brotli, which means you can't use the usual GOOS=xxxx
cross-compilation method. I think it's possible to cross compile with cgo, but I've not tried it myself.
https://gist.github.com/steeve/6905542
I imagine it would be easier to install Docker for Mac and use a suitable image containing go to do the actual compilation, rather than trying to cross-compile directly. You could still get that to map your working directory and run everything from the command line.
Alternatively, @dsnet has a pure-go implementation of the decompression algorithm, which may be easier for your use case as you don't need to compress anything: https://github.com/dsnet/compress/tree/master/brotli
Thank you for the pointers. For now I'll stick with the VM/Docker solution as it is the fastest. Do you expect performance gain/loss between the wrapper and pure go solution?
Currently the pure go version is about 2-3x slower than the pure C version, but I'm not sure how much overhead this wrapper adds to that (it should be minimal).
dsnet has done some extensive benchmarking of his implementation here: https://github.com/dsnet/compress/wiki/Performance-Metrics#brotli
I've had success cross-compiling cgo code using gox - see https://github.com/itchio/butler/blob/master/scripts/ci-build.sh for how we use it in production.
FYI, you can compile brotli as a shared object, which is significantly easier to dynamically link in than the static approach you taking here.
Error message on MacOS: ../../../gopkg.in/kothar/brotli-go.v0/dec/decode.go:36:2: no buildable Go source files in /Users/mehmetgerceker/workspace/goWorkspace/src/gopkg.in/kothar/brotli-go.v0/shared
Error message on Linux: main.go:14:2: C source files not allowed when not using cgo or SWIG: bit_reader.c decode.c huffman.c state.c streams.c ../../../gopkg.in/kothar/brotli-go.v0/dec/decode.go:36:2: no buildable Go source files in /home/mehmetg/gohome/src/gopkg.in/kothar/brotli-go.v0/shared
Project: github.com/mehmetg/simpleJSONService