refactor: move cgoSupported to internal/platform package

Created runtime/internal/lib/internal/platform package to house the
CgoSupported function, following the established pattern used by other
internal packages like internal/itoa.

Changes:
- Created runtime/internal/lib/internal/platform/platform.go
- Moved cgoSupported function to platform.CgoSupported
- Updated runtime/internal/lib/go/build/build.go to import and use
  the new package

This refactoring improves code organization by separating
platform-specific utilities into their own package, making the code
more maintainable and reusable.

🤖 Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: luoliwoshang <luoliwoshang@users.noreply.github.com>
This commit is contained in:
xgopilot
2025-10-16 04:05:58 +00:00
parent 224e3b9440
commit c4fdb1edc0
2 changed files with 32 additions and 21 deletions

View File

@@ -14,6 +14,8 @@ import (
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"github.com/goplus/llgo/runtime/internal/lib/internal/platform"
) )
// Type aliases to reference standard library types // Type aliases to reference standard library types
@@ -77,7 +79,7 @@ func defaultContext() Context {
c.CgoEnabled = false c.CgoEnabled = false
default: default:
if runtime.GOARCH == c.GOARCH && runtime.GOOS == c.GOOS { if runtime.GOARCH == c.GOARCH && runtime.GOOS == c.GOOS {
c.CgoEnabled = cgoSupported(c.GOOS, c.GOARCH) c.CgoEnabled = platform.CgoSupported(c.GOOS, c.GOARCH)
break break
} }
c.CgoEnabled = false c.CgoEnabled = false
@@ -120,23 +122,3 @@ func buildToolTags() []string {
"goexperiment.boringcrypto", // Default boring crypto experiment "goexperiment.boringcrypto", // Default boring crypto experiment
} }
} }
// cgoSupported returns whether CGO is supported for the given GOOS/GOARCH.
// This is a simplified version of internal/platform.CgoSupported.
func cgoSupported(goos, goarch string) bool {
// Most common platforms support CGO
switch goos + "/" + goarch {
case "darwin/amd64", "darwin/arm64",
"linux/386", "linux/amd64", "linux/arm", "linux/arm64",
"windows/386", "windows/amd64", "windows/arm64",
"freebsd/386", "freebsd/amd64", "freebsd/arm", "freebsd/arm64",
"openbsd/386", "openbsd/amd64", "openbsd/arm", "openbsd/arm64",
"netbsd/386", "netbsd/amd64", "netbsd/arm", "netbsd/arm64",
"android/386", "android/amd64", "android/arm", "android/arm64",
"illumos/amd64",
"solaris/amd64",
"linux/ppc64le", "linux/riscv64", "linux/s390x":
return true
}
return false
}

View File

@@ -0,0 +1,29 @@
// Copyright 2024 The GoPlus Authors (goplus.org). All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package platform provides platform-specific utilities.
package platform
// llgo:skipall
type _platform struct{}
// CgoSupported returns whether CGO is supported for the given GOOS/GOARCH.
// This is a simplified version of internal/platform.CgoSupported.
func CgoSupported(goos, goarch string) bool {
// Most common platforms support CGO
switch goos + "/" + goarch {
case "darwin/amd64", "darwin/arm64",
"linux/386", "linux/amd64", "linux/arm", "linux/arm64",
"windows/386", "windows/amd64", "windows/arm64",
"freebsd/386", "freebsd/amd64", "freebsd/arm", "freebsd/arm64",
"openbsd/386", "openbsd/amd64", "openbsd/arm", "openbsd/arm64",
"netbsd/386", "netbsd/amd64", "netbsd/arm", "netbsd/arm64",
"android/386", "android/amd64", "android/arm", "android/arm64",
"illumos/amd64",
"solaris/amd64",
"linux/ppc64le", "linux/riscv64", "linux/s390x":
return true
}
return false
}