Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rebasing patches for go1.21 #66

Merged
merged 7 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Build toolchain

permissions:
contents: write

on:
push:
branches:
- tailscale
- 'tailscale.go1.21'
pull_request:
branches:
- '*'

jobs:
test:
runs-on: ubuntu-20.04
steps:
- name: checkout
uses: actions/checkout@v3
- name: test
run: cd src && ./all.bash

build_release:
strategy:
matrix:
GOOS: ["linux", "darwin"]
GOARCH: ["amd64", "arm64"]
runs-on: ubuntu-20.04
if: github.event_name == 'push'
steps:
- name: checkout
uses: actions/checkout@v3
- name: build
run: cd src && ./make.bash
env:
GOOS: "${{ matrix.GOOS }}"
GOARCH: "${{ matrix.GOARCH }}"
CGO_ENABLED: "0"
- name: trim unnecessary bits
run: |
rm -rf pkg/*_*
mv pkg/tool/${{ matrix.GOOS }}_${{ matrix.GOARCH }} pkg
rm -rf pkg/tool/*_*
mv -f bin/${{ matrix.GOOS }}_${{ matrix.GOARCH }}/* bin/ || true
rm -rf bin/${{ matrix.GOOS }}_${{ matrix.GOARCH }}
mv pkg/${{ matrix.GOOS }}_${{ matrix.GOARCH }} pkg/tool
find . -type d -name 'testdata' -print0 | xargs -0 rm -rf
find . -name '*_test.go' -delete
- name: archive
run: cd .. && tar --exclude-vcs -zcf ${{ matrix.GOOS }}-${{ matrix.GOARCH }}.tar.gz go
- name: save
uses: actions/upload-artifact@v1
with:
name: ${{ matrix.GOOS }}-${{ matrix.GOARCH }}
path: ../${{ matrix.GOOS }}-${{ matrix.GOARCH }}.tar.gz

create_release:
runs-on: ubuntu-20.04
if: github.event_name == 'push'
needs: [test, build_release]
outputs:
url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Release name can't be the same as tag name, sigh
tag_name: build-${{ github.sha }}
release_name: ${{ github.sha }}
draft: false
prerelease: true

upload_release:
strategy:
matrix:
GOOS: ["linux", "darwin"]
GOARCH: ["amd64", "arm64"]
runs-on: ubuntu-20.04
if: github.event_name == 'push'
needs: [create_release]
steps:
- name: download artifact
uses: actions/download-artifact@v1
with:
name: ${{ matrix.GOOS }}-${{ matrix.GOARCH }}
- name: upload artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.url }}
asset_path: ${{ matrix.GOOS }}-${{ matrix.GOARCH }}/${{ matrix.GOOS }}-${{ matrix.GOARCH }}.tar.gz
asset_name: ${{ matrix.GOOS }}-${{ matrix.GOARCH }}.tar.gz
asset_content_type: application/gzip

clean_old:
runs-on: ubuntu-20.04
if: github.event_name == 'push'
needs: [upload_release]
steps:
- name: checkout
uses: actions/checkout@v3
- name: Delete older builds
run: ./.github/workflows/prune_old_builds.sh "${{ secrets.GITHUB_TOKEN }}"
24 changes: 24 additions & 0 deletions .github/workflows/prune_old_builds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -euo pipefail

KEEP=10
GITHUB_TOKEN=$1

delete_release() {
release_id=$1
tag_name=$2
set -x
curl -X DELETE --header "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/tailscale/go/releases/$release_id"
curl -X DELETE --header "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/tailscale/go/git/refs/tags/$tag_name"
set +x
}

curl https://api.github.com/repos/tailscale/go/releases 2>/dev/null |\
jq -r '.[] | "\(.published_at) \(.id) \(.tag_name)"' |\
egrep '[^ ]+ [^ ]+ build-[0-9a-f]{40}' |\
sort |\
head --lines=-${KEEP}|\
while read date release_id tag_name; do
delete_release "$release_id" "$tag_name"
done
10 changes: 10 additions & 0 deletions api/go1.99999.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pkg net, func SetDialEnforcer(func(context.Context, []Addr) error) #55
pkg net, func SetResolveEnforcer(func(context.Context, string, string, string, Addr) error) #55
pkg net, func WithSockTrace(context.Context, *SockTrace) context.Context #58
pkg net, func ContextSockTrace(context.Context) *SockTrace #58
pkg net, type SockTrace struct #58
pkg net, type SockTrace struct, DidRead func(int) #58
pkg net, type SockTrace struct, DidWrite func(int) #58
pkg net, type SockTrace struct, WillOverwrite func(*SockTrace) #58
pkg net, type SockTrace struct, DidCreateTCPConn func(syscall.RawConn) #58
pkg net, type SockTrace struct, WillCloseTCPConn func(syscall.RawConn) #58
6 changes: 6 additions & 0 deletions src/cmd/dist/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ func findgoversion() string {
// its content if available, which is empty at this point.
// Only use the VERSION file if it is non-empty.
if b != "" {
if rev := os.Getenv("TAILSCALE_TOOLCHAIN_REV"); rev != "" {
if len(rev) > 10 {
rev = rev[:10]
}
b += "-ts" + chomp(rev)
}
return b
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/dist/buildgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package main
import (
"fmt"
"io"
"os"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -119,7 +118,7 @@ func mkzcgo(dir, file string) {
writeHeader(&buf)
fmt.Fprintf(&buf, "package build\n")
fmt.Fprintln(&buf)
fmt.Fprintf(&buf, "const defaultCGO_ENABLED = %s\n", quote(os.Getenv("CGO_ENABLED")))
fmt.Fprintf(&buf, "const defaultCGO_ENABLED = %q\n", "")

writefile(buf.String(), file, writeSkipSame)
}
Expand Down
48 changes: 48 additions & 0 deletions src/net/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,24 @@ func parseNetwork(ctx context.Context, network string, needsProto bool) (afnet s
return "", 0, UnknownNetworkError(network)
}

// SetResolveEnforcer set a program-global resolver enforcer that can cause resolvers to
// fail based on the context and/or other arguments.
//
// f must be non-nil, it can only be called once, and must not be called
// concurrent with any dial/resolve.
func SetResolveEnforcer(f func(ctx context.Context, op, network, addr string, hint Addr) error) {
if f == nil {
panic("nil func")
}
if resolveEnforcer != nil {
panic("already called")
}
resolveEnforcer = f
}

// resolveEnforcer, if non-nil, is the installed hook from SetResolveEnforcer.
var resolveEnforcer func(ctx context.Context, op, network, addr string, hint Addr) error

// resolveAddrList resolves addr using hint and returns a list of
// addresses. The result contains at least one address when error is
// nil.
Expand All @@ -269,6 +287,13 @@ func (r *Resolver) resolveAddrList(ctx context.Context, op, network, addr string
}
return addrList{addr}, nil
}

if resolveEnforcer != nil {
if err := resolveEnforcer(ctx, op, network, addr, hint); err != nil {
return nil, err
}
}

addrs, err := r.internetAddrList(ctx, afnet, addr)
if err != nil || op != "dial" || hint == nil {
return addrs, err
Expand Down Expand Up @@ -572,9 +597,32 @@ func (sd *sysDialer) dialParallel(ctx context.Context, primaries, fallbacks addr
}
}

// SetDialEnforcer set a program-global dial enforcer that can cause dials to
// fail based on the context and/or Addr(s).
//
// f must be non-nil, it can only be called once, and must not be called
// concurrent with any dial.
func SetDialEnforcer(f func(context.Context, []Addr) error) {
if f == nil {
panic("nil func")
}
if dialEnforcer != nil {
panic("already called")
}
dialEnforcer = f
}

// dialEnforce, if non-nil, is any installed hook from SetDialEnforcer.
var dialEnforcer func(context.Context, []Addr) error

// dialSerial connects to a list of addresses in sequence, returning
// either the first successful connection, or the first error.
func (sd *sysDialer) dialSerial(ctx context.Context, ras addrList) (Conn, error) {
if dialEnforcer != nil {
if err := dialEnforcer(ctx, ras); err != nil {
return nil, err
}
}
var firstErr error // The error from the first address is most relevant.

for i, ra := range ras {
Expand Down
Loading