Skip to content

Commit d631505

Browse files
committed
cmd/tailscaled: make build fail nicely on older Go versions
Due to a bug in Go (golang/go#51778), cmd/go doesn't warn about your Go version being older than the go.mod's declared Go version in that case that package loading fails before the build starts, such as when you use packages that are only in the current version of Go, like our use of net/netip. This change works around that Go bug by adding build tags and a pre-Go1.18-only file that will cause Go 1.17 and earlier to fail like: $ ~/sdk/go1.17/bin/go install ./cmd/tailscaled # tailscale.com/cmd/tailscaled ./required_version.go:11:2: undefined: you_need_Go_1_18_to_compile_Tailscale note: module requires Go 1.18 Change-Id: I39f5820de646703e19dde448dd86a7022252f75c Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
1 parent 2a412ac commit d631505

File tree

9 files changed

+34
-3
lines changed

9 files changed

+34
-3
lines changed

cmd/tailscaled/debug.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build go1.18
6+
// +build go1.18
7+
58
package main
69

710
import (

cmd/tailscaled/install_darwin.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build go1.18
6+
// +build go1.18
7+
58
package main
69

710
import (

cmd/tailscaled/install_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build go1.18
6+
// +build go1.18
7+
58
package main
69

710
import (

cmd/tailscaled/proxy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build go1.18
6+
// +build go1.18
7+
58
// HTTP proxy code
69

710
package main

cmd/tailscaled/required_version.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build !go1.18
6+
// +build !go1.18
7+
8+
package main
9+
10+
func init() {
11+
you_need_Go_1_18_to_compile_Tailscale()
12+
}

cmd/tailscaled/tailscaled.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build go1.18
6+
// +build go1.18
7+
58
// The tailscaled program is the Tailscale client daemon. It's configured
69
// and controlled via the tailscale CLI program.
710
//

cmd/tailscaled/tailscaled_bird.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build linux || darwin || freebsd || openbsd
5+
//go:build go1.18 && (linux || darwin || freebsd || openbsd)
6+
// +build go1.18
67
// +build linux darwin freebsd openbsd
78

89
package main

cmd/tailscaled/tailscaled_notwindows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !windows
6-
// +build !windows
5+
//go:build !windows && go1.18
6+
// +build !windows,go1.18
77

88
package main // import "tailscale.com/cmd/tailscaled"
99

cmd/tailscaled/tailscaled_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build go1.18
6+
// +build go1.18
7+
58
package main // import "tailscale.com/cmd/tailscaled"
69

710
// TODO: check if administrator, like tswin does.

0 commit comments

Comments
 (0)