summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-07-19 12:58:57 +0800
committerruki <[email protected]>2020-07-19 12:58:57 +0800
commit4ef022737b74da6e2c2e2a351424dd281ea7cf0c (patch)
tree29771c2bc94454ef8707c86aba350bf592120654
parent5bcf2414231f41c96be8ba8403a17b679c18af59 (diff)
add goos and goarch
-rw-r--r--xmake/modules/core/tools/go.lua6
-rw-r--r--xmake/toolchains/go/xmake.lua19
2 files changed, 23 insertions, 2 deletions
diff --git a/xmake/modules/core/tools/go.lua b/xmake/modules/core/tools/go.lua
index 80230ba4f..b62ad4e22 100644
--- a/xmake/modules/core/tools/go.lua
+++ b/xmake/modules/core/tools/go.lua
@@ -106,7 +106,8 @@ function link(self, objectfiles, targetkind, targetfile, flags)
os.mkdir(path.directory(targetfile))
-- link it
- os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags))
+ local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags)
+ os.runv(program, argv, {envs = self:runenvs()})
end
-- make the compile arguments list
@@ -121,6 +122,7 @@ function compile(self, sourcefiles, objectfile, dependinfo, flags)
os.mkdir(path.directory(objectfile))
-- compile it
- os.runv(compargv(self, sourcefiles, objectfile, flags))
+ local program, argv = compargv(self, sourcefiles, objectfile, flags)
+ os.runv(program, argv, {envs = self:runenvs()})
end
diff --git a/xmake/toolchains/go/xmake.lua b/xmake/toolchains/go/xmake.lua
index 39c253b57..60fed9041 100644
--- a/xmake/toolchains/go/xmake.lua
+++ b/xmake/toolchains/go/xmake.lua
@@ -32,6 +32,25 @@ toolchain("go")
-- on load
on_load(function (toolchain)
+ if not toolchain:is_plat(os.host()) or not toolchain:is_arch(os.arch()) then
+ local goos, goarch
+ if toolchain:is_plat("windows", "mingw", "msys", "cygwin") then
+ goos = "windows"
+ goarch = toolchain:is_arch("x64", "x86_64") and "amd64" or "386"
+ elseif toolchain:is_plat("linux") then
+ goos = "linux"
+ goarch = toolchain:is_arch("x86_64") and "amd64" or "386"
+ elseif toolchain:is_plat("macosx") then
+ goos = "darwin"
+ goarch = toolchain:is_arch("x86_64") and "amd64" or "386"
+ end
+ if goos then
+ toolchain:add("runenvs", "GOOS", goos)
+ end
+ if goarch then
+ toolchain:add("runenvs", "GOARCH", goarch)
+ end
+ end
toolchain:set("gcldflags", "")
end)