From e87b0644db46c2b313f420c657a4b308fb6bc2cb Mon Sep 17 00:00:00 2001 From: Keyan Pishdadian Date: Tue, 28 Apr 2020 20:06:29 +0000 Subject: [PATCH] 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: cbf43c1bbb0f209474cc323b3813cf270a2ba0a8 GitHub-Pull-Request: golang/go#38670 Reviewed-on: https://go-review.googlesource.com/c/go/+/230202 Reviewed-by: Bryan C. Mills --- src/cmd/go/internal/work/init.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/internal/work/init.go b/src/cmd/go/internal/work/init.go index 473bd1a31b..921a54f6f0 100644 --- a/src/cmd/go/internal/work/init.go +++ b/src/cmd/go/internal/work/init.go @@ -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() }