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:
@@ -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
|
|
||||||
}
|
|
||||||
|
|||||||
12
runtime/internal/lib/internal/buildcfg/buildcfg.go
Normal file
12
runtime/internal/lib/internal/buildcfg/buildcfg.go
Normal 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"
|
||||||
Reference in New Issue
Block a user