-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.go
63 lines (49 loc) · 1.6 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
//go:build never
package main
import (
"flag"
"os"
module "github.com/tensorworks/go-build-helpers/pkg/module"
validation "github.com/tensorworks/go-build-helpers/pkg/validation"
)
// Alias validation.ExitIfError() as check()
var check = validation.ExitIfError
func main() {
// Parse our command-line flags
doClean := flag.Bool("clean", false, "cleans build outputs")
doRelease := flag.Bool("release", false, "builds executables for all target platforms")
flag.Parse()
// Disable CGO
os.Setenv("CGO_ENABLED", "0")
// Create a build helper for the Go module in the current working directory
mod, err := module.ModuleInCwd()
check(err)
// Determine if we're cleaning the build outputs
if *doClean == true {
check(mod.CleanAll())
os.Exit(0)
}
// Install the `go-winres` tool that we use for embedding manifest data in Windows builds
check(mod.InstallGoTools([]string{
"github.com/tc-hib/[email protected]",
}))
// Run `go generate` to invoke `go-winres`
check(mod.Generate())
// Determine if we're building our executables for just the host platform or for the full matrix of release platforms
if *doRelease == false {
check(mod.BuildBinariesForHost(module.DefaultBinDir, module.BuildOptions{Scheme: module.Undecorated}))
} else {
check(mod.BuildBinariesForMatrix(
module.DefaultBinDir,
module.BuildOptions{
AdditionalFlags: []string{"-ldflags", "-s -w"},
Scheme: module.SuffixedFilenames,
},
module.BuildMatrix{
Platforms: []string{"linux", "windows"},
Architectures: []string{"386", "amd64", "arm64"},
Ignore: []string{},
},
))
}
}