-
Notifications
You must be signed in to change notification settings - Fork 22
/
plugin_package.go
84 lines (70 loc) · 1.79 KB
/
plugin_package.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
package plugin
import (
"errors"
)
const (
GoOSLinux = "linux"
GoOSWindows = "windows"
GoOSDarwin = "darwin"
GoArchAmd64 = "amd64"
GoArchArm64 = "arm64"
)
type Kind string
const (
KindSource Kind = "source"
KindDestination Kind = "destination"
)
func (k Kind) Validate() error {
switch k {
case KindSource, KindDestination:
return nil
default:
return errors.New("invalid plugin kind: must be one of source, destination")
}
}
type PackageType string
const (
PackageTypeNative PackageType = "native"
)
type BuildTarget struct {
OS string `json:"os"`
Arch string `json:"arch"`
CGO bool `json:"cgo"`
Env []string `json:"env"`
}
func (t BuildTarget) EnvVariables() []string {
variables := append(t.cgoEnvVariables(), "GOOS="+t.OS, "GOARCH="+t.Arch)
return append(variables, t.Env...)
}
func (t BuildTarget) cgoEnvVariables() []string {
// default is to tool at the param. Can be overridden by adding `CGO_ENABLED=1` to BuildTarget.Env
if !t.CGO {
return []string{"CGO_ENABLED=0"}
}
switch t.OS {
case GoOSWindows:
return []string{"CGO_ENABLED=1", "CC=x86_64-w64-mingw32-gcc", "CXX=x86_64-w64-mingw32-g++"}
case GoOSDarwin:
return []string{"CGO_ENABLED=1", "CC=o64-clang", "CXX=o64-clang++"}
case GoOSLinux:
// nop, see below
default:
return []string{"CGO_ENABLED=1"}
}
// linux
switch t.Arch {
case GoArchAmd64:
return []string{"CGO_ENABLED=1", "CC=gcc", "CXX=g++"}
case GoArchArm64:
return []string{"CGO_ENABLED=1", "CC=aarch64-linux-gnu-gcc", "CXX=aarch64-linux-gnu-g++"}
default:
return []string{"CGO_ENABLED=1"}
}
}
var DefaultBuildTargets = []BuildTarget{
{OS: GoOSLinux, Arch: GoArchAmd64},
{OS: GoOSLinux, Arch: GoArchArm64},
{OS: GoOSWindows, Arch: GoArchAmd64},
{OS: GoOSDarwin, Arch: GoArchAmd64},
{OS: GoOSDarwin, Arch: GoArchArm64},
}