From 3d0d34e5e732d9025d03d5098f50d08e7fb50d2c Mon Sep 17 00:00:00 2001 From: jinke18 Date: Thu, 1 Aug 2024 16:24:00 +0800 Subject: [PATCH 1/3] find_vstudio: cases when variable `WindowsSdkBinPath` is '\' or empty str --- xmake/modules/detect/sdks/find_vstudio.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua index 0bc374204..a87defb66 100644 --- a/xmake/modules/detect/sdks/find_vstudio.lua +++ b/xmake/modules/detect/sdks/find_vstudio.lua @@ -186,7 +186,10 @@ function _load_vcvarsall(vcvarsall, vsver, arch, opt) if WindowsSDKVersion ~= "" then variables["WindowsSDKVersion"] = WindowsSDKVersion end - else + end + + WindowsSDKVersion = variables["WindowsSDKVersion"] + if not WindowsSDKVersion or WindowsSDKVersion == "" then -- 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"] From 3118645da49f4ba2f25493fb207b01b61203e4b4 Mon Sep 17 00:00:00 2001 From: jinke18 Date: Thu, 1 Aug 2024 17:25:39 +0800 Subject: [PATCH 2/3] find_vstudio: parse WindowsSdkBinPath from WindowsSdkDir --- xmake/modules/detect/sdks/find_vstudio.lua | 43 +++++++++++----------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua index a87defb66..86f782aa7 100644 --- a/xmake/modules/detect/sdks/find_vstudio.lua +++ b/xmake/modules/detect/sdks/find_vstudio.lua @@ -179,27 +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 - end - - WindowsSDKVersion = variables["WindowsSDKVersion"] - if not WindowsSDKVersion or WindowsSDKVersion == "" then - -- 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 -- @@ -221,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 From 7d4139194a356d8eb7c7e972dc1337503fca600d Mon Sep 17 00:00:00 2001 From: jinke18 Date: Thu, 1 Aug 2024 17:27:33 +0800 Subject: [PATCH 3/3] problem in find_rc caused by empty variable `WindowsSDKVersion` --- xmake/modules/detect/tools/find_rc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/detect/tools/find_rc.lua b/xmake/modules/detect/tools/find_rc.lua index 08db8fb87..8b8b9d24b 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)