summaryrefslogtreecommitdiff
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
parentef289c5915fd1f8d770333126e0bea39ed504177 (diff)
refactor policy msbuild.multi_tool_task
-rw-r--r--xmake/core/project/policy.lua4
-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
-rw-r--r--xmake/toolchains/msvc/load.lua6
6 files changed, 36 insertions, 28 deletions
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua
index 8735a6921..101ac5ed0 100644
--- a/xmake/core/project/policy.lua
+++ b/xmake/core/project/policy.lua
@@ -88,8 +88,6 @@ function policy.policies()
["build.c++.gcc.modules.cxx11abi"] = {description = "Force to enable new cxx11 abi in C++ modules for gcc.", type = "boolean"},
-- Enable cuda device link
["build.cuda.devlink"] = {description = "Enable Cuda devlink.", type = "boolean"},
- -- Enable msbuild MultiToolTask
- ["msbuild.multi_tool_task"] = {description = "Enable msbuild MultiToolTask.", type = "boolean"},
-- Enable windows UAC and set level, e.g. invoker, admin, highest
["windows.manifest.uac"] = {description = "Enable windows manifest UAC.", type = "string"},
-- Enable ui access for windows UAC
@@ -133,6 +131,8 @@ function policy.policies()
["package.xmake.pass_depconfs"] = {description = "Automatically passes dependency configuration for inner xmake package", default = true, type = "boolean"},
-- It will force cmake package use ninja for build
["package.cmake_generator.ninja"] = {description = "Set cmake package use ninja for build", default = false, type = "boolean"},
+ -- Enable msbuild MultiToolTask
+ ["package.msbuild.multi_tool_task"] = {description = "Enable msbuild MultiToolTask.", type = "boolean"},
-- Stop to test on the first failure
["test.stop_on_first_failure"] = {description = "Stop to test on the first failure", default = false, type = "boolean"},
-- Return zero as exit code on failure
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
diff --git a/xmake/toolchains/msvc/load.lua b/xmake/toolchains/msvc/load.lua
index a12d894e8..c5f2f6dac 100644
--- a/xmake/toolchains/msvc/load.lua
+++ b/xmake/toolchains/msvc/load.lua
@@ -21,7 +21,6 @@
-- imports
import("core.base.option")
import("core.base.semver")
-import("core.project.project")
import("core.project.config")
import("detect.sdks.find_vstudio")
@@ -91,10 +90,5 @@ function main(toolchain)
if vs and semver.is_valid(vs) and semver.compare(vs, "2005") < 0 then
toolchain:add("runenvs", "VS_BINARY_OUTPUT", "1")
end
-
- -- enable msbuild mtt
- if project.policy("msbuild.multi_tool_task") then
- toolchain:add("runenvs", "UseMultiToolTask", "true")
- end
end