summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstar9029 <[email protected]>2025-10-03 22:27:54 +0800
committerstar9029 <[email protected]>2025-10-03 22:27:54 +0800
commit85ee33be02afc40a7c5f91de1bb48d603f9a186c (patch)
treea1dd8d22f7db6c4ce42e8638a87d25d1c7abd839
parentb04e997c1a09cfc6d1a78a982d4ababd0d4ef609 (diff)
Add msystem support on msys2
-rw-r--r--xmake/modules/detect/sdks/find_mingw.lua23
-rw-r--r--xmake/toolchains/mingw/check.lua7
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)