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/modules/private/tools/go | |
| parent | 6d803e27d205bc7282597ac4db2a105f2a79d5ad (diff) | |
rewrite golang support
Diffstat (limited to 'xmake/modules/private/tools/go')
| -rw-r--r-- | xmake/modules/private/tools/go/goenv.lua | 84 |
1 files changed, 73 insertions, 11 deletions
diff --git a/xmake/modules/private/tools/go/goenv.lua b/xmake/modules/private/tools/go/goenv.lua index 278146a6c..1a448e6f3 100644 --- a/xmake/modules/private/tools/go/goenv.lua +++ b/xmake/modules/private/tools/go/goenv.lua @@ -21,26 +21,88 @@ -- imports import("lib.detect.find_tool") +-- Map xmake platform to Go OS function GOOS(plat) - local goos - if plat == "windows" or plat == "mingw" or plat == "msys" or plat == "cygwin" then - goos = "windows" - elseif plat == "linux" then - goos = "linux" - elseif plat == "macosx" then - goos = "darwin" - end - return goos + local goos_map = { + windows = "windows", + mingw = "windows", + msys = "windows", + cygwin = "windows", + linux = "linux", + macosx = "darwin", + android = "android", + ios = "ios", + freebsd = "freebsd", + netbsd = "netbsd", + openbsd = "openbsd", + dragonfly = "dragonfly", + solaris = "solaris", + aix = "aix", + plan9 = "plan9" + } + return goos_map[plat] end +-- Map xmake architecture to Go architecture function GOARCH(arch) - return (arch == "x86" or arch == "i386") and "386" or "amd64" + local goarch_map = { + x86 = "386", + i386 = "386", + x64 = "amd64", + x86_64 = "amd64", + amd64 = "amd64", + arm = "arm", + armv7 = "arm", + armv7s = "arm", + arm64 = "arm64", + aarch64 = "arm64", + mips = "mips", + mips64 = "mips64", + mips64le = "mips64le", + mipsle = "mipsle", + ppc = "ppc", + ppc64 = "ppc64", + ppc64le = "ppc64le", + riscv64 = "riscv64", + s390x = "s390x", + wasm = "wasm" + } + + -- try direct match first + if goarch_map[arch] then + return goarch_map[arch] + end + + -- try pattern matching for arm variants + if arch:match("^arm") then + if arch:match("64") or arch:match("aarch64") then + return "arm64" + else + return "arm" + end + end + + -- try pattern matching for x86 variants + if arch:match("^x86") or arch:match("^i386") or arch:match("^i686") then + return "386" + end + + if arch:match("^x64") or arch:match("^amd64") or arch:match("^x86_64") then + return "amd64" + end + + return nil end +-- Get GOROOT from Go installation function GOROOT(toolchain) local go = find_tool("go") if go then - local gorootdir = try { function() return os.iorunv(go.program, {"env", "GOROOT"}) end } + local gorootdir = try { + function() + return os.iorunv(go.program, {"env", "GOROOT"}, {envs = toolchain and toolchain:get("runenvs") or nil}) + end + } if gorootdir then return gorootdir:trim() end |
