1
15
16 package rule
17
18 import (
19 "sort"
20 )
21
22
23
24
25
26
27 type Platform struct {
28 OS, Arch string
29 }
30
31
32
33 func (p Platform) String() string {
34 switch {
35 case p.OS != "" && p.Arch != "":
36 return p.OS + "_" + p.Arch
37 case p.OS != "":
38 return p.OS
39 case p.Arch != "":
40 return p.Arch
41 default:
42 return ""
43 }
44 }
45
46
47
48
49
50
51 var KnownPlatforms = []Platform{
52 {"aix", "ppc64"},
53 {"android", "386"},
54 {"android", "amd64"},
55 {"android", "arm"},
56 {"android", "arm64"},
57 {"darwin", "386"},
58 {"darwin", "amd64"},
59 {"darwin", "arm"},
60 {"darwin", "arm64"},
61 {"dragonfly", "amd64"},
62 {"freebsd", "386"},
63 {"freebsd", "amd64"},
64 {"freebsd", "arm"},
65 {"freebsd", "arm64"},
66 {"illumos", "amd64"},
67 {"ios", "amd64"},
68 {"ios", "arm64"},
69 {"js", "wasm"},
70 {"linux", "386"},
71 {"linux", "amd64"},
72 {"linux", "arm"},
73 {"linux", "arm64"},
74 {"linux", "mips"},
75 {"linux", "mips64"},
76 {"linux", "mips64le"},
77 {"linux", "mipsle"},
78 {"linux", "ppc64"},
79 {"linux", "ppc64le"},
80 {"linux", "riscv64"},
81 {"linux", "s390x"},
82 {"netbsd", "386"},
83 {"netbsd", "amd64"},
84 {"netbsd", "arm"},
85 {"netbsd", "arm64"},
86 {"openbsd", "386"},
87 {"openbsd", "amd64"},
88 {"openbsd", "arm"},
89 {"openbsd", "arm64"},
90 {"plan9", "386"},
91 {"plan9", "amd64"},
92 {"plan9", "arm"},
93 {"solaris", "amd64"},
94 {"windows", "386"},
95 {"windows", "amd64"},
96 {"windows", "arm"},
97 {"windows", "arm64"},
98 }
99
100 var OSAliases = map[string][]string{
101 "android": {"linux"},
102 "ios": {"darwin"},
103 }
104
105
106
107 var UnixOS = map[string]bool{
108 "aix": true,
109 "android": true,
110 "darwin": true,
111 "dragonfly": true,
112 "freebsd": true,
113 "hurd": true,
114 "illumos": true,
115 "ios": true,
116 "linux": true,
117 "netbsd": true,
118 "openbsd": true,
119 "solaris": true,
120 }
121
122 var (
123
124 KnownOSs []string
125
126
127 KnownOSSet map[string]bool
128
129
130 KnownArchs []string
131
132
133 KnownArchSet map[string]bool
134
135
136 KnownOSArchs map[string][]string
137
138
139 KnownArchOSs map[string][]string
140 )
141
142 func init() {
143 KnownOSSet = make(map[string]bool)
144 KnownArchSet = make(map[string]bool)
145 KnownOSArchs = make(map[string][]string)
146 KnownArchOSs = make(map[string][]string)
147 for _, p := range KnownPlatforms {
148 KnownOSSet[p.OS] = true
149 KnownArchSet[p.Arch] = true
150 KnownOSArchs[p.OS] = append(KnownOSArchs[p.OS], p.Arch)
151 KnownArchOSs[p.Arch] = append(KnownArchOSs[p.Arch], p.OS)
152 }
153 KnownOSs = make([]string, 0, len(KnownOSSet))
154 KnownArchs = make([]string, 0, len(KnownArchSet))
155 for os := range KnownOSSet {
156 KnownOSs = append(KnownOSs, os)
157 }
158 for arch := range KnownArchSet {
159 KnownArchs = append(KnownArchs, arch)
160 }
161 sort.Strings(KnownOSs)
162 sort.Strings(KnownArchs)
163 }
164
View as plain text