summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-10-04 20:22:19 +0800
committerGitHub <[email protected]>2025-10-04 20:22:19 +0800
commit05525e2450c8af5344bd1ace78d4b532955de76c (patch)
treead35b96ef96c44135e2978695f4df1e2c45f8299
parent3abd796be60f8b5b69a2c61e36d2e67197328359 (diff)
parentd877bfa5f10301d59d0cf0b15246612e277e8d81 (diff)
Merge pull request #6886 from xmake-io/opti
Decrease jobs count in jobgraph
-rw-r--r--tests/benchmarks/build_targets/test.lua94
-rw-r--r--tests/benchmarks/config_targets/test.lua75
-rw-r--r--xmake/core/project/target.lua16
-rw-r--r--xmake/modules/private/action/build/target.lua5
-rw-r--r--xmake/rules/c++/modules/config.lua3
-rw-r--r--xmake/rules/linker/soname/xmake.lua8
-rw-r--r--xmake/rules/utils/merge_archive/xmake.lua4
-rw-r--r--xmake/rules/utils/symbols/extract/xmake.lua5
8 files changed, 145 insertions, 65 deletions
diff --git a/tests/benchmarks/build_targets/test.lua b/tests/benchmarks/build_targets/test.lua
index 0f5124bfa..8660dbe52 100644
--- a/tests/benchmarks/build_targets/test.lua
+++ b/tests/benchmarks/build_targets/test.lua
@@ -1,6 +1,18 @@
import("lib.detect.find_tool")
import("core.tool.toolchain")
+function run_test(func)
+ local dt = os.mclock()
+ local n = 2
+ local delta = 0
+ for i = 1, n do
+ local e = func()
+ delta = delta + e
+ end
+ dt = os.mclock() - dt - delta
+ return math.floor(dt / n)
+end
+
function test_build(t)
if xmake.is_embed() then
@@ -10,29 +22,33 @@ function test_build(t)
local jobs = tostring(os.default_njob())
-- xmake
- os.tryrm("build")
- os.tryrm(".xmake")
- local xmake_dt = os.mclock()
- os.runv("xmake", {"-j" .. jobs})
- xmake_dt = os.mclock() - xmake_dt
+ local xmake_dt = run_test(function()
+ local dt = os.mclock()
+ os.tryrm("build")
+ os.tryrm(".xmake")
+ dt = os.mclock() - dt
+ os.runv("xmake", {"-j" .. jobs})
+ return dt
+ end)
print("build targets/30: xmake: %d ms", xmake_dt)
-- cmake
local cmake = find_tool("cmake")
if cmake then
- os.tryrm("build")
- os.mkdir("build")
- local cmake_default_dt = os.mclock()
- os.runv(cmake.program, {".."}, {curdir = "build"})
- os.runv(cmake.program, {"--build", ".", "-j" .. jobs}, {curdir = "build"})
- cmake_default_dt = os.mclock() - cmake_default_dt
+ local cmake_default_dt = run_test(function()
+ local dt = os.mclock()
+ os.tryrm("build")
+ os.mkdir("build")
+ dt = os.mclock() - dt
+ os.runv(cmake.program, {".."}, {curdir = "build"})
+ os.runv(cmake.program, {"--build", ".", "-j" .. jobs}, {curdir = "build"})
+ return dt
+ end)
print("build targets/30: cmake/default: %d ms", cmake_default_dt)
t:require((cmake_default_dt > xmake_dt) or (cmake_default_dt + 3000 > xmake_dt))
local ninja = find_tool("ninja")
if ninja then
- os.tryrm("build")
- os.mkdir("build")
local configs = {}
local envs
if is_host("windows") then
@@ -44,22 +60,30 @@ function test_build(t)
envs = os.joinenvs(msvc:runenvs())
end
end
- local cmake_ninja_dt = os.mclock()
- os.runv(cmake.program, table.join("..", "-G", "Ninja", configs), {curdir = "build", envs = envs})
- os.runv(cmake.program, {"--build", ".", "-j" .. jobs}, {curdir = "build", envs = envs})
- cmake_ninja_dt = os.mclock() - cmake_ninja_dt
+ local cmake_ninja_dt = run_test(function ()
+ local dt = os.mclock()
+ os.tryrm("build")
+ os.mkdir("build")
+ dt = os.mclock() - dt
+ os.runv(cmake.program, table.join("..", "-G", "Ninja", configs), {curdir = "build", envs = envs})
+ os.runv(cmake.program, {"--build", ".", "-j" .. jobs}, {curdir = "build", envs = envs})
+ return dt
+ end)
print("build targets/30: cmake/ninja: %d ms", cmake_ninja_dt)
t:require((cmake_ninja_dt > xmake_dt) or (cmake_ninja_dt + 3000 > xmake_dt))
end
local make = find_tool("make")
if make and not is_subhost("windows") then
- os.tryrm("build")
- os.mkdir("build")
- local cmake_makefile_dt = os.mclock()
- os.runv(cmake.program, {"..", "-G", "Unix Makefiles"}, {curdir = "build"})
- os.runv(cmake.program, {"--build", ".", "-j" .. jobs}, {curdir = "build"})
- cmake_makefile_dt = os.mclock() - cmake_makefile_dt
+ local cmake_makefile_dt = run_test(function()
+ local dt = os.mclock()
+ os.tryrm("build")
+ os.mkdir("build")
+ dt = os.mclock() - dt
+ os.runv(cmake.program, {"..", "-G", "Unix Makefiles"}, {curdir = "build"})
+ os.runv(cmake.program, {"--build", ".", "-j" .. jobs}, {curdir = "build"})
+ return dt
+ end)
print("build targets/30: cmake/makefile: %d ms", cmake_makefile_dt)
t:require((cmake_makefile_dt > xmake_dt) or (cmake_makefile_dt + 3000 > xmake_dt))
end
@@ -68,18 +92,18 @@ function test_build(t)
-- meson
local meson = find_tool("meson")
if meson then
- os.tryrm("build")
- local meson_setup_dt = os.mclock()
- os.runv(meson.program, {"setup", "build"})
- meson_setup_dt = os.mclock() - meson_setup_dt
-
- -- ccache will cache object files globally, which may affect the results of the second run.
- io.replace("build/build.ninja", "ccache", "")
-
- local meson_build_dt = os.mclock()
- os.runv(meson.program, {"compile", "-j", jobs, "-C", "build"})
- meson_build_dt = os.mclock() - meson_build_dt
- local meson_dt = meson_setup_dt + meson_build_dt
+ local meson_dt = run_test(function()
+ local dt1 = os.mclock()
+ os.tryrm("build")
+ dt1 = os.mclock() - dt1
+ os.runv(meson.program, {"setup", "build"})
+ -- ccache will cache object files globally, which may affect the results of the second run.
+ local dt2 = os.mclock()
+ io.replace("build/build.ninja", "ccache", "")
+ dt2 = os.mclock() - dt2
+ os.runv(meson.program, {"compile", "-j", jobs, "-C", "build"})
+ return dt1 + dt2
+ end)
print("build targets/30: meson: %d ms", meson_dt)
t:require((meson_dt > xmake_dt) or (meson_dt + 3000 > xmake_dt))
end
diff --git a/tests/benchmarks/config_targets/test.lua b/tests/benchmarks/config_targets/test.lua
index d5eb8b227..8eacf2dc1 100644
--- a/tests/benchmarks/config_targets/test.lua
+++ b/tests/benchmarks/config_targets/test.lua
@@ -1,6 +1,18 @@
import("lib.detect.find_tool")
import("core.tool.toolchain")
+function run_test(func)
+ local dt = os.mclock()
+ local n = 2
+ local delta = 0
+ for i = 1, n do
+ local e = func()
+ delta = delta + e
+ end
+ dt = os.mclock() - dt - delta
+ return math.floor(dt / n)
+end
+
function test_config(t)
if xmake.is_embed() then
@@ -8,28 +20,32 @@ function test_config(t)
end
-- xmake
- os.tryrm("build")
- os.tryrm(".xmake")
- local xmake_dt = os.mclock()
- os.runv("xmake", {"config", "-c"})
- xmake_dt = os.mclock() - xmake_dt
+ local xmake_dt = run_test(function ()
+ local dt = os.mclock()
+ os.tryrm("build")
+ os.tryrm(".xmake")
+ dt = os.mclock() - dt
+ os.runv("xmake", {"config", "-c"})
+ return dt
+ end)
print("config targets/1k: xmake: %d ms", xmake_dt)
-- cmake
local cmake = find_tool("cmake")
if cmake then
- os.tryrm("build")
- os.mkdir("build")
- local cmake_default_dt = os.mclock()
- os.runv(cmake.program, {".."}, {curdir = "build"})
- cmake_default_dt = os.mclock() - cmake_default_dt
+ local cmake_default_dt = run_test(function()
+ local dt = os.mclock()
+ os.tryrm("build")
+ os.mkdir("build")
+ dt = os.mclock() - dt
+ os.runv(cmake.program, {".."}, {curdir = "build"})
+ return dt
+ end)
print("config targets/1k: cmake/default: %d ms", cmake_default_dt)
t:require((cmake_default_dt > xmake_dt) or (cmake_default_dt + 2000 > xmake_dt))
local ninja = find_tool("ninja")
if ninja then
- os.tryrm("build")
- os.mkdir("build")
local configs = {}
local envs
if is_host("windows") then
@@ -41,19 +57,27 @@ function test_config(t)
envs = os.joinenvs(msvc:runenvs())
end
end
- local cmake_ninja_dt = os.mclock()
- os.runv(cmake.program, table.join("..", "-G", "Ninja", configs), {curdir = "build", envs = envs})
- cmake_ninja_dt = os.mclock() - cmake_ninja_dt
+ local cmake_ninja_dt = run_test(function()
+ local dt = os.mclock()
+ os.tryrm("build")
+ os.mkdir("build")
+ dt = os.mclock() - dt
+ os.runv(cmake.program, table.join("..", "-G", "Ninja", configs), {curdir = "build", envs = envs})
+ return dt
+ end)
print("config targets/1k: cmake/ninja: %d ms", cmake_ninja_dt)
t:require((cmake_ninja_dt > xmake_dt) or (cmake_ninja_dt + 2000 > xmake_dt))
end
if find_tool("make") and not is_subhost("windows") then
- os.tryrm("build")
- os.mkdir("build")
- local cmake_makefile_dt = os.mclock()
- os.runv(cmake.program, {"..", "-G", "Unix Makefiles"}, {curdir = "build"})
- cmake_makefile_dt = os.mclock() - cmake_makefile_dt
+ local cmake_makefile_dt = run_test(function ()
+ local dt = os.mclock()
+ os.tryrm("build")
+ os.mkdir("build")
+ dt = os.mclock() - dt
+ os.runv(cmake.program, {"..", "-G", "Unix Makefiles"}, {curdir = "build"})
+ return dt
+ end)
print("config targets/1k: cmake/makefile: %d ms", cmake_makefile_dt)
t:require((cmake_makefile_dt > xmake_dt) or (cmake_makefile_dt + 2000 > xmake_dt))
end
@@ -62,10 +86,13 @@ function test_config(t)
-- meson
local meson = find_tool("meson")
if meson then
- os.tryrm("build")
- local meson_dt = os.mclock()
- os.runv(meson.program, {"setup", "build"})
- meson_dt = os.mclock() - meson_dt
+ local meson_dt = run_test(function()
+ local dt = os.mclock()
+ os.tryrm("build")
+ dt = os.mclock() - dt
+ os.runv(meson.program, {"setup", "build"})
+ return dt
+ end)
print("config targets/1k: meson: %d ms", meson_dt)
t:require((meson_dt > xmake_dt) or (meson_dt + 2000 > xmake_dt))
end
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 3839eb01f..2f69abdd8 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -1184,6 +1184,22 @@ function _instance:rule_add(r)
self._ORDERULES = nil
end
+-- enable or disable rule
+function _instance:rule_enable(name, enabled)
+ local ruleinst = self:rule(name)
+ if ruleinst then
+ self:data_set("__rule_enabled." .. name, enabled)
+ else
+ utils.warning("target(%s): rule(%s) not found", self:name(), name)
+ end
+end
+
+-- the given rule is enabled or disabled?
+function _instance:rule_is_enabled(name)
+ local enabled = self:data("__rule_enabled." .. name)
+ return enabled ~= false
+end
+
-- is phony target?
function _instance:is_phony()
local targetkind = self:kind()
diff --git a/xmake/modules/private/action/build/target.lua b/xmake/modules/private/action/build/target.lua
index 6c651b68e..c8a7987d5 100644
--- a/xmake/modules/private/action/build/target.lua
+++ b/xmake/modules/private/action/build/target.lua
@@ -235,7 +235,7 @@ function add_targetjobs_with_stage(jobgraph, target, stage, opt)
local instances = {target}
for _, ruleinst in ipairs(target:orderules()) do
-- we only ignore some builtin rules, so we need not to use fullname.
- if not ignored_rules or not ignored_rules:has(ruleinst:name()) then
+ if target:rule_is_enabled(ruleinst:fullname()) and (not ignored_rules or not ignored_rules:has(ruleinst:name())) then
table.insert(instances, ruleinst)
end
end
@@ -262,6 +262,7 @@ function add_targetjobs_with_stage(jobgraph, target, stage, opt)
has_script = true
end
end)
+
-- if custom target.on_build/prepare exists, we need to ignore all scripts in rules
if has_script and instance == target and stage == "" then
break
@@ -571,7 +572,7 @@ function add_filejobs_with_stage(jobgraph, target, sourcebatches, stage, opt)
if rulename then
-- we only ignore some builtin rules, so we need not to use fullname.
local ruleinst = rule_utils.get_rule(target, rulename)
- if not ignored_rules or not ignored_rules:has(ruleinst:name()) then
+ if target:rule_is_enabled(ruleinst:fullname()) and (not ignored_rules or not ignored_rules:has(ruleinst:name())) then
sourcebatches_map[ruleinst] = sourcebatch
-- avoid duplicate scripts being called twice in the target,
-- we just build sourcebatch with on_build_files scripts
diff --git a/xmake/rules/c++/modules/config.lua b/xmake/rules/c++/modules/config.lua
index 30f2f2680..25d85bf0e 100644
--- a/xmake/rules/c++/modules/config.lua
+++ b/xmake/rules/c++/modules/config.lua
@@ -86,6 +86,9 @@ function main(target)
end
end
end
+ else
+ target:rule_enable("c++.build.modules.scanner", false)
+ target:rule_enable("c++.build.modules.builder", false)
end
end
diff --git a/xmake/rules/linker/soname/xmake.lua b/xmake/rules/linker/soname/xmake.lua
index 9f4da3e6a..16cc4271d 100644
--- a/xmake/rules/linker/soname/xmake.lua
+++ b/xmake/rules/linker/soname/xmake.lua
@@ -20,6 +20,7 @@
rule("linker.soname")
on_config(function (target)
+ local enabled = false
local soname = target:soname()
if target:is_shared() and soname then
if target:has_tool("sh", "gcc", "gxx", "clang", "clangxx") then
@@ -28,15 +29,18 @@ rule("linker.soname")
else
target:add("shflags", "-Wl,-soname," .. soname, {force = true})
end
- target:data_set("soname.enabled", true)
+ enabled = true
end
end
+ if not enabled then
+ target:rule_enable("linker.soname", false)
+ end
end)
after_link(function (target)
import("core.project.depend")
local soname = target:soname()
- if target:is_shared() and soname and target:data("soname.enabled") then
+ if target:is_shared() and soname then
local version = target:version()
local filename = target:filename()
local extension = path.extension(filename)
diff --git a/xmake/rules/utils/merge_archive/xmake.lua b/xmake/rules/utils/merge_archive/xmake.lua
index 20ef3c264..ad5039a89 100644
--- a/xmake/rules/utils/merge_archive/xmake.lua
+++ b/xmake/rules/utils/merge_archive/xmake.lua
@@ -31,13 +31,17 @@ rule("utils.merge.archive")
dep:data_set("inherit.links.deplink", false)
end
end
+ else
+ target:rule_enable("utils.merge.archive", false)
end
end)
+
on_build_files(function (target, sourcebatch, opt)
if sourcebatch.sourcefiles then
target:data_set("merge_archive.sourcefiles", sourcebatch.sourcefiles)
end
end)
+
after_link(function (target, opt)
if not target:is_static() then
return
diff --git a/xmake/rules/utils/symbols/extract/xmake.lua b/xmake/rules/utils/symbols/extract/xmake.lua
index 0cc8c9c97..b9fd816eb 100644
--- a/xmake/rules/utils/symbols/extract/xmake.lua
+++ b/xmake/rules/utils/symbols/extract/xmake.lua
@@ -20,8 +20,7 @@
-- define rule: utils.symbols.extract
rule("utils.symbols.extract")
- before_link(function(target)
- import("core.platform.platform")
+ after_config(function(target)
-- need generate symbols?
local strip = target:get("strip")
@@ -32,6 +31,8 @@ rule("utils.symbols.extract")
target:data_set("utils.symbols.extract", true)
target:set("strip", "none") -- disable strip in link stage, because we need to run separate strip commands
target:data_set("strip.origin", strip)
+ else
+ target:rule_enable("utils.symbols.extract", false)
end
end)
after_link(function (target, opt)