diff --git a/runtime/internal/lib/go/build/build.go b/runtime/internal/lib/go/build/build.go index f39fc8bb..dc778edb 100644 --- a/runtime/internal/lib/go/build/build.go +++ b/runtime/internal/lib/go/build/build.go @@ -15,6 +15,8 @@ import ( "strconv" "strings" _ "unsafe" + + "github.com/goplus/llgo/runtime/internal/lib/internal/buildcfg" ) // Type aliases to reference standard library types @@ -77,10 +79,13 @@ func defaultContext() Context { c.GOPATH = envOr("GOPATH", defaultGOPATH()) // LLGO PATCH: Use "gc" instead of runtime.Compiler to avoid "unknown compiler" error c.Compiler = "gc" - c.ToolTags = append(c.ToolTags, buildToolTags()...) + c.ToolTags = append(c.ToolTags, 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() for i := 1; i <= goVersion; i++ { c.ReleaseTags = append(c.ReleaseTags, "go1."+strconv.Itoa(i)) @@ -90,7 +95,7 @@ func defaultContext() Context { env := os.Getenv("CGO_ENABLED") if env == "" { - env = "1" + env = buildcfg.DefaultCGO_ENABLED } switch env { case "1": @@ -133,7 +138,3 @@ func defaultGOPATH() string { return "" } -// buildToolTags returns the tool tags for the current build configuration. -func buildToolTags() []string { - return toolTags -} diff --git a/runtime/internal/lib/internal/buildcfg/buildcfg.go b/runtime/internal/lib/internal/buildcfg/buildcfg.go new file mode 100644 index 00000000..88d78b00 --- /dev/null +++ b/runtime/internal/lib/internal/buildcfg/buildcfg.go @@ -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"