Skip to content

Commit

Permalink
feat: support to gomips (#1288)
Browse files Browse the repository at this point in the history
* feat: support to gomips

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: prefix

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Jan 26, 2020
1 parent 5f2cf50 commit 3bfb363
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 5 deletions.
1 change: 1 addition & 0 deletions internal/artifact/artifact.go
Expand Up @@ -72,6 +72,7 @@ type Artifact struct {
Goos string
Goarch string
Goarm string
Gomips string
Type Type
Extra map[string]interface{}
}
Expand Down
10 changes: 8 additions & 2 deletions internal/builders/golang/build.go
Expand Up @@ -79,6 +79,7 @@ func (*Builder) Build(ctx *context.Context, build config.Build, options api.Opti
Goos: target.os,
Goarch: target.arch,
Goarm: target.arm,
Gomips: target.mips,
Extra: map[string]interface{}{
"Binary": build.Binary,
"Ext": options.Ext,
Expand Down Expand Up @@ -157,7 +158,7 @@ func run(ctx *context.Context, command, env []string, dir string) error {
}

type buildTarget struct {
os, arch, arm string
os, arch, arm, mips string
}

func newBuildTarget(s string) (buildTarget, error) {
Expand All @@ -168,9 +169,12 @@ func newBuildTarget(s string) (buildTarget, error) {
}
t.os = parts[0]
t.arch = parts[1]
if len(parts) == 3 {
if strings.HasPrefix(t.arch, "arm") && len(parts) == 3 {
t.arm = parts[2]
}
if strings.HasPrefix(t.arch, "mips") && len(parts) == 3 {
t.mips = parts[2]
}
return t, nil
}

Expand All @@ -179,6 +183,8 @@ func (b buildTarget) Env() []string {
"GOOS=" + b.os,
"GOARCH=" + b.arch,
"GOARM=" + b.arm,
"GOMIPS=" + b.mips,
"GOMIPS64=" + b.mips,
}
}

Expand Down
33 changes: 33 additions & 0 deletions internal/builders/golang/build_test.go
Expand Up @@ -38,13 +38,18 @@ func TestWithDefaults(t *testing.T) {
Goarch: []string{
"amd64",
"arm",
"mips",
},
Goarm: []string{
"6",
},
Gomips: []string{
"softfloat",
},
},
targets: []string{
"linux_amd64",
"linux_mips_softfloat",
"darwin_amd64",
"windows_amd64",
"linux_arm_6",
Expand Down Expand Up @@ -93,6 +98,8 @@ func TestBuild(t *testing.T) {
"windows_amd64",
"linux_arm_6",
"js_wasm",
"linux_mips_softfloat",
"linux_mips64le_softfloat",
},
Asmflags: []string{".=", "all="},
Gcflags: []string{"all="},
Expand Down Expand Up @@ -133,6 +140,32 @@ func TestBuild(t *testing.T) {
"ID": "foo",
},
},
{
Name: "foo",
Path: filepath.Join(folder, "dist", "linux_mips_softfloat", "foo"),
Goos: "linux",
Goarch: "mips",
Gomips: "softfloat",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": "",
"Binary": "foo",
"ID": "foo",
},
},
{
Name: "foo",
Path: filepath.Join(folder, "dist", "linux_mips64le_softfloat", "foo"),
Goos: "linux",
Goarch: "mips64le",
Gomips: "softfloat",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": "",
"Binary": "foo",
"ID": "foo",
},
},
{
Name: "foo",
Path: filepath.Join(folder, "dist", "darwin_amd64", "foo"),
Expand Down
19 changes: 18 additions & 1 deletion internal/builders/golang/targets.go
Expand Up @@ -2,19 +2,23 @@ package golang

import (
"fmt"
"strings"

"github.com/apex/log"
"github.com/goreleaser/goreleaser/pkg/config"
)

type target struct {
os, arch, arm string
os, arch, arm, mips string
}

func (t target) String() string {
if t.arm != "" {
return fmt.Sprintf("%s_%s_%s", t.os, t.arch, t.arm)
}
if t.mips != "" {
return fmt.Sprintf("%s_%s_%s", t.os, t.arch, t.mips)
}
return fmt.Sprintf("%s_%s", t.os, t.arch)
}

Expand Down Expand Up @@ -53,6 +57,16 @@ func allBuildTargets(build config.Build) (targets []target) {
}
continue
}
if strings.HasPrefix(goarch, "mips") {
for _, gomips := range build.Gomips {
targets = append(targets, target{
os: goos,
arch: goarch,
mips: gomips,
})
}
continue
}
targets = append(targets, target{
os: goos,
arch: goarch,
Expand All @@ -75,6 +89,9 @@ func ignored(build config.Build, target target) bool {
if ig.Goarm != "" && ig.Goarm != target.arm {
continue
}
if ig.Gomips != "" && ig.Gomips != target.mips {
continue
}
return true
}
return false
Expand Down
22 changes: 21 additions & 1 deletion internal/builders/golang/targets_test.go
Expand Up @@ -23,11 +23,19 @@ func TestAllBuildTargets(t *testing.T) {
"arm",
"arm64",
"wasm",
"mips",
"mips64",
"mipsle",
"mips64le",
},
Goarm: []string{
"6",
"7",
},
Gomips: []string{
"hardfloat",
"softfloat",
},
Ignore: []config.IgnoredBuild{
{
Goos: "darwin",
Expand All @@ -39,6 +47,12 @@ func TestAllBuildTargets(t *testing.T) {
}, {
Goos: "openbsd",
Goarch: "arm",
}, {
Goarch: "mips64",
Gomips: "hardfloat",
}, {
Goarch: "mips64le",
Gomips: "softfloat",
},
},
}
Expand All @@ -47,6 +61,12 @@ func TestAllBuildTargets(t *testing.T) {
"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",
"darwin_amd64",
"freebsd_386",
"freebsd_amd64",
Expand Down Expand Up @@ -109,7 +129,7 @@ func TestGoosGoarchCombos(t *testing.T) {
}
for _, p := range platforms {
t.Run(fmt.Sprintf("%v %v valid=%v", p.os, p.arch, p.valid), func(t *testing.T) {
assert.Equal(t, p.valid, valid(target{p.os, p.arch, ""}))
assert.Equal(t, p.valid, valid(target{p.os, p.arch, "", ""}))
})
}
}
3 changes: 2 additions & 1 deletion pkg/config/config.go
Expand Up @@ -97,7 +97,7 @@ type Hooks struct {

// IgnoredBuild represents a build ignored by the user
type IgnoredBuild struct {
Goos, Goarch, Goarm string
Goos, Goarch, Goarm, Gomips string
}

// StringArray is a wrapper for an array of strings
Expand Down Expand Up @@ -142,6 +142,7 @@ type Build struct {
Goos []string `yaml:",omitempty"`
Goarch []string `yaml:",omitempty"`
Goarm []string `yaml:",omitempty"`
Gomips []string `yaml:",omitempty"`
Targets []string `yaml:",omitempty"`
Ignore []IgnoredBuild `yaml:",omitempty"`
Dir string `yaml:",omitempty"`
Expand Down
9 changes: 9 additions & 0 deletions www/content/build.md
Expand Up @@ -86,6 +86,13 @@ builds:
- 6
- 7

# GOMIPS and GOMIPS64 to build when GOARCH is mips, mips64, mipsle or mips64le.
# For more info refer to: https://golang.org/doc/install/source#environment
# Default is empty.
gomips:
- hardfloat
- softfloat

# List of combinations of GOOS + GOARCH + GOARM to ignore.
# Default is empty.
ignore:
Expand All @@ -94,6 +101,8 @@ builds:
- goos: linux
goarch: arm
goarm: 7
- goarm: mips64
gomips: hardfloat

# Hooks can be used to customize the final binary,
# for example, to run generators.
Expand Down

0 comments on commit 3bfb363

Please sign in to comment.