Cross compiling Go app with go-sqlite3 on Docker6th April 2017
go-sqlite3 using CGO for binding sqlite3 to go library. That requires cross compilers for each target platform. First, I tried to setup mingw64, etc for each platform. But it was easy to implement if you are familiar with xgo.
xgo is a Docker images that pre configured for each Go version and target platforms.
If you are using glide for packaging system. Prepare Dockerfile like below.
FROM karalabe/xgo-1.7.x RUN apt-get update -y RUN apt-get upgrade -y RUN apt-get install -y zip git curl ENV GOBIN=/usr/local/go/bin ENV PATH=$PATH:/usr/local/go/bin RUN curl https://glide.sh/get | sh
Then, just build with
xgo command like below.
xgo --ldflags="$LD_FLAGS" -targets "windows/*,linux/*,darwin/*" github.com/watermint/toolbox/tools/$t