refactor: follow Go stdlib conventions for build.go

- Created internal/buildcfg package with DefaultCGO_ENABLED constant
- Updated CGO_ENABLED handling to use buildcfg.DefaultCGO_ENABLED
- Added original Go stdlib comment for release tags
- Simplified toolTags usage by using it directly instead of wrapper function

🤖 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 10:39:14 +00:00
parent 946a4bf990
commit ee49fad4a4
2 changed files with 19 additions and 6 deletions

View File

@@ -15,6 +15,8 @@ import (
"strconv" "strconv"
"strings" "strings"
_ "unsafe" _ "unsafe"
"github.com/goplus/llgo/runtime/internal/lib/internal/buildcfg"
) )
// Type aliases to reference standard library types // Type aliases to reference standard library types
@@ -77,10 +79,13 @@ func defaultContext() Context {
c.GOPATH = envOr("GOPATH", defaultGOPATH()) c.GOPATH = envOr("GOPATH", defaultGOPATH())
// LLGO PATCH: Use "gc" instead of runtime.Compiler to avoid "unknown compiler" error // LLGO PATCH: Use "gc" instead of runtime.Compiler to avoid "unknown compiler" error
c.Compiler = "gc" c.Compiler = "gc"
c.ToolTags = append(c.ToolTags, buildToolTags()...) c.ToolTags = append(c.ToolTags, toolTags...)
defaultToolTags = append([]string{}, c.ToolTags...) defaultToolTags = append([]string{}, c.ToolTags...)
// Each major Go release in the Go 1.x series adds a new
// "go1.x" release tag. That is, the go1.x tag is present in
// all releases >= Go 1.x.
goVersion := parseGoVersion() goVersion := parseGoVersion()
for i := 1; i <= goVersion; i++ { for i := 1; i <= goVersion; i++ {
c.ReleaseTags = append(c.ReleaseTags, "go1."+strconv.Itoa(i)) c.ReleaseTags = append(c.ReleaseTags, "go1."+strconv.Itoa(i))
@@ -90,7 +95,7 @@ func defaultContext() Context {
env := os.Getenv("CGO_ENABLED") env := os.Getenv("CGO_ENABLED")
if env == "" { if env == "" {
env = "1" env = buildcfg.DefaultCGO_ENABLED
} }
switch env { switch env {
case "1": case "1":
@@ -133,7 +138,3 @@ func defaultGOPATH() string {
return "" return ""
} }
// buildToolTags returns the tool tags for the current build configuration.
func buildToolTags() []string {
return toolTags
}

View File

@@ -0,0 +1,12 @@
// 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 buildcfg
// llgo:skipall
type _buildcfg struct{}
// DefaultCGO_ENABLED is the default value for CGO_ENABLED
// when the environment variable is not set.
const DefaultCGO_ENABLED = "1"