From b5e5b3567c61ecbfd9094307e4efa53e3be3e23e Mon Sep 17 00:00:00 2001 From: Jeremy Schlatter Date: Tue, 19 Feb 2019 03:18:37 -0800 Subject: [PATCH] crypto: fix build when CGO_ENABLED=0 (#19121) Package crypto works with or without cgo, which is great. However, to make it work without cgo required setting the build tag `nocgo`. It's common to disable cgo by instead just setting the environment variable `CGO_ENABLED=0`. Setting this environment variable does _not_ implicitly set the build tag `nocgo`. So projects that try to build the crypto package with `CGO_ENABLED=0` will fail. I have done this myself several times. Until today, I had just assumed that this meant that this package requires cgo. But a small build tag change will make this case work. Instead of using `nocgo` and `!nocgo`, we can use `!cgo` and `cgo`, respectively. The `cgo` build tag is automatically set if cgo is enabled, and unset if it is disabled. --- crypto/signature_cgo.go | 2 +- crypto/signature_nocgo.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/signature_cgo.go b/crypto/signature_cgo.go index 340bfc221e..aadf028d26 100644 --- a/crypto/signature_cgo.go +++ b/crypto/signature_cgo.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -// +build !nacl,!js,!nocgo +// +build !nacl,!js,cgo package crypto diff --git a/crypto/signature_nocgo.go b/crypto/signature_nocgo.go index e8fa18ed47..90d072cda7 100644 --- a/crypto/signature_nocgo.go +++ b/crypto/signature_nocgo.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -// +build nacl js nocgo +// +build nacl js !cgo package crypto