-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: 'go build -race' with a cross-compiled GOOS should not suggest setting CGO_ENABLED #37021
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
Comments
Cross-compiling programs with C dependencies is generally not supported, and the runtime support for If you want to build a race-enabled binary, you need to either compile for GOOS=windows or build the binary on a Linux machine. |
Probably the best we can do here is emit a clearer diagnostic for cross-compiled |
just try to cross compile this:
from windows\amd64 to linux\amd64 with gox |
I think "'go build -race' with a cross-compiled GOOS should not suggest setting CGO_ENABLED" is not what this issue is for, that is another issue\suggestion. Current issue is unavailability to crosscompile "-race" with gox. |
@MasterDimmy, the fact that If you want to volunteer to rewrite the race-detector library in pure Go, you're welcome to do so, but as far as “things we can feasibly plan to fix” are concerned, a better error message for this case is about the limit. |
Change https://golang.org/cl/230202 mentions this issue: |
Wait, I'm not following the suggestion here. Cross-compiling cgo code works fine if you have a cross-compiler. We may want a general fix to do better checking of whether you are using a cross-compiler when doing a cross-build that uses cgo. But that seems separate from the narrow issue of "go build -race", which should work if a cross-compiler is installed. |
I misunderstood Bryan's comment:
If I understand correctly now, the short term move is just to not mention setting CGO_ENABLED because that isn't sufficient on its' own and it is too verbose to explain that you need to have a cross-compiler installed? |
Race builds require C dependencies, but cross-compiled cgo builds are not always possible, so don't suggest enabling CGO in those cases. Fixes golang#37021 Change-Id: I1fd675efc9cef958a926bd63eac8e6858bc59d0a GitHub-Last-Rev: cbf43c1 GitHub-Pull-Request: golang#38670 Reviewed-on: https://go-review.googlesource.com/c/go/+/230202 Reviewed-by: Bryan C. Mills <[email protected]>
Does this issue reproduce with the latest release?
YES
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
i compile this file for test:
import (
"fmt"
)
func main() {
c := make(chan bool)
m := make(map[string]string)
go func() {
m["1"] = "a" // First conflicting access.
c <- true
}()
m["2"] = "b" // Second conflicting access.
<-c
for k, v := range m {
fmt.Println(k, v)
}
}
with
What did you expect to see?
success compile
What did you see instead?
Note, that
is succecced, but i need to compile with "-race" detector. If CGO_ENABLED=0
then i got
The text was updated successfully, but these errors were encountered: