revert: restore full overlay approach for go/build
After investigating the hasAltPkg mechanism, determined that it's not suitable for go/build.defaultContext() because: 1. hasAltPkg works well for providing additional/alternative functions 2. But defaultContext() needs to REPLACE an existing function that depends on internal/buildcfg, internal/goversion, and internal/platform 3. These internal packages cannot be imported from runtime/internal/lib The full overlay approach (2073 lines) works correctly. Seeking guidance on whether this is acceptable or if there's an alternative approach. Demo verified working: - runtime.Compiler = "llgo" - go/build.Import() works correctly - No "unknown compiler" error Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <luoliwoshang@users.noreply.github.com>
This commit is contained in:
2073
runtime/_overlay/go/build/build.go
Normal file
2073
runtime/_overlay/go/build/build.go
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,87 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
// Minimal overlay for go/build package.
|
|
||||||
// This file contains only the patched defaultContext function.
|
|
||||||
|
|
||||||
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())
|
|
||||||
// LLGO PATCH: Use "gc" instead of runtime.Compiler to avoid "unknown compiler" error
|
|
||||||
c.Compiler = "gc"
|
|
||||||
c.ToolTags = append(c.ToolTags, buildcfg.ToolTags...)
|
|
||||||
|
|
||||||
defaultToolTags = append([]string{}, c.ToolTags...)
|
|
||||||
|
|
||||||
for i := 1; i <= goversion.Version; i++ {
|
|
||||||
c.ReleaseTags = append(c.ReleaseTags, "go1."+strconv.Itoa(i))
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultReleaseTags = append([]string{}, c.ReleaseTags...)
|
|
||||||
|
|
||||||
env := os.Getenv("CGO_ENABLED")
|
|
||||||
if env == "" {
|
|
||||||
env = "1"
|
|
||||||
}
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultGOPATH() string {
|
|
||||||
env := "HOME"
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
env = "USERPROFILE"
|
|
||||||
} else if runtime.GOOS == "plan9" {
|
|
||||||
env = "home"
|
|
||||||
}
|
|
||||||
if home := os.Getenv(env); home != "" {
|
|
||||||
def := filepath.Join(home, "go")
|
|
||||||
if filepath.Clean(def) == filepath.Clean(runtime.GOROOT()) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,7 @@ var testing_testing_go124 string
|
|||||||
//go:embed _overlay/net/textproto/textproto.go
|
//go:embed _overlay/net/textproto/textproto.go
|
||||||
var net_textproto string
|
var net_textproto string
|
||||||
|
|
||||||
//go:embed internal/go/build/build.go
|
//go:embed _overlay/go/build/build.go
|
||||||
var go_build_build string
|
var go_build_build string
|
||||||
|
|
||||||
var OverlayFiles = map[string]string{
|
var OverlayFiles = map[string]string{
|
||||||
|
|||||||
Reference in New Issue
Block a user