summaryrefslogtreecommitdiff
path: root/xmake/rules
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-05 22:36:39 +0800
committerruki <[email protected]>2025-12-05 22:36:39 +0800
commite688a7bd853c49ec10aa8656e704c2115ea5e14c (patch)
treeea514a602e65bec18b18e4037df605357bd95443 /xmake/rules
parent6d803e27d205bc7282597ac4db2a105f2a79d5ad (diff)
rewrite golang support
Diffstat (limited to 'xmake/rules')
-rw-r--r--xmake/rules/go/build/object.lua84
-rw-r--r--xmake/rules/go/env/xmake.lua83
-rw-r--r--xmake/rules/go/xmake.lua3
3 files changed, 1 insertions, 169 deletions
diff --git a/xmake/rules/go/build/object.lua b/xmake/rules/go/build/object.lua
deleted file mode 100644
index f9f1ccee4..000000000
--- a/xmake/rules/go/build/object.lua
+++ /dev/null
@@ -1,84 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
--- Copyright (C) 2015-present, Xmake Open Source Community.
---
--- @author ruki
--- @file object.lua
---
-
--- imports
-import("core.base.option")
-import("core.base.hashset")
-import("core.tool.compiler")
-import("core.project.depend")
-import("utils.progress")
-
--- build the source files
-function main(target, sourcebatch, opt)
-
- -- get source files and kind
- local sourcefiles = sourcebatch.sourcefiles
- local sourcekind = sourcebatch.sourcekind
-
- -- get object file
- local objectfile = target:objectfile(path.join(path.directory(sourcefiles[1]), "__go__"))
-
- -- get depend file
- local dependfile = target:dependfile(objectfile)
-
- -- remove the object files in sourcebatch
- local objectfiles_set = hashset.from(sourcebatch.objectfiles)
- for idx, file in irpairs(target:objectfiles()) do
- if objectfiles_set:has(file) then
- table.remove(target:objectfiles(), idx)
- end
- end
-
- -- add object file
- table.insert(target:objectfiles(), objectfile)
-
- -- load compiler
- local compinst = compiler.load(sourcekind, {target = target})
-
- -- get compile flags
- local compflags = compinst:compflags({target = target})
-
- -- load dependent info
- local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
-
- -- need build this object?
- local depvalues = {compinst:program(), compflags}
- if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then
- return
- end
-
- -- trace progress info
- for index, sourcefile in ipairs(sourcefiles) do
- progress.show(opt.progress, "${color.build.object}compiling.$(mode) %s", sourcefile)
- end
-
- -- trace verbose info
- vprint(compinst:compcmd(sourcefiles, objectfile, {compflags = compflags}))
-
- -- compile it
- dependinfo.files = {}
- assert(compinst:compile(sourcefiles, objectfile, {dependinfo = dependinfo, compflags = compflags}))
-
- -- update files and values to the dependent file
- dependinfo.values = depvalues
- table.join2(dependinfo.files, sourcefiles)
- depend.save(dependinfo, dependfile)
-end
-
diff --git a/xmake/rules/go/env/xmake.lua b/xmake/rules/go/env/xmake.lua
deleted file mode 100644
index 5ac24297a..000000000
--- a/xmake/rules/go/env/xmake.lua
+++ /dev/null
@@ -1,83 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
--- Copyright (C) 2015-present, Xmake Open Source Community.
---
--- @author ruki
--- @file xmake.lua
---
-
-rule("go.env")
- on_load(function (target)
-
- -- imports
- import("private.tools.go.goenv")
- import("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 goroot_local = path.join(config.builddir(), ".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 to build go for %s_%s only once first!"):format(goos, goarch)})
- if confirm then
- local build_task = function ()
- tty.erase_line_to_start().cr()
- printf("building go for %s_%s .. ", goos, goarch)
- io.flush()
- 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 to 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
- -- ERROR: $GOROOT_BOOTSTRAP must not be set to $GOROOT
- -- Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.
- --
- os.vrunv(path.join(gosrcdir, "make.bash"), {"--no-clean"}, {envs = {GOOS = goos, GOARCH = goarch, GOROOT_BOOTSTRAP = goroot .. "/"}, curdir = gosrcdir})
- end
- tty.erase_line_to_start().cr()
- cprint("building go for %s_%s .. ${color.success}${text.success}", goos, goarch)
- end
- if option.get("verbose") then
- build_task()
- else
- runjobs("build/goenv", build_task, {waiting_indicator = true})
- 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)
diff --git a/xmake/rules/go/xmake.lua b/xmake/rules/go/xmake.lua
index 18cee3e96..25ab5af56 100644
--- a/xmake/rules/go/xmake.lua
+++ b/xmake/rules/go/xmake.lua
@@ -20,7 +20,6 @@
rule("go.build")
set_sourcekinds("gc")
- add_deps("go.env")
on_load(function (target)
-- we disable to build across targets in parallel, because the source files may depend on other target modules
target:set("policy", "build.fence", true)
@@ -29,7 +28,7 @@ rule("go.build")
target:set("prefixname", "")
end
end)
- on_build_files("build.object")
+ on_build("build.target")
rule("go")