-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.go
98 lines (91 loc) · 1.98 KB
/
build.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// DO NOT RUN DIRECTLY
package main
import (
"fmt"
"os"
"os/exec"
)
const (
binDir = "bin"
goBin = "go"
myos = "linux"
myarch = "amd64"
)
func main() {
total := len(knownArch) * len(knownOS)
filePrefix := os.Args[1]
for os_ := range knownOS {
for arch := range knownArch {
addExe := func() string {
switch os_ {
case "windows":
return ".exe"
default:
return ""
}
}
file := fmt.Sprintf("%s-%s-%s%s", filePrefix, os_, arch, addExe())
filePath := fmt.Sprintf("../%s/%s", binDir, file)
fmt.Printf("%d %-40s ", total, file)
cmd := exec.Command(goBin, "build", "-o", filePath, "-ldflags", "-s -w")
cmd.Env = os.Environ()
if myos == os_ && myarch == arch {
cmd.Env = append(cmd.Env, "CGO_ENABLED=0")
}
cmd.Env = append(cmd.Env, fmt.Sprintf("GOOS=%s", os_))
cmd.Env = append(cmd.Env, fmt.Sprintf("GOARCH=%s", arch))
if err := cmd.Run(); err == nil {
fmt.Print("OK")
}
fmt.Println()
total--
}
}
}
// https://github.com/golang/go/blob/master/src/internal/syslist/syslist.go
var knownOS = map[string]bool{
"aix": true,
"android": true,
"darwin": true,
"dragonfly": true,
"freebsd": true,
"hurd": true,
"illumos": true,
"ios": true,
"js": true,
"linux": true,
"nacl": true,
"netbsd": true,
"openbsd": true,
"plan9": true,
"solaris": true,
"wasip1": true,
"windows": true,
"zos": true,
}
var knownArch = map[string]bool{
"386": true,
"amd64": true,
"amd64p32": true,
"arm": true,
"armbe": true,
"arm64": true,
"arm64be": true,
"loong64": true,
"mips": true,
"mipsle": true,
"mips64": true,
"mips64le": true,
"mips64p32": true,
"mips64p32le": true,
"ppc": true,
"ppc64": true,
"ppc64le": true,
"riscv": true,
"riscv64": true,
"s390": true,
"s390x": true,
"sparc": true,
"sparc64": true,
"wasm": true,
}