1
- // + build mage
1
+ //go: build mage
2
2
3
3
package main
4
4
@@ -7,13 +7,34 @@ import (
7
7
"fmt"
8
8
"os"
9
9
"path"
10
+ "sort"
10
11
11
12
"github.com/magefile/mage/mg"
12
13
"github.com/magefile/mage/sh"
13
14
)
14
15
16
+ func intersect (a , b []string ) []string {
17
+ sort .Strings (a )
18
+ sort .Strings (b )
19
+
20
+ res := make ([]string , 0 , func () int {
21
+ if len (a ) < len (b ) {
22
+ return len (a )
23
+ }
24
+ return len (b )
25
+ }())
26
+
27
+ for _ , v := range a {
28
+ idx := sort .SearchStrings (b , v )
29
+ if idx < len (b ) && b [idx ] == v {
30
+ res = append (res , v )
31
+ }
32
+ }
33
+ return res
34
+ }
35
+
15
36
// getBuildMatrix returns the build matrix from the current version of the go compiler
16
- func getBuildMatrix () (map [string ][]string , error ) {
37
+ func getFullBuildMatrix () (map [string ][]string , error ) {
17
38
jsonData , err := sh .Output ("go" , "tool" , "dist" , "list" , "-json" )
18
39
if err != nil {
19
40
return nil , err
@@ -38,6 +59,31 @@ func getBuildMatrix() (map[string][]string, error) {
38
59
return matrix , nil
39
60
}
40
61
62
+ func getBuildMatrix () (map [string ][]string , error ) {
63
+ minimalMatrix := map [string ][]string {
64
+ "linux" : []string {"amd64" },
65
+ "darwin" : []string {"amd64" , "arm64" },
66
+ "freebsd" : []string {"amd64" },
67
+ "js" : []string {"wasm" },
68
+ "solaris" : []string {"amd64" },
69
+ "windows" : []string {"amd64" , "arm64" },
70
+ }
71
+
72
+ fullMatrix , err := getFullBuildMatrix ()
73
+ if err != nil {
74
+ return nil , err
75
+ }
76
+
77
+ for os , arches := range minimalMatrix {
78
+ if fullV , ok := fullMatrix [os ]; ! ok {
79
+ delete (minimalMatrix , os )
80
+ } else {
81
+ minimalMatrix [os ] = intersect (arches , fullV )
82
+ }
83
+ }
84
+ return minimalMatrix , nil
85
+ }
86
+
41
87
func CrossBuild () error {
42
88
matrix , err := getBuildMatrix ()
43
89
if err != nil {
0 commit comments