-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbuild.go
44 lines (39 loc) · 850 Bytes
/
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
package main
import (
"fmt"
"os"
"os/exec"
)
func buildBinaries() {
// Set the build targets
targets := []struct {
os string
arch string
}{
{"linux", "amd64"},
{"darwin", "amd64"},
{"darwin", "arm64"},
{"windows", "amd64"},
}
// Create the bin folder if it doesn't already exist
if _, err := os.Stat("bin"); os.IsNotExist(err) {
os.Mkdir("bin", 0755)
}
// Build the binaries
for _, target := range targets {
filename := "bin/matcha-" + target.os + "-" + target.arch
fmt.Printf("Building for %s/%s...\n", target.os, target.arch)
if target.os == "windows" {
filename += ".exe"
}
cmd := exec.Command("go", "build", "-o", filename)
cmd.Env = append(os.Environ(),
"GOOS="+target.os,
"GOARCH="+target.arch,
)
if err := cmd.Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
}