diff --git a/Makefile b/Makefile index a235ef0..c69d3b0 100644 --- a/Makefile +++ b/Makefile @@ -60,17 +60,14 @@ ifeq ($(JAVA_HOME),) unexport JAVA_HOME endif -# Go toolchain path, by default pulled from Tailscale prebuilts pinned to the -# version in tailscale.com/cmd/printdep. -TOOLCHAINDIR ?= ${HOME}/.cache/tailscale-android-go-$(shell go run tailscale.com/cmd/printdep --go) - -# TODO: GOPATH should be handled more cleanly here, but gomobile installs files -# into GOPATH/bin and expects them in $PATH. Ideally we'd move GOPATH entirely -# 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 -# $(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) +# TOOLCHAINDIR is set by fdoid CI and used by tool/* scripts. +TOOLCHAINDIR ?= +export TOOLCHAINDIR + +GOBIN ?= $(PWD)/android/build/go/bin +export GOBIN + +export PATH := $(PWD)/tool:$(GOBIN):$(JAVA_HOME)/bin:$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$(PATH) export GOROOT := # Unset 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 tag -a "$(VERSION_LONG)" -bumposs: toolchain +bumposs: GOPROXY=direct go get tailscale.com@main + go run tailscale.com/cmd/printdep --go > go.toolchain.rev 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. $(ANDROID_HOME)/cmdline-tools/latest/bin/sdkmanager: mkdir -p $(ANDROID_HOME)/tmp @@ -134,9 +123,7 @@ androidpath: @echo "export ANDROID_SDK_ROOT=$(ANDROID_SDK_ROOT)" @echo 'export PATH=$(ANDROID_HOME)/cmdline-tools/latest/bin:$(ANDROID_HOME)/platform-tools:$$PATH' -toolchain: $(TOOLCHAINDIR)/bin/go - -$(AAR): toolchain checkandroidsdk +$(AAR): checkandroidsdk @mkdir -p android_legacy/libs && \ go run gioui.org/cmd/gogio \ -ldflags $(VERSION_LDFLAGS) \ @@ -169,18 +156,16 @@ LIBTAILSCALE_SOURCES=$(shell find libtailscale -name *.go) go.mod go.sum android/libs: mkdir -p android/libs -android/build/go: - mkdir -p android/build/go +$(GOBIN)/gomobile: $(GOBIN)/gobind go.mod go.sum + go install golang.org/x/mobile/cmd/gomobile -GOMOBILE=android/build/go/gomobile -$(GOMOBILE): go.mod go.sum $(TOOLCHAINDIR)/bin/go - $(TOOLCHAINDIR)/bin/go build -o android/build/go/gomobile golang.org/x/mobile/cmd/gomobile +$(GOBIN)/gobind: go.mod go.sum + go install golang.org/x/mobile/cmd/gobind # TODO: the version names used below parse the legacy version information, # though hopefully they won't substantially differ for now. -$(LIBTAILSCALE): Makefile android/libs android/build/go/gomobile $(LIBTAILSCALE_SOURCES) - ./$(GOMOBILE) init - ./$(GOMOBILE) bind -target android -androidapi 26 \ +$(LIBTAILSCALE): Makefile android/libs $(LIBTAILSCALE_SOURCES) $(GOBIN)/gomobile + gomobile bind -target android -androidapi 26 \ -ldflags $(VERSION_LDFLAGS) \ -o $@ ./libtailscale diff --git a/go.mod b/go.mod index d99da41..3123a70 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( golang.org/x/mobile v0.0.0-20240319015410-c58ccf4b0c87 golang.org/x/sys v0.18.0 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 ( diff --git a/go.sum b/go.sum index dace082..065fcb2 100644 --- a/go.sum +++ b/go.sum @@ -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/go.mod h1:Qiz0EyvDRJjjxGyUQa2cCNZn/wMyzrRJ/qcDXOQazLI= 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.61.0-pre.0.20240311120500-7429e8912acb/go.mod h1:cC0b0vYCoSDOLufJX5J5zDUrvV3lYwOLqlt9NW8y4cY= +tailscale.com v1.63.0-pre.0.20240319225125-6da1dc84de57 h1:AkU/jPJff3JoDr3gbM8Aut/GK7zriPTOYL7IY99YTXc= +tailscale.com v1.63.0-pre.0.20240319225125-6da1dc84de57/go.mod h1:cC0b0vYCoSDOLufJX5J5zDUrvV3lYwOLqlt9NW8y4cY= diff --git a/go.toolchain.rev b/go.toolchain.rev new file mode 100644 index 0000000..9eb5f82 --- /dev/null +++ b/go.toolchain.rev @@ -0,0 +1 @@ +f86d7c8ef64a0f8a2516fc23652eee28abc8d8e0 diff --git a/tool/go b/tool/go new file mode 100755 index 0000000..28734f0 --- /dev/null +++ b/tool/go @@ -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 "$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" "$@" \ No newline at end of file