Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add policy msbuild.multi_tool_task #5367

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions xmake/core/project/policy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,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
Expand Down
19 changes: 4 additions & 15 deletions xmake/modules/package/tools/cmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"})

Expand Down Expand Up @@ -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})
ChrisCatCP marked this conversation as resolved.
Show resolved Hide resolved
msbuild.build(package, {slnfile, "-t:Rebuild"})
end

-- do build for make
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions xmake/modules/package/tools/msbuild.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down
Loading