diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua index 0bc37420459..86f782aa7e7 100644 --- a/xmake/modules/detect/sdks/find_vstudio.lua +++ b/xmake/modules/detect/sdks/find_vstudio.lua @@ -179,24 +179,6 @@ function _load_vcvarsall(vcvarsall, vsver, arch, opt) end end - -- fix WindowsSDKVersion - local WindowsSDKVersion = variables["WindowsSDKVersion"] - if WindowsSDKVersion then - WindowsSDKVersion = WindowsSDKVersion:gsub("\\", ""):trim() - if WindowsSDKVersion ~= "" then - variables["WindowsSDKVersion"] = WindowsSDKVersion - end - else - -- sometimes the variable `WindowsSDKVersion` is not available - -- then parse it from `WindowsSdkBinPath`, such as: `C:\\Program Files (x86)\\Windows Kits\\8.1\\bin` - local WindowsSdkBinPath = variables["WindowsSdkBinPath"] - if WindowsSdkBinPath then - WindowsSDKVersion = string.match(WindowsSdkBinPath, "\\(%d+%.%d+)\\bin$") - if WindowsSDKVersion then - variables["WindowsSDKVersion"] = WindowsSDKVersion - end - end - end -- fix UCRTVersion -- @@ -218,6 +200,28 @@ function _load_vcvarsall(vcvarsall, vsver, arch, opt) variables["UCRTVersion"] = UCRTVersion end + -- fix WindowsSDKVersion + local WindowsSDKVersion = variables["WindowsSDKVersion"] + if WindowsSDKVersion then + WindowsSDKVersion = WindowsSDKVersion:gsub("\\", ""):trim() + if WindowsSDKVersion ~= "" then + variables["WindowsSDKVersion"] = WindowsSDKVersion + end + end + + WindowsSDKVersion = variables["WindowsSDKVersion"] + if not WindowsSDKVersion or WindowsSDKVersion == "" then + -- sometimes the variable `WindowsSDKVersion` is not available + -- then parse it from `WindowsSdkDir`, such as: `C:\\Program Files (x86)\\Windows Kits\\8.1\\` + local WindowsSdkDir = variables["WindowsSdkDir"] + if WindowsSdkDir then + WindowsSDKVersion = string.match(WindowsSdkDir, "\\(%d+%.%d+)\\$") + if WindowsSDKVersion then + variables["WindowsSDKVersion"] = WindowsSDKVersion + end + end + end + -- convert path/lib/include to PATH/LIB/INCLUDE variables.PATH = variables.path variables.LIB = variables.lib diff --git a/xmake/modules/detect/tools/find_rc.lua b/xmake/modules/detect/tools/find_rc.lua index 08db8fb8794..8b8b9d24b0d 100644 --- a/xmake/modules/detect/tools/find_rc.lua +++ b/xmake/modules/detect/tools/find_rc.lua @@ -58,7 +58,7 @@ function main(opt) -- e.g. C:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x64 -- local envs = opt.envs - if envs and envs.WindowsSdkDir and envs.WindowsSDKVersion then + if envs and envs.WindowsSdkDir and envs.WindowsSDKVersion and type(envs.WindowsSDKVersion) == "string" then local toolchain = opt.toolchain local arch = toolchain and toolchain:arch() or config.arch() local bindir = path.join(envs.WindowsSdkDir, "bin", envs.WindowsSDKVersion, arch)