Repository: goreleaser/goreleaser
Pull request #1288 (2020-01-04 16:29:10)

feat: support to gomips
<!-- If applied, this commit will... -->

adds support to set `GOMIPS` and `GOMIPS64` when building one of the `mips` `GOARCH`es.

<!-- Why is this change being made? -->

<!-- # Provide links to any relevant tickets, URLs or other resources -->


closes https://github.com/goreleaser/goreleaser/issues/1287

codecov-io: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1288?src=pr&el=h1) Report
> Merging [#1288](https://codecov.io/gh/goreleaser/goreleaser/pull/1288?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/5f5f263aa8cc293a5684786af73ef68a7b77b902?src=pr&el=desc) will **increase** coverage by `0.08%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/1288/graphs/tree.svg?width=650&token=3bJvv6b7hN&height=150&src=pr)](https://codecov.io/gh/goreleaser/goreleaser/pull/1288?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1288      +/-   ##
==========================================
+ Coverage   83.82%   83.91%   +0.08%     
==========================================
  Files          59       59              
  Lines        3358     3375      +17     
==========================================
+ Hits         2815     2832      +17     
  Misses        461      461              
  Partials       82       82
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/1288?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/config/config.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1288/diff?src=pr&el=tree#diff-cGtnL2NvbmZpZy9jb25maWcuZ28=) | `100% <ø> (ø)` | :arrow_up: |
| [internal/artifact/artifact.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1288/diff?src=pr&el=tree#diff-aW50ZXJuYWwvYXJ0aWZhY3QvYXJ0aWZhY3QuZ28=) | `83.62% <ø> (ø)` | :arrow_up: |
| [internal/builders/golang/build.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1288/diff?src=pr&el=tree#diff-aW50ZXJuYWwvYnVpbGRlcnMvZ29sYW5nL2J1aWxkLmdv) | `98.48% <100%> (+0.05%)` | :arrow_up: |
| [internal/builders/golang/targets.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1288/diff?src=pr&el=tree#diff-aW50ZXJuYWwvYnVpbGRlcnMvZ29sYW5nL3RhcmdldHMuZ28=) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1288?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1288?src=pr&el=footer). Last update [5f5f263...5600889](https://codecov.io/gh/goreleaser/goreleaser/pull/1288?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/internal/artifact/artifact.go b/internal/artifact/artifact.go
index f4eaf6cb..58b631c6 100644
--- a/internal/artifact/artifact.go
+++ b/internal/artifact/artifact.go
@@ -72,6 +72,7 @@ type Artifact struct {
 	Goos   string
 	Goarch string
 	Goarm  string
+	Gomips string
 	Type   Type
 	Extra  map[string]interface{}
 }
diff --git a/internal/builders/golang/build.go b/internal/builders/golang/build.go
index 1f4a248a..6c6b10a9 100644
--- a/internal/builders/golang/build.go
+++ b/internal/builders/golang/build.go
@@ -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,
@@ -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) {
@@ -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
 }
 
@@ -179,6 +183,8 @@ func (b buildTarget) Env() []string {
 		"GOOS=" + b.os,
 		"GOARCH=" + b.arch,
 		"GOARM=" + b.arm,
+		"GOMIPS=" + b.mips,
+		"GOMIPS64=" + b.mips,
 	}
 }
 
diff --git a/internal/builders/golang/targets.go b/internal/builders/golang/targets.go
index 703aef01..74fdc89d 100644
--- a/internal/builders/golang/targets.go
+++ b/internal/builders/golang/targets.go
@@ -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)
 }
 
@@ -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,
@@ -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
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 4748fb4d..f883831c 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -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
@@ -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"`
diff --git a/www/content/build.md b/www/content/build.md
index 862f9eeb..c0cdacf6 100644
--- a/www/content/build.md
+++ b/www/content/build.md
@@ -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:
@@ -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.


Test patch:
diff --git a/internal/builders/golang/build_test.go b/internal/builders/golang/build_test.go
index d6ed2af0..1a689c8c 100644
--- a/internal/builders/golang/build_test.go
+++ b/internal/builders/golang/build_test.go
@@ -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",
@@ -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="},
@@ -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"),
diff --git a/internal/builders/golang/targets_test.go b/internal/builders/golang/targets_test.go
index c38557df..c39f9393 100644
--- a/internal/builders/golang/targets_test.go
+++ b/internal/builders/golang/targets_test.go
@@ -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",
@@ -39,6 +47,12 @@ func TestAllBuildTargets(t *testing.T) {
 			}, {
 				Goos:   "openbsd",
 				Goarch: "arm",
+			}, {
+				Goarch: "mips64",
+				Gomips: "hardfloat",
+			}, {
+				Goarch: "mips64le",
+				Gomips: "softfloat",
 			},
 		},
 	}
@@ -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",
@@ -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, "", ""}))
 		})
 	}
 }