summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
author白喵 <[email protected]>2024-07-22 13:34:59 +0800
committer白喵 <[email protected]>2024-07-22 13:34:59 +0800
commitd3f4cf3871782744ebbcb0898a0c5df69d924b15 (patch)
treeaeeda3a69706bec9a5522f4c91e42ca89d1b5bca /xmake/modules
parentef289c5915fd1f8d770333126e0bea39ed504177 (diff)
refactor policy msbuild.multi_tool_task
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/package/tools/cmake.lua19
-rw-r--r--xmake/modules/package/tools/msbuild.lua6
-rw-r--r--xmake/modules/private/action/trybuild/cmake.lua15
-rw-r--r--xmake/modules/private/action/trybuild/msbuild.lua14
4 files changed, 34 insertions, 20 deletions
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua
index 6055d813c..172f11f35 100644
--- a/xmake/modules/package/tools/cmake.lua
+++ b/xmake/modules/package/tools/cmake.lua
@@ -29,6 +29,7 @@ import("core.project.project")
import("lib.detect.find_file")
import("lib.detect.find_tool")
import("package.tools.ninja")
+import("package.tools.msbuild")
import("detect.sdks.find_emsdk")
import("private.utils.toolchain", {alias = "toolchain_utils"})
@@ -945,14 +946,8 @@ end
-- do build for msvc
function _build_for_msvc(package, configs, opt)
- local jobs = _get_parallel_njobs(opt)
local slnfile = assert(find_file("*.sln", os.curdir()), "*.sln file not found!")
- local runenvs = _get_msvc_runenvs(package)
- local msbuild = find_tool("msbuild", {envs = runenvs})
- os.vrunv(msbuild.program, {slnfile, "-nologo", "-t:Rebuild",
- (jobs ~= nil and format("-m:%d", jobs) or "-m"),
- "-p:Configuration=" .. (package:is_debug() and "Debug" or "Release"),
- "-p:Platform=" .. _get_vsarch(package)}, {envs = runenvs})
+ msbuild.build(package, {slnfile, "-t:Rebuild"})
end
-- do build for make
@@ -1013,17 +1008,11 @@ end
-- do install for msvc
function _install_for_msvc(package, configs, opt)
- local jobs = _get_parallel_njobs(opt)
local slnfile = assert(find_file("*.sln", os.curdir()), "*.sln file not found!")
- local runenvs = _get_msvc_runenvs(package)
- local msbuild = assert(find_tool("msbuild", {envs = runenvs}), "msbuild not found!")
- os.vrunv(msbuild.program, {slnfile, "-nologo", "-t:Rebuild", "/nr:false",
- (jobs ~= nil and format("-m:%d", jobs) or "-m"),
- "-p:Configuration=" .. (package:is_debug() and "Debug" or "Release"),
- "-p:Platform=" .. _get_vsarch(package)}, {envs = runenvs})
+ msbuild.build(package, {slnfile, "-t:Rebuild", "/nr:false"})
local projfile = os.isfile("INSTALL.vcxproj") and "INSTALL.vcxproj" or "INSTALL.vcproj"
if os.isfile(projfile) then
- os.vrunv(msbuild.program, {projfile, "/property:configuration=" .. (package:is_debug() and "Debug" or "Release")}, {envs = runenvs})
+ msbuild.build(package, {projfile})
os.trycp("install/bin", package:installdir())
os.trycp("install/lib", package:installdir()) -- perhaps only headers library
os.trycp("install/share", package:installdir())
diff --git a/xmake/modules/package/tools/msbuild.lua b/xmake/modules/package/tools/msbuild.lua
index 34aa86453..e6945168e 100644
--- a/xmake/modules/package/tools/msbuild.lua
+++ b/xmake/modules/package/tools/msbuild.lua
@@ -20,6 +20,7 @@
-- imports
import("core.base.option")
+import("core.project.project")
import("core.tool.toolchain")
import("lib.detect.find_tool")
import("private.utils.upgrade_vsproj")
@@ -64,6 +65,11 @@ function _get_configs(package, configs, opt)
if not configs_str:find("p:Platform=", 1, true) then
table.insert(configs, "-p:Platform=" .. _get_vsarch(package))
end
+ if jobs and project.policy("package.msbuild.multi_tool_task") then
+ table.insert(configs, "/p:UseMultiToolTask=true")
+ table.insert(configs, "/p:EnforceProcessCountAcrossBuilds=true")
+ table.insert(configs, format("/p:MultiProcMaxCount=%d", jobs))
+ end
return configs
end
diff --git a/xmake/modules/private/action/trybuild/cmake.lua b/xmake/modules/private/action/trybuild/cmake.lua
index 747ab9c94..c6caa6d65 100644
--- a/xmake/modules/private/action/trybuild/cmake.lua
+++ b/xmake/modules/private/action/trybuild/cmake.lua
@@ -21,6 +21,7 @@
-- imports
import("core.base.option")
import("core.project.config")
+import("core.project.project")
import("core.tool.toolchain")
import("core.platform.platform")
import("lib.detect.find_file")
@@ -467,9 +468,17 @@ function _build_for_msvc(opt)
local runenvs = _get_msvc_runenvs()
local msbuild = find_tool("msbuild", {envs = runenvs})
local slnfile = assert(find_file("*.sln", os.curdir()), "*.sln file not found!")
- os.vexecv(msbuild.program, {slnfile, "-nologo", "-t:Build", "-m",
- "-p:Configuration=" .. (is_mode("debug") and "Debug" or "Release"),
- "-p:Platform=" .. _get_vsarch()}, {envs = runenvs})
+ local jobs = option.get("jobs") or tostring(os.default_njob())
+ local configs = {
+ slnfile, "-nologo", "-t:Build", (jobs ~= nil and format("-m:%d", jobs) or "-m"),
+ "-p:Configuration=" .. (is_mode("debug") and "Debug" or "Release"),"-p:Platform=" .. _get_vsarch()
+ }
+ if jobs and project.policy("package.msbuild.multi_tool_task") then
+ table.insert(configs, "/p:UseMultiToolTask=true")
+ table.insert(configs, "/p:EnforceProcessCountAcrossBuilds=true")
+ table.insert(configs, format("/p:MultiProcMaxCount=%d", jobs))
+ end
+ os.vexecv(msbuild.program, configs, {envs = runenvs})
local projfile = os.isfile("INSTALL.vcxproj") and "INSTALL.vcxproj" or "INSTALL.vcproj"
if os.isfile(projfile) then
os.vexecv(msbuild.program, {projfile, "/property:configuration=" .. (is_mode("debug") and "Debug" or "Release")}, {envs = runenvs})
diff --git a/xmake/modules/private/action/trybuild/msbuild.lua b/xmake/modules/private/action/trybuild/msbuild.lua
index d8e1f1baa..1df12347d 100644
--- a/xmake/modules/private/action/trybuild/msbuild.lua
+++ b/xmake/modules/private/action/trybuild/msbuild.lua
@@ -21,6 +21,7 @@
-- imports
import("core.base.option")
import("core.project.config")
+import("core.project.project")
import("core.tool.toolchain")
import("lib.detect.find_file")
import("lib.detect.find_tool")
@@ -42,11 +43,12 @@ function clean()
local projectfile = _find_projectfile()
local runenvs = toolchain.load("msvc"):runenvs()
local msbuild = find_tool("msbuild", {envs = runenvs})
+ local platform = is_arch("x64") and "x64" or "Win32"
local projectdata = io.readfile(projectfile)
if projectdata and projectdata:find("Any CPU", 1, true) then
platform = "Any CPU"
end
- os.vexecv(msbuild.program, {projectfile, "-nologo", "-t:Clean", "-p:Configuration=Release", "-p:Platform=" .. platform}, {envs = runenvs})
+ os.vexecv(msbuild.program, {projectfile, "-nologo", "-t:Clean", "-p:Configuration=" .. (is_mode("debug") and "Debug" or "Release"), "-p:Platform=" .. platform}, {envs = runenvs})
end
-- do build
@@ -64,6 +66,14 @@ function build()
if projectdata and projectdata:find("Any CPU", 1, true) then
platform = "Any CPU"
end
- os.vexecv(msbuild.program, {projectfile, "-nologo", "-t:Build", "-p:Configuration=Release", "-p:Platform=" .. platform}, {envs = runenvs})
+ local configs = {projectfile, "-nologo", "-t:Build", "-p:Configuration=" .. (is_mode("debug") and "Debug" or "Release"), "-p:Platform=" .. platform}
+ local jobs = option.get("jobs") or tostring(os.default_njob())
+ table.insert(configs, (jobs ~= nil and format("-m:%d", jobs) or "-m"))
+ if jobs and project.policy("package.msbuild.multi_tool_task") then
+ table.insert(configs, "/p:UseMultiToolTask=true")
+ table.insert(configs, "/p:EnforceProcessCountAcrossBuilds=true")
+ table.insert(configs, format("/p:MultiProcMaxCount=%d", jobs))
+ end
+ os.vexecv(msbuild.program, configs, {envs = runenvs})
cprint("${color.success}build ok!")
end