*: introduce tool/go following our common pattern

- This tool/go does not currently invoke gocross, as there's more work to
do in gocross to be fully compatible with gomobile.
- Use GOBIN to target the output destinations for gomobile and gobind.
- Remove the old toolchain targets from the Makefile.
- Use ~/.cache/tailscale-go, like the OSS repo does.
- Introduce go.toolchain.rev as we have in the OSS repo, and update it in
the bumposs task.

Updates tailscale/corp#18202

Signed-off-by: James Tucker <james@tailscale.com>
raggi/builds3
James Tucker 8 months ago
parent 2a14964878
commit 526b614ef4
No known key found for this signature in database

@ -60,17 +60,14 @@ ifeq ($(JAVA_HOME),)
unexport JAVA_HOME unexport JAVA_HOME
endif endif
# Go toolchain path, by default pulled from Tailscale prebuilts pinned to the # TOOLCHAINDIR is set by fdoid CI and used by tool/* scripts.
# version in tailscale.com/cmd/printdep. TOOLCHAINDIR ?=
TOOLCHAINDIR ?= ${HOME}/.cache/tailscale-android-go-$(shell go run tailscale.com/cmd/printdep --go) export TOOLCHAINDIR
# TODO: GOPATH should be handled more cleanly here, but gomobile installs files GOBIN ?= $(PWD)/android/build/go/bin
# into GOPATH/bin and expects them in $PATH. Ideally we'd move GOPATH entirely export GOBIN
# inside the build output directory, but as Go marks all the files recursively
# read only that makes clean more complex as well. We run the risk of export PATH := $(PWD)/tool:$(GOBIN):$(JAVA_HOME)/bin:$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$(PATH)
# $(TOOLCHAINDIR)/bin/go and "go" providing different answers, but today that
# would be extremely unlikely.
export PATH := $(TOOLCHAINDIR)/bin:$(JAVA_HOME)/bin:$(shell go env GOPATH)/bin:$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$(PATH)
export GOROOT := # Unset export GOROOT := # Unset
all: tailscale-new-debug.apk test $(DEBUG_APK) tailscale-fdroid.apk all: tailscale-new-debug.apk test $(DEBUG_APK) tailscale-fdroid.apk
@ -89,19 +86,11 @@ tag_release:
git commit -sm "android: bump version code" android_legacy/build.gradle git commit -sm "android: bump version code" android_legacy/build.gradle
git tag -a "$(VERSION_LONG)" git tag -a "$(VERSION_LONG)"
bumposs: toolchain bumposs:
GOPROXY=direct go get tailscale.com@main GOPROXY=direct go get tailscale.com@main
go run tailscale.com/cmd/printdep --go > go.toolchain.rev
go mod tidy -compat=1.22 go mod tidy -compat=1.22
$(TOOLCHAINDIR)/bin/go:
@if ! echo $(TOOLCHAINDIR) | grep -q 'tailscale-android-go'; then \
echo "ERROR: TOOLCHAINDIR=$(TOOLCHAINDIR) is missing bin/go and does not appear to be a tailscale managed path"; \
exit 1; \
fi
rm -rf ${HOME}/.cache/tailscale-android-go-*
mkdir -p $(TOOLCHAINDIR)
curl --silent -L $(shell go run tailscale.com/cmd/printdep --go-url) | tar --strip-components=1 -C $(TOOLCHAINDIR) -zx
# Get the commandline tools package, this provides (among other things) the sdkmanager binary. # Get the commandline tools package, this provides (among other things) the sdkmanager binary.
$(ANDROID_HOME)/cmdline-tools/latest/bin/sdkmanager: $(ANDROID_HOME)/cmdline-tools/latest/bin/sdkmanager:
mkdir -p $(ANDROID_HOME)/tmp mkdir -p $(ANDROID_HOME)/tmp
@ -134,9 +123,7 @@ androidpath:
@echo "export ANDROID_SDK_ROOT=$(ANDROID_SDK_ROOT)" @echo "export ANDROID_SDK_ROOT=$(ANDROID_SDK_ROOT)"
@echo 'export PATH=$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$$PATH' @echo 'export PATH=$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$$PATH'
toolchain: $(TOOLCHAINDIR)/bin/go $(AAR): checkandroidsdk
$(AAR): toolchain checkandroidsdk
@mkdir -p android_legacy/libs && \ @mkdir -p android_legacy/libs && \
go run gioui.org/cmd/gogio \ go run gioui.org/cmd/gogio \
-ldflags $(VERSION_LDFLAGS) \ -ldflags $(VERSION_LDFLAGS) \
@ -169,18 +156,16 @@ LIBTAILSCALE_SOURCES=$(shell find libtailscale -name *.go) go.mod go.sum
android/libs: android/libs:
mkdir -p android/libs mkdir -p android/libs
android/build/go: $(GOBIN)/gomobile: $(GOBIN)/gobind go.mod go.sum
mkdir -p android/build/go go install golang.org/x/mobile/cmd/gomobile
GOMOBILE=android/build/go/gomobile $(GOBIN)/gobind: go.mod go.sum
$(GOMOBILE): go.mod go.sum $(TOOLCHAINDIR)/bin/go go install golang.org/x/mobile/cmd/gobind
$(TOOLCHAINDIR)/bin/go build -o android/build/go/gomobile golang.org/x/mobile/cmd/gomobile
# TODO: the version names used below parse the legacy version information, # TODO: the version names used below parse the legacy version information,
# though hopefully they won't substantially differ for now. # though hopefully they won't substantially differ for now.
$(LIBTAILSCALE): Makefile android/libs android/build/go/gomobile $(LIBTAILSCALE_SOURCES) $(LIBTAILSCALE): Makefile android/libs $(LIBTAILSCALE_SOURCES) $(GOBIN)/gomobile
./$(GOMOBILE) init gomobile bind -target android -androidapi 26 \
./$(GOMOBILE) bind -target android -androidapi 26 \
-ldflags $(VERSION_LDFLAGS) \ -ldflags $(VERSION_LDFLAGS) \
-o $@ ./libtailscale -o $@ ./libtailscale

@ -13,7 +13,7 @@ require (
golang.org/x/mobile v0.0.0-20240319015410-c58ccf4b0c87 golang.org/x/mobile v0.0.0-20240319015410-c58ccf4b0c87
golang.org/x/sys v0.18.0 golang.org/x/sys v0.18.0
inet.af/netaddr v0.0.0-20220617031823-097006376321 inet.af/netaddr v0.0.0-20220617031823-097006376321
tailscale.com v1.61.0-pre.0.20240311120500-7429e8912acb tailscale.com v1.63.0-pre.0.20240319225125-6da1dc84de57
) )
require ( require (

@ -666,5 +666,5 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
software.sslmate.com/src/go-pkcs12 v0.4.0 h1:H2g08FrTvSFKUj+D309j1DPfk5APnIdAQAB8aEykJ5k= software.sslmate.com/src/go-pkcs12 v0.4.0 h1:H2g08FrTvSFKUj+D309j1DPfk5APnIdAQAB8aEykJ5k=
software.sslmate.com/src/go-pkcs12 v0.4.0/go.mod h1:Qiz0EyvDRJjjxGyUQa2cCNZn/wMyzrRJ/qcDXOQazLI= software.sslmate.com/src/go-pkcs12 v0.4.0/go.mod h1:Qiz0EyvDRJjjxGyUQa2cCNZn/wMyzrRJ/qcDXOQazLI=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
tailscale.com v1.61.0-pre.0.20240311120500-7429e8912acb h1:XUkF0NkRcJ3gZupkOyZ4+NJ8t6scL+QuntLYP/iyeuo= tailscale.com v1.63.0-pre.0.20240319225125-6da1dc84de57 h1:AkU/jPJff3JoDr3gbM8Aut/GK7zriPTOYL7IY99YTXc=
tailscale.com v1.61.0-pre.0.20240311120500-7429e8912acb/go.mod h1:cC0b0vYCoSDOLufJX5J5zDUrvV3lYwOLqlt9NW8y4cY= tailscale.com v1.63.0-pre.0.20240319225125-6da1dc84de57/go.mod h1:cC0b0vYCoSDOLufJX5J5zDUrvV3lYwOLqlt9NW8y4cY=

@ -0,0 +1 @@
f86d7c8ef64a0f8a2516fc23652eee28abc8d8e0

@ -0,0 +1,68 @@
#!/bin/bash
# Copyright (c) Tailscale Inc & AUTHORS
# SPDX-License-Identifier: BSD-3-Clause
set -eo pipefail
if [[ "${CI:-}" == "true" && "${NOBASHDEBUG:-}" != "true" ]]; then
set -x
fi
# Allow TOOLCHAINDIR to be overridden, as a special case for the fdroid build
if [[ -z "${TOOLCHAINDIR}" ]]; then
toolchain="$HOME/.cache/tailscale-go"
if [[ -d "$toolchain" ]]; then
# A toolchain exists, but is it recent enough to compile gocross? If not,
# wipe it out so that the next if block fetches a usable one.
want_go_minor=$(grep -E '^go ' "go.mod" | cut -f2 -d'.')
have_go_minor=""
if [[ -f "$toolchain/VERSION" ]]; then
have_go_minor=$(head -1 "$toolchain/VERSION" | cut -f2 -d'.')
fi
# Shortly before stable releases, we run release candidate
# toolchains, which have a non-numeric suffix on the version
# number. Remove the rc qualifier, we just care about the minor
# version.
have_go_minor="${have_go_minor%rc*}"
if [[ -z "$have_go_minor" || "$have_go_minor" -lt "$want_go_minor" ]]; then
rm -rf "$toolchain" "$toolchain.extracted"
fi
fi
if [[ ! -d "$toolchain" ]]; then
mkdir -p "$HOME/.cache"
read -r REV <go.toolchain.rev
case "$REV" in
/*)
toolchain="$REV"
;;
*)
# This works for linux and darwin, which is sufficient
# (we do not build tailscale-go for other targets).
HOST_OS=$(uname -s | tr A-Z a-z)
HOST_ARCH="$(uname -m)"
if [[ "$HOST_ARCH" == "aarch64" ]]; then
# Go uses the name "arm64".
HOST_ARCH="arm64"
elif [[ "$HOST_ARCH" == "x86_64" ]]; then
# Go uses the name "amd64".
HOST_ARCH="amd64"
fi
rm -rf "$toolchain" "$toolchain.extracted"
curl -f -L -o "$toolchain.tar.gz" "https://github.com/tailscale/go/releases/download/build-${REV}/${HOST_OS}-${HOST_ARCH}.tar.gz"
mkdir -p "$toolchain"
(cd "$toolchain" && tar --strip-components=1 -xf "$toolchain.tar.gz")
echo "$REV" >"$toolchain.extracted"
rm -f "$toolchain.tar.gz"
;;
esac
fi
else
# fdroid supplies it's own toolchain, rather than using ours.
toolchain="${TOOLCHAINDIR}"
fi
exec "${toolchain}/bin/go" "$@"
Loading…
Cancel
Save