Skip to content

crypto: fix build when CGO_ENABLED=0 #19121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2019
Merged

Conversation

jeremyschlatter
Copy link
Contributor

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.

You can test this change by running:

CGO_ENABLED=0 go test ./crypto

Before this change, that test would fail. After this change, it passes.

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.

You can test this change by running:

	CGO_ENABLED=0 go test ./crypto

Before this change, that test would fail. After this change, it passes.
@karalabe
Copy link
Member

The problem is that there is no stable pure Go implementation of secp256k1. @whyrusleeping tried to use the same one we have for no-cgo at some point in time, even fixed a few issues, but I think they gave up in in end. As long as it's not stable, I don't think it's a good idea to make it simple for people to use it. It's mostly there for some gopherjs testing AFAIK. Ping @fjl.

@fjl
Copy link
Contributor

fjl commented Feb 19, 2019

I disagree. The nocgo implementation of secp256k1 is fine and passes all consensus tests. It's slower than libsecp256k1, but that's expected.

@fjl
Copy link
Contributor

fjl commented Feb 19, 2019

The btcsuite authors addressed the remaining incompatibilities in May 2018 (test cases added here).

@karalabe
Copy link
Member

@fjl Your call.

@fjl fjl merged commit b5e5b35 into ethereum:master Feb 19, 2019
@jeremyschlatter jeremyschlatter deleted the patch branch February 19, 2019 17:35
@whyrusleeping
Copy link

Yeah, i think we were using a version before the may 2018 fixes.

kiku-jw pushed a commit to kiku-jw/go-ethereum that referenced this pull request Mar 29, 2019
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.
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Nov 29, 2024
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.
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Dec 2, 2024
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.
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Dec 2, 2024
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.
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Dec 4, 2024
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.
gzliudan added a commit to gzliudan/XDPoSChain that referenced this pull request Dec 9, 2024
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.
JukLee0ira pushed a commit to JukLee0ira/XDPoSChain that referenced this pull request Jan 2, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants