summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-03-29 22:24:46 +0800
committerruki <[email protected]>2025-04-08 15:31:56 +0800
commit4b47fa99489e59337b056e0c95b50493c050fe32 (patch)
tree848a747075f30c8848571c5d4dd79272d051b2ad
parentb8b1f389c02bdb5521699e73622ea674d676fa90 (diff)
improve to build object to support jobgraph
-rw-r--r--xmake/modules/private/action/build/object.lua27
-rw-r--r--xmake/rules/c++/xmake.lua4
2 files changed, 27 insertions, 4 deletions
diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua
index ae6bf9f4a..8f71f4b68 100644
--- a/xmake/modules/private/action/build/object.lua
+++ b/xmake/modules/private/action/build/object.lua
@@ -143,8 +143,8 @@ function build(target, sourcebatch, opt)
end
end
--- add batch jobs to build the source files
-function main(target, batchjobs, sourcebatch, opt)
+-- add build jobs to batchjobs
+function _add_batchjobs(target, batchjobs, sourcebatch, opt)
local rootjob = opt.rootjob
for i = 1, #sourcebatch.sourcefiles do
local sourcefile = sourcebatch.sourcefiles[i]
@@ -157,3 +157,26 @@ function main(target, batchjobs, sourcebatch, opt)
end, {rootjob = rootjob, distcc = opt.distcc})
end
end
+
+-- add build jobs to jobgraph
+function _add_jobgraph(target, jobgraph, sourcebatch, opt)
+ for i = 1, #sourcebatch.sourcefiles do
+ local sourcefile = sourcebatch.sourcefiles[i]
+ local objectfile = sourcebatch.objectfiles[i]
+ local dependfile = sourcebatch.dependfiles[i]
+ local sourcekind = assert(sourcebatch.sourcekind, "%s: sourcekind not found!", sourcefile)
+ local jobname = target:fullname() .. "/" .. sourcefile
+ jobgraph:add(jobname, function (index, total, jobopt)
+ local build_opt = table.join({objectfile = objectfile, dependfile = dependfile, sourcekind = sourcekind, progress = jobopt.progress}, opt)
+ build_object(target, sourcefile, build_opt)
+ end, {distcc = opt.distcc})
+ end
+end
+
+function main(target, jobs, sourcebatch, opt)
+ if jobs.add_orders then
+ _add_jobgraph(target, jobs, sourcebatch, opt)
+ else
+ _add_batchjobs(target, jobs, sourcebatch, opt)
+ end
+end
diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua
index 94bba431e..abe6cf334 100644
--- a/xmake/rules/c++/xmake.lua
+++ b/xmake/rules/c++/xmake.lua
@@ -21,7 +21,7 @@
rule("c.build")
set_sourcekinds("cc")
add_deps("c.build.pcheader", "c.build.optimization", "c.build.sanitizer")
- on_build_files("private.action.build.object", {batch = true, distcc = true})
+ on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true})
on_config(function (target)
-- enable vs runtime as MD by default
if target:is_plat("windows") and not target:get("runtimes") then
@@ -43,7 +43,7 @@ rule("c.build")
rule("c++.build")
set_sourcekinds("cxx")
add_deps("c++.build.pcheader", "c++.build.modules", "c++.build.optimization", "c++.build.sanitizer")
- on_build_files("private.action.build.object", {batch = true, distcc = true})
+ on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true})
on_config(function (target)
-- enable c++ exceptions by default
if target:is_plat("windows") and not target:get("exceptions") then