Add conan.tools.gnu.is_mingw() helper#19963
Open
HYUEHFJKhfjklkej wants to merge 1 commit into
Open
Conversation
Adds a `conan.tools.gnu.is_mingw(conanfile, build_context=False)` helper for
recipes that need to branch on a MinGW toolchain (e.g. choose Autotools
instead of NMake/MSBuild, set MinGW-specific package_info fields, or fix
import-library naming in `package()`).
Detection uses an early-return strategy and the canonical Conan settings:
- `os == "Windows"` (a non-Windows host is never MinGW).
- `os.subsystem != "cygwin"` (Cygwin uses a POSIX layer, not MinGW).
- `compiler == "gcc"`, OR
`compiler == "clang"` with `compiler.runtime` unset.
The clang branch follows the official guidance for distinguishing
MinGW-Clang from clang-cl: clang-cl sets `compiler.runtime`, MinGW-Clang
does not. Reference:
https://blog.conan.io/2022/10/13/Different-flavors-Clang-compiler-Windows.html
This addresses feedback from the prior Conan 1.x attempt (conan-io#12678):
- Logic restructured with early returns for readability (memsharded).
- `compiler.libcxx` is intentionally not consulted; it is removed in
`configure()` of pure-C recipes and would be unreliable (SpaceIm).
- `compiler.runtime` is the supported way to disambiguate clang-mingw
from clang-cl (mhthies).
closes conan-io#15648
3 tasks
memsharded
reviewed
Jun 24, 2026
| compiler = settings.get_safe("compiler") | ||
| if compiler == "gcc": | ||
| return True | ||
| if compiler == "clang" and settings.get_safe("compiler.runtime") is None: |
Member
There was a problem hiding this comment.
This isn't necessarily true. The msys2 clang compiler is its own "environment", not a MinGW environment https://www.msys2.org/docs/environments/
the most common definition of is_mingw in ConanCenter recipes is:
@property
def _is_mingw(self):
return self.settings.os == "Windows" and self.settings.compiler == "gcc"So changing and doing it for clang too might be breaking some recipes or use cases?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
conan.tools.gnu.is_mingw(conanfile, build_context=False)helper.Recipes commonly need to branch on a MinGW toolchain (Autotools instead
of NMake/MSBuild, MinGW-specific
package_info, import-library namingin
package()); today they reimplement this check inline, often missingedge cases.
This is a fresh take on the prior 1.x attempt (#12678), rewritten for
2.x with the review feedback applied:
@CJCombrink) flagged the dense boolean expression as the main blocker.
compiler.libcxx— it is removed inconfigure()ofpure-C recipes, so it can't be used to disambiguate clang-mingw vs.
clang-cl (@SpaceIm).
compiler.runtimefor clang disambiguation — clang-cl sets it,MinGW-Clang doesn't. Aligns with the official guidance in
https://blog.conan.io/2022/10/13/Different-flavors-Clang-compiler-Windows.html
(@mhthies).
Detection rules
A toolchain is identified as MinGW when:
os"Windows"os.subsystem"cygwin"compiler"gcc", or"clang"withcompiler.runtimeunsetAnything else (incl.
msvc,clang-cl, Cygwin gcc, Linux/macOS gcc/clang)returns
False.API
build_context=Truemirrorsis_msvc()and consultssettings_buildinstead of host settings.
closes #15648
Test plan
Unit tests
New parametrized suite at
test/unittests/tools/gnu/test_mingw.pycovers:gcc-mingw, MinGW-Clang, clang-cl, msvc, Cygwin gcc, Linux gcc/clang,
macOS apple-clang,
build_context=True, and a C-only recipe with nocompiler.libcxxset.pytest test/unittests/tools/gnu/test_mingw.pypytest test/unittests/tools/gnu/pytest test/unittests/tools/End-to-end on real Windows host
Verified via
conan installon Windows Server 2022 Standard Evaluationwith four profiles, each driving a tiny recipe whose
generate()callsis_mingw(self):TrueTruecompiler.runtime=dynamic(clang-cl)FalseFalseFalseFalseFalseFalseFollow-up
Docs PR to follow at conan-io/docs once this lands.