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() }