diff options
| author | ruki <[email protected]> | 2025-12-05 22:36:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-05 22:36:39 +0800 |
| commit | e688a7bd853c49ec10aa8656e704c2115ea5e14c (patch) | |
| tree | ea514a602e65bec18b18e4037df605357bd95443 /xmake/toolchains/go/xmake.lua | |
| parent | 6d803e27d205bc7282597ac4db2a105f2a79d5ad (diff) | |
rewrite golang support
Diffstat (limited to 'xmake/toolchains/go/xmake.lua')
| -rw-r--r-- | xmake/toolchains/go/xmake.lua | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/xmake/toolchains/go/xmake.lua b/xmake/toolchains/go/xmake.lua index 69c06e3e0..d12fe0dc2 100644 --- a/xmake/toolchains/go/xmake.lua +++ b/xmake/toolchains/go/xmake.lua @@ -26,23 +26,48 @@ toolchain("go") set_description("Go Programming Language Compiler") -- set toolset - set_toolset("gc", "$(env GC)", "go", "gccgo") - set_toolset("gcld", "$(env GC)", "go", "gccgo") - set_toolset("gcar", "$(env GC)", "go", "gccgo") + -- Modern Go uses "go" command for all operations + set_toolset("gc", "$(env GC)", "go") + set_toolset("gcld", "$(env GC)", "go") + set_toolset("gcar", "$(env GC)", "go") -- on load on_load(function (toolchain) - if not toolchain:is_plat(os.host()) or not toolchain:is_arch(os.arch()) then - import("private.tools.go.goenv") - local goos = goenv.GOOS(toolchain:plat()) - if goos then - toolchain:add("runenvs", "GOOS", goos) - end - local goarch = goenv.GOARCH(toolchain:arch()) - if goarch then - toolchain:add("runenvs", "GOARCH", goarch) + import("private.tools.go.goenv") + + -- set GOOS and GOARCH for cross-compilation + local goos = goenv.GOOS(toolchain:plat()) + if goos then + toolchain:add("runenvs", "GOOS", goos) + end + + local goarch = goenv.GOARCH(toolchain:arch()) + if goarch then + toolchain:add("runenvs", "GOARCH", goarch) + end + + -- Set CGO_ENABLED=0 by default for better cross-compilation support + -- Users can override this if they need CGO + if not os.getenv("CGO_ENABLED") then + toolchain:add("runenvs", "CGO_ENABLED", "0") + end + + -- Disable Go modules mode to use GOPATH mode + -- This allows Go to find packages using GOPATH + if not os.getenv("GO111MODULE") then + toolchain:add("runenvs", "GO111MODULE", "off") + end + + -- Set GOPATH to project directory if not already set + -- This allows Go to find packages in the project + if not os.getenv("GOPATH") then + local projectdir = os.projectdir() + if projectdir then + toolchain:add("runenvs", "GOPATH", projectdir) end end + + -- set default flags toolchain:set("gcldflags", "") + toolchain:set("gcarflags", "") end) - |
