valyala / gozstd

go wrapper for zstd
MIT License
432 stars 60 forks source link

Cross compilation fails #21

Closed rolandjitsu closed 4 years ago

rolandjitsu commented 4 years ago

As reported in https://github.com/vmihailenco/taskq/issues/55, if I try to cross compile a project that has a indirect dependency on this package I get:

❯ env GOOS=linux GOARCH=arm CGO_ENABLED=0 go build ./cmd/api/main.go                   
# github.com/valyala/gozstd
../../go/pkg/mod/github.com/valyala/gozstd@v1.6.2/stream.go:31:59: undefined: CDict
../../go/pkg/mod/github.com/valyala/gozstd@v1.6.2/stream.go:35:64: undefined: CDict
../../go/pkg/mod/github.com/valyala/gozstd@v1.6.2/stream.go:47:20: undefined: Writer
valyala commented 4 years ago

Try running the following command before building the app:

cd ../../go/pkg/mod/github.com/valyala/gozstd && make clean libzstd.a

This command should re-build libzstd.a file for the host GOOS and GOARCH as mentioned in the FAQ.

rolandjitsu commented 4 years ago

I managed to build it with a C cross compiler:

env CC=arm-linux-gnueabi-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 go build ./cmd/api/main.go 

But I could only do this on Linux. So I use docker to cross compile on a Mac.

I'm not sure if your suggestion would work if I do it on macOS and use the resulted binary on an ARM architecture.

valyala commented 4 years ago

I'm not sure if your suggestion would work if I do it on macOS and use the resulted binary on an ARM architecture.

My suggestion will work only when building binaries for host system. It doesn't work for cross-compilation :(

rolandjitsu commented 4 years ago

I'm not sure if your suggestion would work if I do it on macOS and use the resulted binary on an ARM architecture.

My suggestion will work only when building binaries for host system. It doesn't work for cross-compilation :(

That's ok, it can be done using docker, so that's good enough I'd say. I will close this issue, but maybe it's worth mentioning in the docs that one must use a C cross compiler and the appropriate flags when cross compiling.

valyala commented 4 years ago

maybe it's worth mentioning in the docs that one must use a C cross compiler and the appropriate flags when cross compiling.

Agreed. Could you prepare the corresponding pull request?