-
Notifications
You must be signed in to change notification settings - Fork 386
/
platform.go
147 lines (131 loc) · 3.83 KB
/
platform.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* Copyright 2017 The Bazel Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package rule
import (
"sort"
)
// Platform represents a GOOS/GOARCH pair. When Platform is used to describe
// sources, dependencies, or flags, either OS or Arch may be empty.
//
// DEPRECATED: do not use outside language/go. This type is Go-specific
// and should be moved to the Go extension.
type Platform struct {
OS, Arch string
}
// String returns OS, Arch, or "OS_Arch" if both are set. This must match
// the names of config_setting rules in @io_bazel_rules_go//go/platform.
func (p Platform) String() string {
switch {
case p.OS != "" && p.Arch != "":
return p.OS + "_" + p.Arch
case p.OS != "":
return p.OS
case p.Arch != "":
return p.Arch
default:
return ""
}
}
// KnownPlatforms is the set of target platforms that Go supports. Gazelle
// will generate multi-platform build files using these tags. rules_go and
// Bazel may not actually support all of these.
//
// DEPRECATED: do not use outside language/go.
var KnownPlatforms = []Platform{
{"aix", "ppc64"},
{"android", "386"},
{"android", "amd64"},
{"android", "arm"},
{"android", "arm64"},
{"darwin", "386"},
{"darwin", "amd64"},
{"darwin", "arm"},
{"darwin", "arm64"},
{"dragonfly", "amd64"},
{"freebsd", "386"},
{"freebsd", "amd64"},
{"freebsd", "arm"},
{"freebsd", "arm64"},
{"illumos", "amd64"},
{"ios", "386"},
{"ios", "amd64"},
{"ios", "arm"},
{"ios", "arm64"},
{"js", "wasm"},
{"linux", "386"},
{"linux", "amd64"},
{"linux", "arm"},
{"linux", "arm64"},
{"linux", "mips"},
{"linux", "mips64"},
{"linux", "mips64le"},
{"linux", "mipsle"},
{"linux", "ppc64"},
{"linux", "ppc64le"},
{"linux", "riscv64"},
{"linux", "s390x"},
{"netbsd", "386"},
{"netbsd", "amd64"},
{"netbsd", "arm"},
{"netbsd", "arm64"},
{"openbsd", "386"},
{"openbsd", "amd64"},
{"openbsd", "arm"},
{"openbsd", "arm64"},
{"plan9", "386"},
{"plan9", "amd64"},
{"plan9", "arm"},
{"solaris", "amd64"},
{"windows", "386"},
{"windows", "amd64"},
{"windows", "arm"},
}
var OSAliases = map[string][]string{
"android": []string{"linux"},
"ios": []string{"darwin"},
}
var (
// KnownOSs is the sorted list of operating systems that Go supports.
KnownOSs []string
// KnownOSSet is the set of operating systems that Go supports.
KnownOSSet map[string]bool
// KnownArchs is the sorted list of architectures that Go supports.
KnownArchs []string
// KnownArchSet is the set of architectures that Go supports.
KnownArchSet map[string]bool
// KnownOSArchs is a map from OS to the archictures they run on.
KnownOSArchs map[string][]string
// KnownArchOSs is a map from architectures to that OSs that run on them.
KnownArchOSs map[string][]string
)
func init() {
KnownOSSet = make(map[string]bool)
KnownArchSet = make(map[string]bool)
KnownOSArchs = make(map[string][]string)
KnownArchOSs = make(map[string][]string)
for _, p := range KnownPlatforms {
KnownOSSet[p.OS] = true
KnownArchSet[p.Arch] = true
KnownOSArchs[p.OS] = append(KnownOSArchs[p.OS], p.Arch)
KnownArchOSs[p.Arch] = append(KnownArchOSs[p.Arch], p.OS)
}
KnownOSs = make([]string, 0, len(KnownOSSet))
KnownArchs = make([]string, 0, len(KnownArchSet))
for os := range KnownOSSet {
KnownOSs = append(KnownOSs, os)
}
for arch := range KnownArchSet {
KnownArchs = append(KnownArchs, arch)
}
sort.Strings(KnownOSs)
sort.Strings(KnownArchs)
}