diff --git a/tool/gocross/autoflags.go b/tool/gocross/autoflags.go index 6bf04d3cc..fd58c1fcb 100644 --- a/tool/gocross/autoflags.go +++ b/tool/gocross/autoflags.go @@ -4,6 +4,7 @@ package main import ( + "cmp" "fmt" "runtime" "strings" @@ -32,8 +33,8 @@ func autoflagsForTest(argv []string, env *Environment, goroot, nativeGOOS, nativ subcommand = "" cc = "cc" - targetOS = env.Get("GOOS", nativeGOOS) - targetArch = env.Get("GOARCH", nativeGOARCH) + targetOS = cmp.Or(env.Get("GOOS", ""), nativeGOOS) + targetArch = cmp.Or(env.Get("GOARCH", ""), nativeGOARCH) buildFlags = []string{"-trimpath"} cgoCflags = []string{"-O3", "-std=gnu11"} cgoLdflags []string diff --git a/tool/gocross/autoflags_test.go b/tool/gocross/autoflags_test.go index 9f24a131b..438198de7 100644 --- a/tool/gocross/autoflags_test.go +++ b/tool/gocross/autoflags_test.go @@ -275,6 +275,64 @@ func TestAutoflags(t *testing.T) { GOOS=darwin (was ) GOROOT=/goroot (was ) GOTOOLCHAIN=local (was ) +TS_LINK_FAIL_REFLECT=0 (was )`, + wantArgv: []string{ + "gocross", "build", + "-trimpath", + "-tags=tailscale_go,omitidna,omitpemdecrypt", + "-ldflags", "-X tailscale.com/version.longStamp=1.2.3-long -X tailscale.com/version.shortStamp=1.2.3 -X tailscale.com/version.gitCommitStamp=abcd -X tailscale.com/version.extraGitCommitStamp=defg", + "./cmd/tailcontrol", + }, + }, + { + name: "darwin_arm64_to_darwin_arm64_empty_goos", + argv: []string{"gocross", "build", "./cmd/tailcontrol"}, + env: map[string]string{ + "GOOS": "", + }, + goroot: "/goroot", + nativeGOOS: "darwin", + nativeGOARCH: "arm64", + + envDiff: `CC=cc (was ) +CGO_CFLAGS=-O3 -std=gnu11 (was ) +CGO_ENABLED=1 (was ) +CGO_LDFLAGS= (was ) +GOARCH=arm64 (was ) +GOARM=5 (was ) +GOMIPS=softfloat (was ) +GOOS=darwin (was ) +GOROOT=/goroot (was ) +GOTOOLCHAIN=local (was ) +TS_LINK_FAIL_REFLECT=0 (was )`, + wantArgv: []string{ + "gocross", "build", + "-trimpath", + "-tags=tailscale_go,omitidna,omitpemdecrypt", + "-ldflags", "-X tailscale.com/version.longStamp=1.2.3-long -X tailscale.com/version.shortStamp=1.2.3 -X tailscale.com/version.gitCommitStamp=abcd -X tailscale.com/version.extraGitCommitStamp=defg", + "./cmd/tailcontrol", + }, + }, + { + name: "darwin_arm64_to_darwin_arm64_empty_goarch", + argv: []string{"gocross", "build", "./cmd/tailcontrol"}, + env: map[string]string{ + "GOARCH": "", + }, + goroot: "/goroot", + nativeGOOS: "darwin", + nativeGOARCH: "arm64", + + envDiff: `CC=cc (was ) +CGO_CFLAGS=-O3 -std=gnu11 (was ) +CGO_ENABLED=1 (was ) +CGO_LDFLAGS= (was ) +GOARCH=arm64 (was ) +GOARM=5 (was ) +GOMIPS=softfloat (was ) +GOOS=darwin (was ) +GOROOT=/goroot (was ) +GOTOOLCHAIN=local (was ) TS_LINK_FAIL_REFLECT=0 (was )`, wantArgv: []string{ "gocross", "build",