refactor: simplify go/build patch - use build.Default directly

Remove unnecessary go:linkname, runtime import, and unsafe import.
Access build.Default.Compiler directly instead of via linkname.

- Removed go:linkname directive
- Removed runtime and unsafe imports
- Removed unnecessary _ = runtime.Compiler line
- Simplified from 27 lines to 19 lines
- Same functionality, cleaner code

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 13:28:54 +00:00
parent 6e41cc702f
commit 420ad8e010

View File

@@ -9,19 +9,11 @@ package build
import (
"go/build"
"runtime"
_ "unsafe"
)
//go:linkname buildDefault go/build.Default
var buildDefault build.Context
func init() {
// LLGO PATCH: Override build.Default.Compiler to be "gc" instead of "llgo"
// This prevents "unknown compiler" errors when user code uses go/build package
// Even though runtime.Compiler = "llgo", we set build.Default.Compiler = "gc"
buildDefault.Compiler = "gc"
// Verify that runtime.Compiler is still "llgo" (unchanged)
_ = runtime.Compiler
build.Default.Compiler = "gc"
}