diff --git a/internal/builders/golang/build.go b/internal/builders/golang/build.go index 706fc9a53a5..604b6ebbd54 100644 --- a/internal/builders/golang/build.go +++ b/internal/builders/golang/build.go @@ -59,7 +59,7 @@ func (*Builder) WithDefaults(build config.Build) (config.Build, error) { if len(build.Gomips) == 0 { build.Gomips = []string{"hardfloat"} } - targets, err := matrix(build) + targets, err := matrix(build, goVersion(build)) build.Targets = targets if err != nil { return build, err diff --git a/internal/builders/golang/targets.go b/internal/builders/golang/targets.go index bb6e533a1a3..dd658984029 100644 --- a/internal/builders/golang/targets.go +++ b/internal/builders/golang/targets.go @@ -1,9 +1,9 @@ package golang import ( - "bytes" "fmt" "os/exec" + "regexp" "strings" "github.com/apex/log" @@ -25,7 +25,7 @@ func (t target) String() string { return fmt.Sprintf("%s_%s", t.os, t.arch) } -func matrix(build config.Build) ([]string, error) { +func matrix(build config.Build, version []byte) ([]string, error) { // nolint:prealloc var targets []target // nolint:prealloc @@ -43,13 +43,20 @@ func matrix(build config.Build) ([]string, error) { if target.mips != "" && !contains(target.mips, validGomips) { return result, fmt.Errorf("invalid gomips: %s", target.mips) } - if target.os == "darwin" && target.arch == "arm64" && !isGo116(build) { + if target.os == "darwin" && target.arch == "arm64" && !go116re.Match(version) { log.Warn(color.New(color.Bold, color.FgHiYellow).Sprintf( "DEPRECATED: skipped darwin/arm64 build on Go < 1.16 for compatibility, check %s for more info.", "https://goreleaser.com/deprecations/#builds-for-darwinarm64", )) continue } + if target.os == "windows" && target.arch == "arm64" && !go117re.Match(version) { + log.Warn(color.New(color.Bold, color.FgHiYellow).Sprintf( + "DEPRECATED: skipped windows/arm64 build on Go < 1.17 for compatibility, check %s for more info.", + "https://goreleaser.com/deprecations/#builds-for-windowsarm64", + )) + continue + } if !valid(target) { log.WithField("target", target).Debug("skipped invalid build") continue @@ -119,9 +126,14 @@ func ignored(build config.Build, target target) bool { return false } -func isGo116(build config.Build) bool { +var ( + go116re = regexp.MustCompile(`go version go1.1[6-9]`) + go117re = regexp.MustCompile(`go version go1.1[7-9]`) +) + +func goVersion(build config.Build) []byte { bts, _ := exec.Command(build.GoBinary, "version").CombinedOutput() - return bytes.Contains(bts, []byte("go version go1.16")) + return bts } func valid(target target) bool { @@ -179,6 +191,7 @@ var ( "plan9arm", "solarisamd64", "windowsarm", + "windowsarm64", "windows386", "windowsamd64", } diff --git a/internal/builders/golang/targets_test.go b/internal/builders/golang/targets_test.go index b2af7e5eea6..c518b366a9e 100644 --- a/internal/builders/golang/targets_test.go +++ b/internal/builders/golang/targets_test.go @@ -56,36 +56,105 @@ func TestAllBuildTargets(t *testing.T) { }, }, } - result, err := matrix(build) - require.NoError(t, err) - require.Equal(t, []string{ - "linux_386", - "linux_amd64", - "linux_arm_6", - "linux_arm64", - "linux_mips_hardfloat", - "linux_mips_softfloat", - "linux_mips64_softfloat", - "linux_mipsle_hardfloat", - "linux_mipsle_softfloat", - "linux_mips64le_hardfloat", - "linux_riscv64", - "darwin_amd64", - "darwin_arm64", - "freebsd_386", - "freebsd_amd64", - "freebsd_arm_6", - "freebsd_arm_7", - "freebsd_arm64", - "openbsd_386", - "openbsd_amd64", - "openbsd_arm64", - "windows_386", - "windows_amd64", - "windows_arm_6", - "windows_arm_7", - "js_wasm", - }, result) + + t.Run("go 1.15", func(t *testing.T) { + result, err := matrix(build, []byte("go version go1.15.0")) + require.NoError(t, err) + require.Equal(t, []string{ + "linux_386", + "linux_amd64", + "linux_arm_6", + "linux_arm64", + "linux_mips_hardfloat", + "linux_mips_softfloat", + "linux_mips64_softfloat", + "linux_mipsle_hardfloat", + "linux_mipsle_softfloat", + "linux_mips64le_hardfloat", + "linux_riscv64", + "darwin_amd64", + "freebsd_386", + "freebsd_amd64", + "freebsd_arm_6", + "freebsd_arm_7", + "freebsd_arm64", + "openbsd_386", + "openbsd_amd64", + "openbsd_arm64", + "windows_386", + "windows_amd64", + "windows_arm_6", + "windows_arm_7", + "js_wasm", + }, result) + }) + + t.Run("go 1.16", func(t *testing.T) { + result, err := matrix(build, []byte("go version go1.16.2")) + require.NoError(t, err) + require.Equal(t, []string{ + "linux_386", + "linux_amd64", + "linux_arm_6", + "linux_arm64", + "linux_mips_hardfloat", + "linux_mips_softfloat", + "linux_mips64_softfloat", + "linux_mipsle_hardfloat", + "linux_mipsle_softfloat", + "linux_mips64le_hardfloat", + "linux_riscv64", + "darwin_amd64", + "darwin_arm64", + "freebsd_386", + "freebsd_amd64", + "freebsd_arm_6", + "freebsd_arm_7", + "freebsd_arm64", + "openbsd_386", + "openbsd_amd64", + "openbsd_arm64", + "windows_386", + "windows_amd64", + "windows_arm_6", + "windows_arm_7", + "js_wasm", + }, result) + }) + + t.Run("go 1.17", func(t *testing.T) { + result, err := matrix(build, []byte("go version go1.17.0")) + require.NoError(t, err) + require.Equal(t, []string{ + "linux_386", + "linux_amd64", + "linux_arm_6", + "linux_arm64", + "linux_mips_hardfloat", + "linux_mips_softfloat", + "linux_mips64_softfloat", + "linux_mipsle_hardfloat", + "linux_mipsle_softfloat", + "linux_mips64le_hardfloat", + "linux_riscv64", + "darwin_amd64", + "darwin_arm64", + "freebsd_386", + "freebsd_amd64", + "freebsd_arm_6", + "freebsd_arm_7", + "freebsd_arm64", + "openbsd_386", + "openbsd_amd64", + "openbsd_arm64", + "windows_386", + "windows_amd64", + "windows_arm_6", + "windows_arm_7", + "windows_arm64", + "js_wasm", + }, result) + }) } func TestGoosGoarchCombos(t *testing.T) { @@ -132,11 +201,11 @@ func TestGoosGoarchCombos(t *testing.T) { {"windows", "386", true}, {"windows", "amd64", true}, {"windows", "arm", true}, + {"windows", "arm64", true}, {"js", "wasm", true}, // invalid targets {"darwin", "386", false}, {"darwin", "arm", false}, - {"windows", "arm64", false}, {"windows", "riscv64", false}, } for _, p := range platforms { diff --git a/www/docs/deprecations.md b/www/docs/deprecations.md index 6769b449b1b..318531c3d61 100644 --- a/www/docs/deprecations.md +++ b/www/docs/deprecations.md @@ -38,6 +38,25 @@ Description. --> +### builds for windows/arm64 + +> since 2021-08-16 (v0.175.0) + +Since Go 1.17, `windows/arm64` is a valid target. + +Prior to v0.175.0, GoReleaser would just ignore this target. +Since in Go 1.17 it is now a valid target, GoReleaser will build it if the Go version being used is 1.17 or later. + +If you want to make sure it is ignored in the future, you need to add this to your build config: + +```yaml +ignore: +- goos: windows + goarch: arm64 +``` + +If you try to use new versions of GoReleaser with Go 1.16 or older, it will warn about it until this deprecation warning expires, after that your build will likely fail. + ### docker.use_buildx > since 2021-06-26 (v0.172.0) @@ -76,8 +95,8 @@ Because of that, once this deprecation expires, GoReleaser will hard fail on non Since Go 1.16, `darwin/arm64` is macOS on Apple Silicon instead of `iOS`. -Prior to v0.156.0, GoReleaser would just ignore this target, but since in Go 1.16 it is a valid target, GoReleaser will -now build it if the Go version being used is 1.16. +Prior to v0.156.0, GoReleaser would just ignore this target. +Since in Go 1.16 and later it is a valid target, GoReleaser will now build it if the Go version being used is 1.16 or later. If you want to make sure it is ignored in the future, you need to add this to your build config: @@ -87,8 +106,7 @@ ignore: goarch: arm64 ``` -If you try to use new versions of GoReleaser with Go 1.15, it will warn about it until this deprecation warning expires. - +If you try to use new versions of GoReleaser with Go 1.15 or older, it will warn about it until this deprecation warning expires, after that your build will likely fail. ## Expired deprecation notices