tool/gocross: support local toolchain for development

This makes gocross and its bootstrap script understand an absolute
path in go.toolchain.rev to mean "use the given toolchain directly".

Signed-off-by: David Anderson <danderson@tailscale.com>
pull/6914/merge
David Anderson 2 years ago committed by Dave Anderson
parent 66621ab38e
commit 64181e17c8

@ -31,23 +31,30 @@ if [ ! -d "$toolchain" ]; then
# updates. # updates.
read -r REV <$repo_root/go.toolchain.rev read -r REV <$repo_root/go.toolchain.rev
# This works for linux and darwin, which is sufficient case "$REV" in
# (we do not build tailscale-go for other targets). /*)
HOST_OS=$(uname -s | tr A-Z a-z) toolchain="$REV"
HOST_ARCH="$(uname -m)" ;;
if [ "$HOST_ARCH" = "aarch64" ]; then *)
# Go uses the name "arm64". # This works for linux and darwin, which is sufficient
HOST_ARCH="arm64" # (we do not build tailscale-go for other targets).
elif [ "$HOST_ARCH" = "x86_64" ]; then HOST_OS=$(uname -s | tr A-Z a-z)
# Go uses the name "amd64". HOST_ARCH="$(uname -m)"
HOST_ARCH="amd64" if [ "$HOST_ARCH" = "aarch64" ]; then
fi # 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" 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" 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" mkdir -p "$toolchain"
(cd "$toolchain" && tar --strip-components=1 -xf "$toolchain.tar.gz") (cd "$toolchain" && tar --strip-components=1 -xf "$toolchain.tar.gz")
echo "$REV" >"$toolchain.extracted" echo "$REV" >"$toolchain.extracted"
;;
esac
fi fi
# Binaries run with `gocross run` can reinvoke gocross, resulting in a # Binaries run with `gocross run` can reinvoke gocross, resulting in a

@ -112,9 +112,18 @@ func ensureToolchain(cacheDir, toolchainDir string) error {
return err return err
} }
if err := downloadCachedgo(toolchainDir, wantRev); err != nil { if filepath.IsAbs(wantRev) {
return err // Local dev toolchain.
if err := os.Symlink(wantRev, toolchainDir); err != nil {
return err
}
return nil
} else {
if err := downloadCachedgo(toolchainDir, wantRev); err != nil {
return err
}
} }
if err := os.WriteFile(stampFile, []byte(wantRev), 0644); err != nil { if err := os.WriteFile(stampFile, []byte(wantRev), 0644); err != nil {
return err return err
} }

Loading…
Cancel
Save