From 85ee33be02afc40a7c5f91de1bb48d603f9a186c Mon Sep 17 00:00:00 2001 From: star9029 Date: Fri, 3 Oct 2025 22:27:54 +0800 Subject: Add msystem support on msys2 --- xmake/modules/detect/sdks/find_mingw.lua | 23 +++++++++++++++-------- xmake/toolchains/mingw/check.lua | 7 ++++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/xmake/modules/detect/sdks/find_mingw.lua b/xmake/modules/detect/sdks/find_mingw.lua index e1b3571ec..448b89cec 100644 --- a/xmake/modules/detect/sdks/find_mingw.lua +++ b/xmake/modules/detect/sdks/find_mingw.lua @@ -27,9 +27,7 @@ import("core.cache.detectcache") import("detect.sdks.find_cross_toolchain") -- find mingw directory -function _find_mingwdir(sdkdir) - - -- get mingw directory +function _find_mingwdir(sdkdir, msystem) if not sdkdir then if is_host("macosx", "linux") and os.isdir("/opt/llvm-mingw") then sdkdir = "/opt/llvm-mingw" @@ -65,6 +63,10 @@ function _find_mingwdir(sdkdir) end end + if is_subhost("msys") and sdkdir and msystem and not sdkdir:find(msystem, 1, true) then + sdkdir = path.unix(path.join(path.directory(sdkdir), msystem)) + end + -- attempt to find mingw directory from the qt sdk local qt = config.get("qt") if not sdkdir and qt then @@ -78,10 +80,10 @@ function _find_mingwdir(sdkdir) end -- find the mingw toolchain -function _find_mingw(sdkdir, bindir, cross) +function _find_mingw(sdkdir, bindir, cross, msystem) -- find mingw root directory - sdkdir = _find_mingwdir(sdkdir) + sdkdir = _find_mingwdir(sdkdir, msystem) if not sdkdir then return end @@ -105,7 +107,7 @@ function _find_mingw(sdkdir, bindir, cross) toolchain = find_cross_toolchain(sdkdir or bindir, {bindir = bindir}) end if toolchain then - return {sdkdir = toolchain.sdkdir, bindir = toolchain.bindir, cross = toolchain.cross} + return {sdkdir = toolchain.sdkdir, bindir = toolchain.bindir, cross = toolchain.cross, msystem = msystem} end end @@ -132,12 +134,17 @@ function main(sdkdir, opt) -- attempt to load cache first local key = "detect.sdks.find_mingw" local cacheinfo = detectcache:get(key) or {} - if not opt.force and cacheinfo.mingw and cacheinfo.mingw.sdkdir and os.isdir(cacheinfo.mingw.sdkdir) then + if not opt.force and cacheinfo.mingw and cacheinfo.mingw.sdkdir and os.isdir(cacheinfo.mingw.sdkdir) and cacheinfo.msystem == opt.msystem then return cacheinfo.mingw end -- find mingw - local mingw = _find_mingw(sdkdir or config.get("mingw") or global.get("mingw") or config.get("sdk"), opt.bindir or config.get("bin"), opt.cross or config.get("cross")) + local mingw = _find_mingw( + sdkdir or config.get("mingw") or global.get("mingw") or config.get("sdk"), + opt.bindir or config.get("bin"), + opt.cross or config.get("cross"), + opt.msystem + ) if mingw and mingw.sdkdir then -- save to config diff --git a/xmake/toolchains/mingw/check.lua b/xmake/toolchains/mingw/check.lua index fbb647661..030dc6dd4 100644 --- a/xmake/toolchains/mingw/check.lua +++ b/xmake/toolchains/mingw/check.lua @@ -35,7 +35,12 @@ function main(toolchain) end end if not mingw then - mingw = find_mingw(toolchain:config("mingw") or config.get("mingw"), {verbose = true, bindir = toolchain:bindir(), cross = toolchain:cross()}) + mingw = find_mingw(toolchain:config("mingw") or config.get("mingw"), { + verbose = true, + bindir = toolchain:bindir(), + cross = toolchain:cross(), + msystem = toolchain:config("msystem"), + }) end if mingw then toolchain:config_set("mingw", mingw.sdkdir) -- cgit v1.3.1 From cde688f2021845a23751eeb25aecd3b5194c6952 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 4 Oct 2025 17:39:12 +0800 Subject: fix os.getenvs compat --- xmake/core/base/os.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 988d9e4bf..8f56aa8e0 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -42,6 +42,7 @@ os._tmpdir = os._tmpdir or os.tmpdir os._curdir = os._curdir or os.curdir os._fscase = os._fscase or os.fscase os._setenv = os._setenv or os.setenv +os._getenvs = os._getenvs or os.getenvs os._cpuinfo = os._cpuinfo or os.cpuinfo os._meminfo = os._meminfo or os.meminfo os._readlink = os._readlink or os.readlink @@ -1300,6 +1301,33 @@ function os.term() return require("base/tty").term() end +-- get all current environments variables +function os.getenvs() + local envs = os._getenvs() + if envs then + if envs[1] ~= nil then + local result = {} + for _, line in ipairs(envs) do + local p = line:find('=', 1, true) + if p then + local key = line:sub(1, p - 1):trim() + -- only translate Path to PATH on windows + -- @see https://github.com/xmake-io/xmake/issues/3752 + if os.host() == "windows" and key:lower() == "path" then + key = key:upper() + end + local values = line:sub(p + 1):trim() + if #key > 0 then + result[key] = values + end + end + end + envs = result + end + end + return envs +end + -- set all current environment variables -- e.g. envs["PATH"] = "/xxx:/yyy/foo" function os.setenvs(envs) -- cgit v1.3.1 From d31622c8fb0c962262f3397bc8cb1ac670abd001 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 4 Oct 2025 18:01:37 +0800 Subject: improve hash --- xmake/core/base/hash.lua | 11 ++++++++--- xmake/core/base/os.lua | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/xmake/core/base/hash.lua b/xmake/core/base/hash.lua index e846ba302..9d7ca40ed 100644 --- a/xmake/core/base/hash.lua +++ b/xmake/core/base/hash.lua @@ -120,9 +120,14 @@ end -- generate hash32 from string, e.g. "91e8ecf1" function hash.strhash32(str) - local data = libc.ptraddr(libc.dataptr(str)) - local size = #str - return hash._xxhash(32, data, size) + if hash._rand32 then + local data = libc.ptraddr(libc.dataptr(str)) + local size = #str + return hash._xxhash(32, data, size) + else + -- we need to be compatible with the old binary core (<= v3.0.3) + return hash.uuid4(str):split("-", {plain = true})[1]:lower() + end end -- generate hash64 from string, e.g. "91e8ecf191e8ecf1" diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 8f56aa8e0..e6422c549 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -1305,6 +1305,7 @@ end function os.getenvs() local envs = os._getenvs() if envs then + -- we need to be compatible with the old binary core, if it's array (<= v3.0.3) if envs[1] ~= nil then local result = {} for _, line in ipairs(envs) do -- cgit v1.3.1 From 3ef0e493b6202539879289f7b51180177b7134cc Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 4 Oct 2025 18:05:36 +0800 Subject: Fix cacheinfo field reference for mingw detection --- xmake/modules/detect/sdks/find_mingw.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/detect/sdks/find_mingw.lua b/xmake/modules/detect/sdks/find_mingw.lua index 448b89cec..37b6625c6 100644 --- a/xmake/modules/detect/sdks/find_mingw.lua +++ b/xmake/modules/detect/sdks/find_mingw.lua @@ -134,7 +134,7 @@ function main(sdkdir, opt) -- attempt to load cache first local key = "detect.sdks.find_mingw" local cacheinfo = detectcache:get(key) or {} - if not opt.force and cacheinfo.mingw and cacheinfo.mingw.sdkdir and os.isdir(cacheinfo.mingw.sdkdir) and cacheinfo.msystem == opt.msystem then + if not opt.force and cacheinfo.mingw and cacheinfo.mingw.sdkdir and os.isdir(cacheinfo.mingw.sdkdir) and cacheinfo.mingw.msystem == opt.msystem then return cacheinfo.mingw end -- cgit v1.3.1