refactor: update platform package to match original Go structure
Updated runtime/internal/lib/internal/platform/platform.go to match the original Go internal/platform package structure: - Added OSArch struct with GOOS and GOARCH fields - Added osArchInfo struct with CgoSupported, FirstClass, and Broken fields - Created distInfo map using OSArch as keys - Updated CgoSupported function to use map lookup (matches original implementation) This change makes the package structure more consistent with Go's standard library and follows the established pattern more closely. 🤖 Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <luoliwoshang@users.noreply.github.com>
This commit is contained in:
@@ -8,22 +8,58 @@ package platform
|
|||||||
// llgo:skipall
|
// llgo:skipall
|
||||||
type _platform struct{}
|
type _platform struct{}
|
||||||
|
|
||||||
// CgoSupported returns whether CGO is supported for the given GOOS/GOARCH.
|
// An OSArch is a pair of GOOS and GOARCH values indicating a platform.
|
||||||
// This is a simplified version of internal/platform.CgoSupported.
|
type OSArch struct {
|
||||||
func CgoSupported(goos, goarch string) bool {
|
GOOS, GOARCH string
|
||||||
// Most common platforms support CGO
|
}
|
||||||
switch goos + "/" + goarch {
|
|
||||||
case "darwin/amd64", "darwin/arm64",
|
func (p OSArch) String() string {
|
||||||
"linux/386", "linux/amd64", "linux/arm", "linux/arm64",
|
return p.GOOS + "/" + p.GOARCH
|
||||||
"windows/386", "windows/amd64", "windows/arm64",
|
}
|
||||||
"freebsd/386", "freebsd/amd64", "freebsd/arm", "freebsd/arm64",
|
|
||||||
"openbsd/386", "openbsd/amd64", "openbsd/arm", "openbsd/arm64",
|
// osArchInfo describes information about an OSArch.
|
||||||
"netbsd/386", "netbsd/amd64", "netbsd/arm", "netbsd/arm64",
|
type osArchInfo struct {
|
||||||
"android/386", "android/amd64", "android/arm", "android/arm64",
|
CgoSupported bool
|
||||||
"illumos/amd64",
|
FirstClass bool
|
||||||
"solaris/amd64",
|
Broken bool
|
||||||
"linux/ppc64le", "linux/riscv64", "linux/s390x":
|
}
|
||||||
return true
|
|
||||||
}
|
// distInfo maps OSArch to information about cgo support.
|
||||||
return false
|
// This is a simplified version covering the most common platforms.
|
||||||
|
var distInfo = map[OSArch]osArchInfo{
|
||||||
|
{"darwin", "amd64"}: {CgoSupported: true, FirstClass: true},
|
||||||
|
{"darwin", "arm64"}: {CgoSupported: true, FirstClass: true},
|
||||||
|
{"linux", "386"}: {CgoSupported: true, FirstClass: true},
|
||||||
|
{"linux", "amd64"}: {CgoSupported: true, FirstClass: true},
|
||||||
|
{"linux", "arm"}: {CgoSupported: true, FirstClass: true},
|
||||||
|
{"linux", "arm64"}: {CgoSupported: true, FirstClass: true},
|
||||||
|
{"linux", "ppc64le"}: {CgoSupported: true},
|
||||||
|
{"linux", "riscv64"}: {CgoSupported: true},
|
||||||
|
{"linux", "s390x"}: {CgoSupported: true},
|
||||||
|
{"windows", "386"}: {CgoSupported: true, FirstClass: true},
|
||||||
|
{"windows", "amd64"}: {CgoSupported: true, FirstClass: true},
|
||||||
|
{"windows", "arm64"}: {CgoSupported: true},
|
||||||
|
{"freebsd", "386"}: {CgoSupported: true},
|
||||||
|
{"freebsd", "amd64"}: {CgoSupported: true},
|
||||||
|
{"freebsd", "arm"}: {CgoSupported: true},
|
||||||
|
{"freebsd", "arm64"}: {CgoSupported: true},
|
||||||
|
{"openbsd", "386"}: {CgoSupported: true},
|
||||||
|
{"openbsd", "amd64"}: {CgoSupported: true},
|
||||||
|
{"openbsd", "arm"}: {CgoSupported: true},
|
||||||
|
{"openbsd", "arm64"}: {CgoSupported: true},
|
||||||
|
{"netbsd", "386"}: {CgoSupported: true},
|
||||||
|
{"netbsd", "amd64"}: {CgoSupported: true},
|
||||||
|
{"netbsd", "arm"}: {CgoSupported: true},
|
||||||
|
{"netbsd", "arm64"}: {CgoSupported: true},
|
||||||
|
{"android", "386"}: {CgoSupported: true},
|
||||||
|
{"android", "amd64"}: {CgoSupported: true},
|
||||||
|
{"android", "arm"}: {CgoSupported: true},
|
||||||
|
{"android", "arm64"}: {CgoSupported: true},
|
||||||
|
{"illumos", "amd64"}: {CgoSupported: true},
|
||||||
|
{"solaris", "amd64"}: {CgoSupported: true},
|
||||||
|
}
|
||||||
|
|
||||||
|
// CgoSupported reports whether goos/goarch supports cgo.
|
||||||
|
func CgoSupported(goos, goarch string) bool {
|
||||||
|
return distInfo[OSArch{goos, goarch}].CgoSupported
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user