refactor: use go:linkname to link internal/platform.CgoSupported
Instead of creating a custom platform package, use the go:linkname directive to directly link to Go's standard library internal/platform.CgoSupported function. This approach: - Eliminates the need to maintain a copy of platform support data - Uses Go's canonical platform information directly - Reduces code duplication and maintenance burden - Follows Go's linkname pattern for accessing internal packages Changes: - Added import _ "unsafe" to enable linkname - Added //go:linkname directive for cgoSupported function - Removed custom runtime/internal/lib/internal/platform package - Updated function call from platform.CgoSupported to cgoSupported 🤖 Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <luoliwoshang@users.noreply.github.com>
This commit is contained in:
@@ -14,8 +14,7 @@ import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/goplus/llgo/runtime/internal/lib/internal/platform"
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
// Type aliases to reference standard library types
|
||||
@@ -79,7 +78,7 @@ func defaultContext() Context {
|
||||
c.CgoEnabled = false
|
||||
default:
|
||||
if runtime.GOARCH == c.GOARCH && runtime.GOOS == c.GOOS {
|
||||
c.CgoEnabled = platform.CgoSupported(c.GOOS, c.GOARCH)
|
||||
c.CgoEnabled = cgoSupported(c.GOOS, c.GOARCH)
|
||||
break
|
||||
}
|
||||
c.CgoEnabled = false
|
||||
@@ -122,3 +121,6 @@ func buildToolTags() []string {
|
||||
"goexperiment.boringcrypto", // Default boring crypto experiment
|
||||
}
|
||||
}
|
||||
|
||||
//go:linkname cgoSupported internal/platform.CgoSupported
|
||||
func cgoSupported(goos, goarch string) bool
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
// 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{}
|
||||
|
||||
// An OSArch is a pair of GOOS and GOARCH values indicating a platform.
|
||||
type OSArch struct {
|
||||
GOOS, GOARCH string
|
||||
}
|
||||
|
||||
func (p OSArch) String() string {
|
||||
return p.GOOS + "/" + p.GOARCH
|
||||
}
|
||||
|
||||
// osArchInfo describes information about an OSArch.
|
||||
type osArchInfo struct {
|
||||
CgoSupported bool
|
||||
FirstClass bool
|
||||
Broken bool
|
||||
}
|
||||
|
||||
// distInfo maps OSArch to information about cgo support.
|
||||
// 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