diff options
| author | ruki <[email protected]> | 2023-05-06 00:58:55 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-05-06 00:58:55 +0800 |
| commit | e705d24f4f0bb7194e01e18bb94dbf4261b9b8d6 (patch) | |
| tree | dd4f347c767a1642704052ef42314df9fb44e7a0 /xmake/modules/package/tools/msbuild.lua | |
| parent | 8a51d8bb99a04f3e69797228194738c2856c6c2f (diff) | |
improve msbuild #3078
Diffstat (limited to 'xmake/modules/package/tools/msbuild.lua')
| -rw-r--r-- | xmake/modules/package/tools/msbuild.lua | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/xmake/modules/package/tools/msbuild.lua b/xmake/modules/package/tools/msbuild.lua index b9794a4e3..1524329b6 100644 --- a/xmake/modules/package/tools/msbuild.lua +++ b/xmake/modules/package/tools/msbuild.lua @@ -23,6 +23,12 @@ import("core.base.option") import("core.tool.toolchain") import("lib.detect.find_tool") +-- get the number of parallel jobs +function _get_parallel_njobs(opt) + return opt.jobs or option.get("jobs") or tostring(os.default_njob()) +end + +-- tra -- get msvc function _get_msvc(package) local msvc = toolchain.load("msvc", {plat = package:plat(), arch = package:arch()}) @@ -30,9 +36,36 @@ function _get_msvc(package) return msvc end +-- get msvc run environments +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:startswith('arm64') then return "ARM64" end + if arch:startswith('arm') then return "ARM" end + return arch +end + +-- get configs +function _get_configs(package, configs, opt) + local jobs = _get_parallel_njobs(opt) + configs = configs or {} + table.insert(configs, "-nologo") + table.insert(configs, "-t:Rebuild") + table.insert(configs, (jobs ~= nil and format("-m:%d", jobs) or "-m")) + table.insert(configs, "-p:Configuration=" .. (package:is_debug() and "Debug" or "Release")) + table.insert(configs, "-p:Platform=" .. _get_vsarch(package)) + return configs +end + -- get the build environments function buildenvs(package, opt) - return os.joinenvs(_get_msvc(package):runenvs()) + return _get_msvc_runenvs(package) end -- build package @@ -43,7 +76,7 @@ function build(package, configs, opt) -- pass configurations local argv = {} - for name, value in pairs(configs) do + for name, value in pairs(_get_configs(package, configs, opt)) do value = tostring(value):trim() if value ~= "" then if type(name) == "number" then |
