1
0
mirror of https://github.com/golang/go synced 2024-11-18 12:04:57 -07:00

cmd/go: add error for cross-compiled -race builds

Race builds require C dependencies, but cross-compiled cgo builds are
not always possible, so don't suggest enabling CGO in those cases.

Fixes #37021

Change-Id: I1fd675efc9cef958a926bd63eac8e6858bc59d0a
GitHub-Last-Rev: cbf43c1bbb
GitHub-Pull-Request: golang/go#38670
Reviewed-on: https://go-review.googlesource.com/c/go/+/230202
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Keyan Pishdadian 2020-04-28 20:06:29 +00:00 committed by Bryan C. Mills
parent 41f6388e70
commit e87b0644db

View File

@ -16,6 +16,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
)
@ -84,7 +85,12 @@ func instrumentInit() {
modeFlag := "-" + mode
if !cfg.BuildContext.CgoEnabled {
fmt.Fprintf(os.Stderr, "go %s: %s requires cgo; enable cgo by setting CGO_ENABLED=1\n", flag.Args()[0], modeFlag)
if runtime.GOOS != cfg.Goos || runtime.GOARCH != cfg.Goarch {
fmt.Fprintf(os.Stderr, "go %s: %s requires cgo\n", flag.Args()[0], modeFlag)
} else {
fmt.Fprintf(os.Stderr, "go %s: %s requires cgo; enable cgo by setting CGO_ENABLED=1\n", flag.Args()[0], modeFlag)
}
base.SetExitStatus(2)
base.Exit()
}