2
2
// Use of this source code is governed by a BSD-style
3
3
// license that can be found in the LICENSE file.
4
4
5
+ //go:generate go test . -run=TestGenerated -fix
6
+
5
7
package platform
6
8
9
+ // An OSArch is a pair of GOOS and GOARCH values indicating a platform.
10
+ type OSArch struct {
11
+ GOOS , GOARCH string
12
+ }
13
+
14
+ func (p OSArch ) String () string {
15
+ return p .GOOS + "/" + p .GOARCH
16
+ }
17
+
7
18
// RaceDetectorSupported reports whether goos/goarch supports the race
8
19
// detector. There is a copy of this function in cmd/dist/test.go.
9
20
// Race detector only supports 48-bit VMA on arm64. But it will always
@@ -123,11 +134,11 @@ func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
123
134
return true
124
135
}
125
136
126
- platform := goos + "/" + goarch
127
- if _ , ok := osArchSupportsCgo [platform ]; ! ok {
137
+ if _ , ok := distInfo [OSArch {goos , goarch }]; ! ok {
128
138
return false // platform unrecognized
129
139
}
130
140
141
+ platform := goos + "/" + goarch
131
142
switch buildmode {
132
143
case "archive" :
133
144
return true
@@ -239,11 +250,6 @@ func DefaultPIE(goos, goarch string, isRace bool) bool {
239
250
return false
240
251
}
241
252
242
- // CgoSupported reports whether goos/goarch supports cgo.
243
- func CgoSupported (goos , goarch string ) bool {
244
- return osArchSupportsCgo [goos + "/" + goarch ]
245
- }
246
-
247
253
// ExecutableHasDWARF reports whether the linked executable includes DWARF
248
254
// symbols on goos/goarch.
249
255
func ExecutableHasDWARF (goos , goarch string ) bool {
@@ -253,3 +259,28 @@ func ExecutableHasDWARF(goos, goarch string) bool {
253
259
}
254
260
return true
255
261
}
262
+
263
+ // osArchInfo describes information about an OSArch extracted from cmd/dist and
264
+ // stored in the generated distInfo map.
265
+ type osArchInfo struct {
266
+ CgoSupported bool
267
+ FirstClass bool
268
+ Broken bool
269
+ }
270
+
271
+ // CgoSupported reports whether goos/goarch supports cgo.
272
+ func CgoSupported (goos , goarch string ) bool {
273
+ return distInfo [OSArch {goos , goarch }].CgoSupported
274
+ }
275
+
276
+ // FirstClass reports whether goos/goarch is considered a “first class” port.
277
+ // (See https://go.dev/wiki/PortingPolicy#first-class-ports.)
278
+ func FirstClass (goos , goarch string ) bool {
279
+ return distInfo [OSArch {goos , goarch }].FirstClass
280
+ }
281
+
282
+ // Broken reportsr whether goos/goarch is considered a broken port.
283
+ // (See https://go.dev/wiki/PortingPolicy#broken-ports.)
284
+ func Broken (goos , goarch string ) bool {
285
+ return distInfo [OSArch {goos , goarch }].Broken
286
+ }
0 commit comments