summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-01-16 11:05:21 +0800
committerGitHub <[email protected]>2024-01-16 11:05:21 +0800
commit8665b9d17bc8a4ddb6cd168033e584e602f07e8f (patch)
tree24beb19306f498f7d8a67f4b7accb723d5c146f5
parentd3589b0d7954ed7f37dea0c19299341054cd3f3c (diff)
parent59fbdc6260522310e8f5dc606ab7d5fc1a93bfd9 (diff)
Merge pull request #4617 from xmake-io/vs
support vsdevcmd without vcvarsall.bat #4609
-rw-r--r--xmake/modules/detect/sdks/find_vstudio.lua34
1 files changed, 28 insertions, 6 deletions
diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua
index a95c48059..104a2ca79 100644
--- a/xmake/modules/detect/sdks/find_vstudio.lua
+++ b/xmake/modules/detect/sdks/find_vstudio.lua
@@ -99,9 +99,12 @@ end
-- load vcvarsall environment variables
function _load_vcvarsall(vcvarsall, vsver, arch, opt)
+ opt = opt or {}
+
+ -- is VsDevCmd.bat?
+ local is_vsdevcmd = path.basename(vcvarsall):lower() == "vsdevcmd"
-- make the genvcvars.bat
- opt = opt or {}
local genvcvars_bat = os.tmpfile() .. "_genvcvars.bat"
local file = io.open(genvcvars_bat, "w")
file:print("@echo off")
@@ -115,10 +118,18 @@ function _load_vcvarsall(vcvarsall, vsver, arch, opt)
if vsver and tonumber(vsver) >= 16 then
file:print("set VSCMD_SKIP_SENDTELEMETRY=yes")
end
- if opt.vcvars_ver then
- file:print("call \"%s\" %s %s -vcvars_ver=%s > nul", vcvarsall, arch, opt.sdkver and opt.sdkver or "", opt.vcvars_ver)
+ if is_vsdevcmd then
+ if opt.vcvars_ver then
+ file:print("call \"%s\" -arch=%s -winsdk=%s -vcvars_ver=%s > nul", vcvarsall, arch, opt.sdkver and opt.sdkver or "", opt.vcvars_ver)
+ else
+ file:print("call \"%s\" -arch=%s -winsdk=%s > nul", vcvarsall, arch, opt.sdkver and opt.sdkver or "")
+ end
else
- file:print("call \"%s\" %s %s > nul", vcvarsall, arch, opt.sdkver and opt.sdkver or "")
+ if opt.vcvars_ver then
+ file:print("call \"%s\" %s %s -vcvars_ver=%s > nul", vcvarsall, arch, opt.sdkver and opt.sdkver or "", opt.vcvars_ver)
+ else
+ file:print("call \"%s\" %s %s > nul", vcvarsall, arch, opt.sdkver and opt.sdkver or "")
+ end
end
for idx, var in ipairs(get_vcvars()) do
file:print("echo " .. var .. " = %%" .. var .. "%%")
@@ -276,18 +287,19 @@ function _find_vstudio(opt)
-- * version > 15.0 eschews registry entries; but `vswhere` (included with version >= 15.2) can be used to find VC install path
-- ref: https://github.com/Microsoft/vswhere/blob/master/README.md @@ https://archive.is/mEmdu
local vswhere_VCAuxiliaryBuildDir = nil
+ local vswhere_Common7ToolsDir = nil
if (tonumber(version) >= 15) and vswhere then
local vswhere_vrange = format("%s,%s)", version, (version + 1))
-- build tools: https://github.com/microsoft/vswhere/issues/22 @@ https://aka.ms/vs/workloads
local result = os.iorunv(vswhere.program, {"-products", "*", "-prerelease", "-property", "installationpath", "-version", vswhere_vrange})
if result then
vswhere_VCAuxiliaryBuildDir = path.join(result:trim(), "VC", "Auxiliary", "Build")
+ vswhere_Common7ToolsDir = path.join(result:trim(), "Common7", "Tools")
end
end
-- init paths
- local paths =
- {
+ local paths = {
format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC", version),
format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC7\\bin", version),
format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC", version),
@@ -330,6 +342,16 @@ function _find_vstudio(opt)
end
vcvarsall = find_file("vcvarsall.bat", paths) or find_file("vcvars32.bat", paths)
end
+ if not vcvarsall then
+ local paths = {
+ format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\Common7\\Tools", version),
+ format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\Common7\\Tools", version)
+ }
+ if vswhere_Common7ToolsDir and os.isdir(vswhere_Common7ToolsDir) then
+ table.insert(paths, 1, vswhere_Common7ToolsDir)
+ end
+ vcvarsall = find_file("VsDevCmd.bat", paths)
+ end
if vcvarsall then
-- load vcvarsall