CI\CD

这是在 Mac 上构建的命令。

goreleaser --rm-dist --snapshot
rm-dist/distsnapshotrelease

而当我在 Mac 上运行它时,它在构建 Linux 的二进制文件时失败了。

• releasing using Goreleaser 0.106.0...
• loading config file       file=.goreleaser.yml
... [TRUNCATED]
• BUILDING BINARIES
   • building                  binary=dist/darwin_amd64/mailchain
   • building                  binary=dist/linux_amd64/mailchain
   ⨯ release failed after 9.40s error=failed to build for Linux_amd64: # os/user
/usr/local/Cellar/go/1.12.4/libexec/src/os/user/getgrouplist_unix.go:16:35: warning: passing 'gid_t *' (aka 'unsigned int *') to parameter of type 'int *' converts between pointers to integer types with different sign [-Wpointer-sign]
... [TRUNCATED]
ld: warning: option -s is obsolete and being ignored
ld: warning: ignoring file
... [TRUNCATED]
  "__cgoexp_07a0021afc18_secp256k1GoPanicError", referenced from:
      _secp256k1GoPanicError in 000023.o
  "__cgoexp_07a0021afc18_secp256k1GoPanicIllegal", referenced from:
      _secp256k1GoPanicIllegal in 000023.o
  "_crosscall2", referenced from:
      _secp256k1GoPanicIllegal in 000023.o
      _secp256k1GoPanicError in 000023.o
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这是怎么回事?

问题是一个库依赖于 C 并需要 CGO 。我很喜欢在我的工具包中使用 !所以我深入研究了一下,发现这是一个针对不同操作系统进行编译需要安装正确的依赖包的问题。 Docker 似乎非常适合解决这个问题,甚至还有一个 CGO 的 docker 容器。

docker run --rm --privileged \
-v ($pwd):/go/src/github.com/mailchain/mailchain \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/mailchain/mailchain \
goreleaser/goreleaser:latest-cgo release --snapshot --rm-dist
rm-v ($pwd):/go/src/github.com/:org/:repo-w /go/src/github.com/:org/:repogo/src
:org:repo
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: newIPCConnection

我们正在取得进展 ......

github.com/ethereum/go-ethereum@v.1.8.26/crypto/secp256k1
docker run --rm --privileged \
-v ($pwd):/go/src/github.com/mailchain/mailchain \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/mailchain/mailchain \
mailchain/goreleaser-xcgo Goreleaser --snapshot --rm-dist

成功!


这次它创建了所有二进制文件。

• 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.99s
.goreleaser.yml

如果你想更多的了解我们关于 Mailchain 的工作,请访问 https://github.com/mailchain/mailchain

谢谢


本文由 原创编译, 荣誉推出