github.com/droot/goreleaser@v0.66.2-0.20180420030140-c2db5fb17157/internal/builders/golang/targets.go (about) 1 package golang 2 3 import ( 4 "fmt" 5 6 "github.com/apex/log" 7 "github.com/goreleaser/goreleaser/config" 8 ) 9 10 type target struct { 11 os, arch, arm string 12 } 13 14 func (t target) String() string { 15 if t.arm != "" { 16 return fmt.Sprintf("%s_%s_%s", t.os, t.arch, t.arm) 17 } 18 return fmt.Sprintf("%s_%s", t.os, t.arch) 19 } 20 21 func matrix(build config.Build) (result []string) { 22 var targets []target 23 for _, target := range allBuildTargets(build) { 24 if !valid(target) { 25 log.WithField("target", target). 26 Debug("skipped invalid build") 27 continue 28 } 29 if ignored(build, target) { 30 log.WithField("target", target). 31 Debug("skipped ignored build") 32 continue 33 } 34 targets = append(targets, target) 35 } 36 for _, target := range targets { 37 result = append(result, target.String()) 38 } 39 return 40 } 41 42 func allBuildTargets(build config.Build) (targets []target) { 43 for _, goos := range build.Goos { 44 for _, goarch := range build.Goarch { 45 if goarch == "arm" { 46 for _, goarm := range build.Goarm { 47 targets = append(targets, target{goos, goarch, goarm}) 48 } 49 continue 50 } 51 targets = append(targets, target{goos, goarch, ""}) 52 } 53 } 54 return 55 } 56 57 // TODO: this could be improved by using a map 58 // https://github.com/goreleaser/goreleaser/pull/522#discussion_r164245014 59 func ignored(build config.Build, target target) bool { 60 for _, ig := range build.Ignore { 61 if ig.Goos != "" && ig.Goos != target.os { 62 continue 63 } 64 if ig.Goarch != "" && ig.Goarch != target.arch { 65 continue 66 } 67 if ig.Goarm != "" && ig.Goarm != target.arm { 68 continue 69 } 70 return true 71 } 72 return false 73 } 74 75 func valid(target target) bool { 76 var s = target.os + target.arch 77 for _, a := range validTargets { 78 if a == s { 79 return true 80 } 81 } 82 return false 83 } 84 85 // list from https://golang.org/doc/install/source#environment 86 var validTargets = []string{ 87 "androidarm", 88 "darwin386", 89 "darwinamd64", 90 // "darwinarm", - requires admin rights and other ios stuff 91 // "darwinarm64", - requires admin rights and other ios stuff 92 "dragonflyamd64", 93 "freebsd386", 94 "freebsdamd64", 95 "freebsdarm", 96 "linux386", 97 "linuxamd64", 98 "linuxarm", 99 "linuxarm64", 100 "linuxppc64", 101 "linuxppc64le", 102 "linuxmips", 103 "linuxmipsle", 104 "linuxmips64", 105 "linuxmips64le", 106 "linuxs390x", 107 "netbsd386", 108 "netbsdamd64", 109 "netbsdarm", 110 "openbsd386", 111 "openbsdamd64", 112 "openbsdarm", 113 "plan9386", 114 "plan9amd64", 115 "solarisamd64", 116 "windows386", 117 "windowsamd64", 118 }