-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.go
65 lines (50 loc) · 1.08 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
//go:build ignore
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"sync"
)
const version = "v1.1.0"
type target struct {
goos string
goarch string
}
var targets = []target{
{"linux", "amd64"},
{"linux", "arm64"},
{"darwin", "amd64"},
{"darwin", "arm64"},
{"windows", "amd64"},
{"windows", "arm64"},
{"freebsd", "amd64"},
{"freebsd", "arm64"},
{"openbsd", "amd64"},
{"openbsd", "arm64"},
{"netbsd", "amd64"},
{"netbsd", "arm64"},
}
func main() {
os.MkdirAll("release", 0750)
var wg sync.WaitGroup
wg.Add(len(targets))
for _, tar := range targets {
go func(t target) {
path := filepath.Join("release", "ghdstats-"+version+"-"+t.goos+"-"+t.goarch)
if t.goos == "windows" {
path += ".exe"
}
cmd := exec.Command("go", "build", "-trimpath", "-ldflags", "-s -w", "-o", path)
cmd.Env = append(os.Environ(), "GOOS="+t.goos, "GOARCH="+t.goarch)
out, err := cmd.CombinedOutput()
if err != nil {
fmt.Fprintf(os.Stderr, "%s %s err: %s, out: %s\n", t.goos, t.goarch, err, out)
os.Exit(1)
}
wg.Done()
}(tar)
}
wg.Wait()
}