summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmake/rules/go/env/xmake.lua23
1 files changed, 22 insertions, 1 deletions
diff --git a/xmake/rules/go/env/xmake.lua b/xmake/rules/go/env/xmake.lua
index c2c9ca4a0..2bbd40d8b 100644
--- a/xmake/rules/go/env/xmake.lua
+++ b/xmake/rules/go/env/xmake.lua
@@ -20,15 +20,21 @@
rule("go.env")
on_load(function (target)
+
+ -- imports
import("private.tools.go.goenv")
import("private.async.runjobs")
import("core.base.tty")
import("core.base.option")
+ import("core.project.config")
+
+ -- check and install go packages for other platform
local goroot = goenv.GOROOT()
local goos = goenv.GOOS(target:plat())
local goarch = goenv.GOARCH(target:arch())
if goroot and goos and goarch then
- local gopkgdir = path.join(goroot, "pkg", goos .. "_" .. goarch)
+ local goroot_local = path.join(config.buildir(), ".goenv", path.filename(goroot))
+ local gopkgdir = path.join(os.isdir(goroot_local) and goroot_local or goroot, "pkg", goos .. "_" .. goarch)
if not os.isdir(gopkgdir) or os.emptydir(gopkgdir) then
local gosrcdir = path.join(goroot, "src")
local confirm = utils.confirm({default = true, description = ("we need build go for %s_%s only once first!"):format(goos, goarch)})
@@ -40,6 +46,14 @@ rule("go.env")
if is_host("windows") then
os.vrunv(path.join(gosrcdir, "make.bat"), {"--no-clean"}, {envs = {GOOS = goos, GOARCH = goarch, GOROOT_BOOTSTRAP = goroot}, curdir = gosrcdir})
else
+
+ -- we need copy goroot to the local directory to solving permission problem
+ if is_host("linux") then
+ os.vcp(goroot, goroot_local)
+ goroot = path.absolute(goroot_local)
+ gosrcdir = path.absolute(path.join(goroot_local, "src"))
+ end
+
-- we patch '/' to GOROOT_BOOTSTRAP to solve the following issue
--
-- in make.bash
@@ -58,5 +72,12 @@ rule("go.env")
end
end
end
+
+ -- switch to the local go root directory
+ if os.isdir(goroot_local) and os.isdir(gopkgdir) and not os.emptydir(gopkgdir) then
+ config.set("gc", path.join(goroot_local, "bin", "go"), {readonly = true, force = true})
+ config.set("gcld", path.join(goroot_local, "bin", "go"), {readonly = true, force = true})
+ config.set("gcar", path.join(goroot_local, "bin", "go"), {readonly = true, force = true})
+ end
end
end)