kothar / brotli-go

Not maintained -> see itch.io's more up-to-date fork 👉
https://github.com/itchio/go-brotli
MIT License
82 stars 9 forks source link

It won't cross compile for Linux/amd64 on MacOs. #34

Closed mehmetg closed 7 years ago

mehmetg commented 7 years ago

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

kothar commented 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

mehmetg commented 7 years ago

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?

kothar commented 7 years ago

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

fasterthanlime commented 7 years ago

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.

dsnet commented 7 years ago

FYI, you can compile brotli as a shared object, which is significantly easier to dynamically link in than the static approach you taking here.

See https://github.com/dsnet/compress/blob/619c68bc20d0be0da0563304ea093066c4190cad/internal/cgo/brotli/brotli.go