Cross compile with CGO and GoReleaser

I looked deeper into the issue.

It’s a case of ensuring all the right libraries are installed for CGO to compile against different operating systems.

Docker seems and excellent fit, there’s even a docker container for CGO.

Run goreleaser/goreleaserrm Starts with a fresh docker container each time.

-v ($pwd):/go/src/github.

com/:org/:repo Creates a volume on the docker container with the contents on of the current directory.

-w /go/src/github.

com/:org/:repoSets the working directory to the code that was created in the go/srcdirectory.

Note: remember to replace :organd :repo with your repository details.

releasing using goreleaser 0.

106.

0.

loading config file file=.

goreleaser.

[TRUNCATED]building binary=dist/darwin_amd64/mailchain⨯ release failed after 163.

82s error=failed to build for darwin_amd64: go build github.

com/ethereum/go-ethereum/crypto/secp256k1: build constraints exclude all Go files in /go/pkg/mod/github.

com/ethereum/go-ethereum@v1.

8.

26/crypto/secp256k1# github.

com/ethereum/go-ethereum/rpc/go/pkg/mod/github.

com/ethereum/go-ethereum@v1.

8.

26/rpc/endpoints.

go:96:19: undefined: ipcListen/go/pkg/mod/github.

com/ethereum/go-ethereum@v1.

8.

26/rpc/ipc.

go:50:10: undefined: newIPCConnectionWe are making progress…But I get a different error this time that does not look related to CGO.

It is though, github.

com/ethereum/go-ethereum@v.

1.

8.

26/crypto/secp256k1 is the location of the C dependency.

Looks like I need is a docker container that has CGO libraries and is able to cross compile into Linux, OSX, and Windows.

Enter goreleaser-xcgo, a docker container with all of the required binaries and the latest version of GoReleaser.

Usage is similar to before.

Run with https://github.

com/mailchain/goreleaser-xcgoSuccess!!! :)This time it creates all the binaries are built.

• releasing using goreleaser 0.

106.

0.

[TRUNCATED]• BUILDING BINARIES • building binary=dist/darwin_amd64/mailchain • building binary=dist/linux_amd64/mailchain • building binary=dist/windows_amd64/mailchain.

exe.

[TRUNCATED]• release succeeded after 330.

99sTo see it working the configuration file .

goreleaser.

yml is here, to see how its integrated with travis here is the .

travis.

yml configuration.

If you want to find out more about what we are building at Mailchain find us at https://github.

com/mailchain/mailchainThanks.. More details

Leave a Reply