Skip to content

Commit 8bfade1

Browse files
jeremyschlatterkiku-jw
authored andcommitted
crypto: fix build when CGO_ENABLED=0 (ethereum#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.
1 parent 01ef169 commit 8bfade1

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

crypto/signature_cgo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
1616

17-
// +build !nacl,!js,!nocgo
17+
// +build !nacl,!js,cgo
1818

1919
package crypto
2020

crypto/signature_nocgo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
1616

17-
// +build nacl js nocgo
17+
// +build nacl js !cgo
1818

1919
package crypto
2020

0 commit comments

Comments
 (0)