diff options
| author | ruki <[email protected]> | 2026-01-10 20:29:46 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-01-10 20:29:46 +0800 |
| commit | fedbf62b7e11abac537157b3174e5dfd82333f47 (patch) | |
| tree | 36a3e76af6eebb1ecefd1fc89a812e0e52e8c148 | |
| parent | baf6ad23a4753fe0c3d7d804076f56509696d82a (diff) | |
| parent | 3dea1417ba6abecc32afa3dd944d72d2e96b013b (diff) | |
Merge pull request #7203 from xmake-io/mingw
improve mingw toolchain
| -rw-r--r-- | xmake/modules/detect/sdks/find_mingw.lua | 40 | ||||
| -rw-r--r-- | xmake/toolchains/mingw/check.lua | 3 | ||||
| -rw-r--r-- | xmake/toolchains/mingw/xmake.lua | 35 |
3 files changed, 46 insertions, 32 deletions
diff --git a/xmake/modules/detect/sdks/find_mingw.lua b/xmake/modules/detect/sdks/find_mingw.lua index 37b6625c6..1d1c1fab1 100644 --- a/xmake/modules/detect/sdks/find_mingw.lua +++ b/xmake/modules/detect/sdks/find_mingw.lua @@ -80,7 +80,12 @@ function _find_mingwdir(sdkdir, msystem) end -- find the mingw toolchain -function _find_mingw(sdkdir, bindir, cross, msystem) +function _find_mingw(sdkdir, opt) + opt = opt or {} + local bindir = opt.bindir + local cross = opt.cross + local msystem = opt.msystem + local arch = opt.arch or config.get("arch") or os.arch() -- find mingw root directory sdkdir = _find_mingwdir(sdkdir, msystem) @@ -90,11 +95,11 @@ function _find_mingw(sdkdir, bindir, cross, msystem) -- select cross on macOS, e.g x86_64-w64-mingw32- or i686-w64-mingw32- if not cross then - if is_arch("i386", "x86", "i686") then + if arch == "i386" or arch == "x86" or arch == "i686" then cross = "i686-w64-mingw32-" - elseif is_arch("arm64", "aarch64") then + elseif arch == "arm64" or arch == "aarch64" then cross = "aarch64-w64-mingw32-" -- for llvm-mingw - elseif is_arch("arm.*") then + elseif arch:startswith("arm") then cross = "armv7-w64-mingw32-" -- for llvm-mingw else cross = "x86_64-w64-mingw32-" @@ -115,7 +120,7 @@ end -- -- @param sdkdir the mingw directory -- @param opt the argument options --- e.g. {verbose = true, force = false, bindir = .., cross = ...} +-- e.g. {verbose = true, force = false, bindir = .., cross = ..., arch = ...} -- -- @return the mingw toolchains. e.g. {sdkdir = .., bindir = .., cross = ..} -- @@ -127,36 +132,29 @@ end -- @endcode -- function main(sdkdir, opt) - - -- init arguments opt = opt or {} -- 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.mingw.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 -- 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"), - opt.msystem - ) + local mingw = _find_mingw(sdkdir or config.get("mingw") or global.get("mingw") or config.get("sdk"), { + bindir = opt.bindir or config.get("bin"), + cross = opt.cross or config.get("cross"), + msystem = opt.msystem, + arch = opt.arch + }) if mingw and mingw.sdkdir then - - -- save to config config.set("mingw", mingw.sdkdir, {force = true, readonly = true}) - - -- trace if opt.verbose or option.get("verbose") then - cprint("checking for mingw directory ... ${color.success}%s", mingw.sdkdir) + cprint("checking for mingw directory ... ${color.success}%s (%s)", mingw.sdkdir, mingw.cross) end else - - -- trace if opt.verbose or option.get("verbose") then cprint("checking for mingw directory ... ${color.nothing}${text.nothing}") end diff --git a/xmake/toolchains/mingw/check.lua b/xmake/toolchains/mingw/check.lua index 030dc6dd4..15cfe510a 100644 --- a/xmake/toolchains/mingw/check.lua +++ b/xmake/toolchains/mingw/check.lua @@ -28,7 +28,7 @@ function main(toolchain) for _, package in ipairs(toolchain:packages()) do local installdir = package:installdir() if installdir and os.isdir(installdir) then - mingw = find_mingw(installdir, {verbose = true, cross = toolchain:cross()}) + mingw = find_mingw(installdir, {verbose = true, cross = toolchain:cross(), arch = toolchain:arch()}) if mingw then break end @@ -40,6 +40,7 @@ function main(toolchain) bindir = toolchain:bindir(), cross = toolchain:cross(), msystem = toolchain:config("msystem"), + arch = toolchain:arch() }) end if mingw then diff --git a/xmake/toolchains/mingw/xmake.lua b/xmake/toolchains/mingw/xmake.lua index 5c63cb734..d0695dcfe 100644 --- a/xmake/toolchains/mingw/xmake.lua +++ b/xmake/toolchains/mingw/xmake.lua @@ -31,17 +31,32 @@ toolchain("mingw") local use_clang = toolchain:config("clang") -- get cross - local cross - if toolchain:is_arch("x86_64", "x64") then - cross = "x86_64-w64-mingw32-" - elseif toolchain:is_arch("i386", "x86", "i686") then - cross = "i686-w64-mingw32-" - elseif toolchain:is_arch("arm64", "aarch64") then - cross = "aarch64-w64-mingw32-" - elseif toolchain:is_arch("armv7", "arm.*") then - cross = "armv7-w64-mingw32-" + -- https://github.com/xmake-io/xmake/issues/7196 + local cross = toolchain:cross() or "" + if cross ~= "" then + local arch + if cross:startswith("x86_64") then + arch = "x86_64" + elseif cross:startswith("i686") then + arch = "i386" + elseif cross:startswith("aarch64") then + arch = "arm64" + elseif cross:startswith("arm") then + arch = "armv7" + end + if arch then + toolchain:arch_set(arch) + end else - cross = toolchain:cross() or "" + if toolchain:is_arch("x86_64", "x64") then + cross = "x86_64-w64-mingw32-" + elseif toolchain:is_arch("i386", "x86", "i686") then + cross = "i686-w64-mingw32-" + elseif toolchain:is_arch("arm64", "aarch64") then + cross = "aarch64-w64-mingw32-" + elseif toolchain:is_arch("armv7", "arm.*") then + cross = "armv7-w64-mingw32-" + end end -- add bin search library for loading some dependent .dll files windows |
