-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagefile.go
84 lines (65 loc) · 1.13 KB
/
magefile.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
//go:build mage
// +build mage
package main
import (
"fmt"
"os"
"path"
"runtime"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
type (
Build mg.Namespace
)
var (
name = "pakket-builder"
buildDir = "build"
)
// var Default = Build
type BuildOptions struct {
Static bool
}
func build(arch string, opts BuildOptions) error {
env := map[string]string{
"GOOS": "darwin",
"GOARCH": arch,
}
// Build static binary
if opts.Static {
env["CGO_ENABLED"] = "0"
}
outputName := name
outputPath := path.Join(
buildDir,
runtime.GOARCH, "bin",
outputName,
)
fmt.Printf("Building pakket for %s architecture...\n", runtime.GOARCH)
args := []string{
"build",
"-o",
outputPath,
"-ldflags",
"-s -w",
".",
}
return sh.RunWith(
env, "go", args...,
)
}
func (Build) Intel() error {
return build("amd64", BuildOptions{})
}
func (Build) Silicon() error {
return build("arm64", BuildOptions{})
}
func (Build) All() {
mg.Deps(Build.Intel, Build.Silicon)
}
func Clean() {
sh.Rm("build")
}
func Install() {
os.Rename(fmt.Sprintf("build/pakket-%s", runtime.GOARCH), "/usr/local/bin/pakket")
}