diff options
| author | ruki <[email protected]> | 2024-07-22 17:41:30 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-07-22 17:41:30 +0800 |
| commit | af5c479c7fc1eecf540b3e930b250a79ca34f19c (patch) | |
| tree | 1e8136c11c5d9ff18618ee703d01f50a9e68d5da | |
| parent | c88a078c25a89452853e068ed06e0de6edefb4eb (diff) | |
| parent | bcdc71d60d1896c71a057438a859d9e6f7126c80 (diff) | |
Merge pull request #5367 from ChrisCatCP/msbuild
add policy msbuild.multi_tool_task
| -rw-r--r-- | xmake/core/project/policy.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/package/tools/cmake.lua | 30 | ||||
| -rw-r--r-- | xmake/modules/package/tools/msbuild.lua | 6 |
3 files changed, 12 insertions, 26 deletions
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 2eb2c1193..7299de719 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -133,6 +133,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..b4337c4f7 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"}) @@ -97,17 +98,6 @@ function _get_msvc_runenvs(package) return os.joinenvs(_get_msvc(package):runenvs()) end --- get vs arch -function _get_vsarch(package) - local arch = package:arch() - if arch == "x86" or arch == "i386" then return "Win32" end - if arch == "x86_64" then return "x64" end - if arch == "arm64ec" then return "ARM64EC" end - if arch:startswith("arm64") then return "ARM64" end - if arch:startswith("arm") then return "ARM" end - return arch -end - -- get cflags from package deps function _get_cflags_from_packagedeps(package, opt) local result = {} @@ -945,14 +935,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 +997,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 |
