You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-11-06 09:09:29 +02:00
feat: first class build targets (#3062)
Adds the ability to tell goreleaser to use the first-class Go ports as targets. Closes #3053 Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
committed by
GitHub
parent
5aeb8ace61
commit
69cf1aa887
@@ -68,29 +68,67 @@ func (*Builder) WithDefaults(build config.Build) (config.Build, error) {
|
||||
build.Goamd64 = []string{"v1"}
|
||||
}
|
||||
targets, err := buildtarget.List(build)
|
||||
build.Targets = targets
|
||||
if err != nil {
|
||||
return build, err
|
||||
}
|
||||
build.Targets = targets
|
||||
} else {
|
||||
for i, target := range build.Targets {
|
||||
targets := map[string]bool{}
|
||||
for _, target := range build.Targets {
|
||||
if target == go118FirstClassTargetsName ||
|
||||
target == goStableFirstClassTargetsName {
|
||||
for _, t := range go118FirstClassTargets {
|
||||
targets[t] = true
|
||||
}
|
||||
continue
|
||||
}
|
||||
if strings.HasSuffix(target, "_amd64") {
|
||||
build.Targets[i] = target + "_v1"
|
||||
targets[target+"_v1"] = true
|
||||
continue
|
||||
}
|
||||
if strings.HasSuffix(target, "_arm") {
|
||||
build.Targets[i] = target + "_6"
|
||||
targets[target+"_6"] = true
|
||||
continue
|
||||
}
|
||||
if strings.HasSuffix(target, "_mips") ||
|
||||
strings.HasSuffix(target, "_mips64") ||
|
||||
strings.HasSuffix(target, "_mipsle") ||
|
||||
strings.HasSuffix(target, "_mips64le") {
|
||||
build.Targets[i] = target + "_hardfloat"
|
||||
targets[target+"_hardfloat"] = true
|
||||
continue
|
||||
}
|
||||
targets[target] = true
|
||||
}
|
||||
build.Targets = keys(targets)
|
||||
}
|
||||
return build, nil
|
||||
}
|
||||
|
||||
func keys(m map[string]bool) []string {
|
||||
result := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
result = append(result, k)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
const (
|
||||
go118FirstClassTargetsName = "go_118_first_class"
|
||||
goStableFirstClassTargetsName = "go_first_class"
|
||||
)
|
||||
|
||||
// go tool dist list -json | jq -r '.[] | select(.FirstClass) | [.GOOS, .GOARCH] | @tsv'
|
||||
var go118FirstClassTargets = []string{
|
||||
"darwin_amd64_v1",
|
||||
"darwin_arm64",
|
||||
"linux_386",
|
||||
"linux_amd64_v1",
|
||||
"linux_arm_6",
|
||||
"linux_arm64",
|
||||
"windows_386",
|
||||
"windows_amd64_v1",
|
||||
}
|
||||
|
||||
// Build builds a golang build.
|
||||
func (*Builder) Build(ctx *context.Context, build config.Build, options api.Options) error {
|
||||
if err := checkMain(build); err != nil {
|
||||
|
||||
@@ -185,6 +185,42 @@ func TestWithDefaults(t *testing.T) {
|
||||
},
|
||||
goBinary: "go",
|
||||
},
|
||||
"go first class targets": {
|
||||
build: config.Build{
|
||||
ID: "foo3",
|
||||
Binary: "foo",
|
||||
Targets: []string{goStableFirstClassTargetsName},
|
||||
},
|
||||
targets: go118FirstClassTargets,
|
||||
goBinary: "go",
|
||||
},
|
||||
"go 1.18 first class targets": {
|
||||
build: config.Build{
|
||||
ID: "foo3",
|
||||
Binary: "foo",
|
||||
Targets: []string{go118FirstClassTargetsName},
|
||||
},
|
||||
targets: go118FirstClassTargets,
|
||||
goBinary: "go",
|
||||
},
|
||||
"go 1.18 first class targets plus custom": {
|
||||
build: config.Build{
|
||||
ID: "foo3",
|
||||
Binary: "foo",
|
||||
Targets: []string{"linux_amd64_v1", go118FirstClassTargetsName, "darwin_amd64_v2"},
|
||||
},
|
||||
targets: append(go118FirstClassTargets, "darwin_amd64_v2"),
|
||||
goBinary: "go",
|
||||
},
|
||||
"repeatin targets": {
|
||||
build: config.Build{
|
||||
ID: "foo3",
|
||||
Binary: "foo",
|
||||
Targets: []string{go118FirstClassTargetsName, go118FirstClassTargetsName, goStableFirstClassTargetsName},
|
||||
},
|
||||
targets: go118FirstClassTargets,
|
||||
goBinary: "go",
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
if testcase.build.GoBinary != "" && testcase.build.GoBinary != "go" {
|
||||
|
||||
Reference in New Issue
Block a user