From c4fdb1edc016dc8625137b39c5d9fd58aa2573a6 Mon Sep 17 00:00:00 2001 From: xgopilot Date: Thu, 16 Oct 2025 04:05:58 +0000 Subject: [PATCH] refactor: move cgoSupported to internal/platform package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- runtime/internal/lib/go/build/build.go | 24 ++------------- .../lib/internal/platform/platform.go | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 runtime/internal/lib/internal/platform/platform.go diff --git a/runtime/internal/lib/go/build/build.go b/runtime/internal/lib/go/build/build.go index 676108bc..65afc07f 100644 --- a/runtime/internal/lib/go/build/build.go +++ b/runtime/internal/lib/go/build/build.go @@ -14,6 +14,8 @@ import ( "runtime" "strconv" "strings" + + "github.com/goplus/llgo/runtime/internal/lib/internal/platform" ) // Type aliases to reference standard library types @@ -77,7 +79,7 @@ func defaultContext() Context { c.CgoEnabled = false default: 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 } c.CgoEnabled = false @@ -120,23 +122,3 @@ func buildToolTags() []string { "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 -} diff --git a/runtime/internal/lib/internal/platform/platform.go b/runtime/internal/lib/internal/platform/platform.go new file mode 100644 index 00000000..7db203bf --- /dev/null +++ b/runtime/internal/lib/internal/platform/platform.go @@ -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 +}