2025-10-15 12:33:48 +00:00
|
|
|
// Copyright 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
2025-10-15 11:58:36 +00:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
2025-10-15 12:33:48 +00:00
|
|
|
// Minimal overlay for go/build package.
|
|
|
|
|
// This file contains only the patched defaultContext function.
|
|
|
|
|
|
2025-10-15 11:58:36 +00:00
|
|
|
package build
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"internal/buildcfg"
|
|
|
|
|
"internal/goversion"
|
|
|
|
|
"internal/platform"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"runtime"
|
|
|
|
|
"strconv"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var defaultToolTags []string
|
|
|
|
|
var defaultReleaseTags []string
|
|
|
|
|
|
|
|
|
|
func defaultContext() Context {
|
|
|
|
|
var c Context
|
|
|
|
|
|
|
|
|
|
c.GOARCH = buildcfg.GOARCH
|
|
|
|
|
c.GOOS = buildcfg.GOOS
|
|
|
|
|
if goroot := runtime.GOROOT(); goroot != "" {
|
|
|
|
|
c.GOROOT = filepath.Clean(goroot)
|
|
|
|
|
}
|
|
|
|
|
c.GOPATH = envOr("GOPATH", defaultGOPATH())
|
2025-10-15 12:33:48 +00:00
|
|
|
// LLGO PATCH: Use "gc" instead of runtime.Compiler to avoid "unknown compiler" error
|
2025-10-15 11:58:36 +00:00
|
|
|
c.Compiler = "gc"
|
|
|
|
|
c.ToolTags = append(c.ToolTags, buildcfg.ToolTags...)
|
|
|
|
|
|
2025-10-15 12:33:48 +00:00
|
|
|
defaultToolTags = append([]string{}, c.ToolTags...)
|
2025-10-15 11:58:36 +00:00
|
|
|
|
|
|
|
|
for i := 1; i <= goversion.Version; i++ {
|
|
|
|
|
c.ReleaseTags = append(c.ReleaseTags, "go1."+strconv.Itoa(i))
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-15 12:33:48 +00:00
|
|
|
defaultReleaseTags = append([]string{}, c.ReleaseTags...)
|
2025-10-15 11:58:36 +00:00
|
|
|
|
|
|
|
|
env := os.Getenv("CGO_ENABLED")
|
|
|
|
|
if env == "" {
|
2025-10-15 12:33:48 +00:00
|
|
|
env = "1"
|
2025-10-15 11:58:36 +00:00
|
|
|
}
|
|
|
|
|
switch env {
|
|
|
|
|
case "1":
|
|
|
|
|
c.CgoEnabled = true
|
|
|
|
|
case "0":
|
|
|
|
|
c.CgoEnabled = false
|
|
|
|
|
default:
|
|
|
|
|
if runtime.GOARCH == c.GOARCH && runtime.GOOS == c.GOOS {
|
|
|
|
|
c.CgoEnabled = platform.CgoSupported(c.GOOS, c.GOARCH)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
c.CgoEnabled = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func envOr(name, def string) string {
|
|
|
|
|
s := os.Getenv(name)
|
|
|
|
|
if s == "" {
|
|
|
|
|
return def
|
|
|
|
|
}
|
|
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-15 12:33:48 +00:00
|
|
|
func defaultGOPATH() string {
|
|
|
|
|
env := "HOME"
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
env = "USERPROFILE"
|
|
|
|
|
} else if runtime.GOOS == "plan9" {
|
|
|
|
|
env = "home"
|
2025-10-15 11:58:36 +00:00
|
|
|
}
|
2025-10-15 12:33:48 +00:00
|
|
|
if home := os.Getenv(env); home != "" {
|
|
|
|
|
def := filepath.Join(home, "go")
|
|
|
|
|
if filepath.Clean(def) == filepath.Clean(runtime.GOROOT()) {
|
|
|
|
|
return ""
|
2025-10-15 11:58:36 +00:00
|
|
|
}
|
2025-10-15 12:33:48 +00:00
|
|
|
return def
|
2025-10-15 11:58:36 +00:00
|
|
|
}
|
2025-10-15 12:33:48 +00:00
|
|
|
return ""
|
2025-10-15 11:58:36 +00:00
|
|
|
}
|