From e37eded256ce35ca0ba8d53ac0a23ad51e155e01 Mon Sep 17 00:00:00 2001 From: James Tucker Date: Tue, 19 Mar 2024 16:08:20 -0700 Subject: [PATCH] tool/gocross: add android autoflags (#11465) Updates tailscale/corp#18202 Signed-off-by: James Tucker --- tool/gocross/autoflags.go | 2 ++ tool/gocross/autoflags_test.go | 59 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/tool/gocross/autoflags.go b/tool/gocross/autoflags.go index e8707a55f..6bf04d3cc 100644 --- a/tool/gocross/autoflags.go +++ b/tool/gocross/autoflags.go @@ -61,6 +61,8 @@ func autoflagsForTest(argv []string, env *Environment, goroot, nativeGOOS, nativ } switch targetOS { + case "android": + cgo = env.Get("CGO_ENABLED", "0") == "1" case "linux": // Getting Go to build a static binary with cgo enabled is a // minor ordeal. The incantations you apparently need are diff --git a/tool/gocross/autoflags_test.go b/tool/gocross/autoflags_test.go index 66072f420..9f24a131b 100644 --- a/tool/gocross/autoflags_test.go +++ b/tool/gocross/autoflags_test.go @@ -199,6 +199,65 @@ TS_LINK_FAIL_REFLECT=0 (was )`, "./cmd/tailcontrol", }, }, + { + name: "linux_amd64_to_android_amd64", + env: map[string]string{ + "GOOS": "android", + }, + argv: []string{"gocross", "build", "./cmd/tailcontrol"}, + goroot: "/goroot", + nativeGOOS: "linux", + nativeGOARCH: "amd64", + + envDiff: `CC=cc (was ) +CGO_CFLAGS=-O3 -std=gnu11 (was ) +CGO_ENABLED=0 (was ) +CGO_LDFLAGS= (was ) +GOARCH=amd64 (was ) +GOARM=5 (was ) +GOMIPS=softfloat (was ) +GOOS=android (was android) +GOROOT=/goroot (was ) +GOTOOLCHAIN=local (was ) +TS_LINK_FAIL_REFLECT=0 (was )`, + wantArgv: []string{ + "gocross", "build", + "-trimpath", + "-tags=tailscale_go", + "-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: "linux_amd64_to_android_amd64_cgo", + env: map[string]string{ + "GOOS": "android", + "CGO_ENABLED": "1", + }, + argv: []string{"gocross", "build", "./cmd/tailcontrol"}, + goroot: "/goroot", + nativeGOOS: "linux", + nativeGOARCH: "amd64", + + envDiff: `CC=cc (was ) +CGO_CFLAGS=-O3 -std=gnu11 (was ) +CGO_ENABLED=1 (was 1) +CGO_LDFLAGS= (was ) +GOARCH=amd64 (was ) +GOARM=5 (was ) +GOMIPS=softfloat (was ) +GOOS=android (was android) +GOROOT=/goroot (was ) +GOTOOLCHAIN=local (was ) +TS_LINK_FAIL_REFLECT=0 (was )`, + wantArgv: []string{ + "gocross", "build", + "-trimpath", + "-tags=tailscale_go", + "-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", argv: []string{"gocross", "build", "./cmd/tailcontrol"},