Skip to content

Add conan.tools.gnu.is_mingw() helper#19963

Open
HYUEHFJKhfjklkej wants to merge 1 commit into
conan-io:develop2from
HYUEHFJKhfjklkej:feature/15648-is-mingw
Open

Add conan.tools.gnu.is_mingw() helper#19963
HYUEHFJKhfjklkej wants to merge 1 commit into
conan-io:develop2from
HYUEHFJKhfjklkej:feature/15648-is-mingw

Conversation

@HYUEHFJKhfjklkej

@HYUEHFJKhfjklkej HYUEHFJKhfjklkej commented May 10, 2026

Copy link
Copy Markdown
Contributor

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 naming
in package()); today they reimplement this check inline, often missing
edge cases.

This is a fresh take on the prior 1.x attempt (#12678), rewritten for
2.x with the review feedback applied:

Detection rules

A toolchain is identified as MinGW when:

Setting Required value
os "Windows"
os.subsystem not "cygwin"
compiler "gcc", or "clang" with compiler.runtime unset

Anything else (incl. msvc, clang-cl, Cygwin gcc, Linux/macOS gcc/clang)
returns False.

API

from conan.tools.gnu import is_mingw

class Recipe(ConanFile):
    def generate(self):
        if is_mingw(self):
            ...                    # MinGW-specific branch

build_context=True mirrors is_msvc() and consults settings_build
instead of host settings.

closes #15648

Test plan

Unit tests

New parametrized suite at test/unittests/tools/gnu/test_mingw.py covers:
gcc-mingw, MinGW-Clang, clang-cl, msvc, Cygwin gcc, Linux gcc/clang,
macOS apple-clang, build_context=True, and a C-only recipe with no
compiler.libcxx set.

Suite Result
pytest test/unittests/tools/gnu/test_mingw.py 10 passed (Linux/macOS) + 10 passed (Windows Server 2022)
pytest test/unittests/tools/gnu/ 164 passed
pytest test/unittests/tools/ 710 passed, 8 skipped (pre-existing)

End-to-end on real Windows host

Verified via conan install on Windows Server 2022 Standard Evaluation
with four profiles, each driving a tiny recipe whose generate() calls
is_mingw(self):

Profile Expected Got
Windows + gcc-mingw + libstdc++11 True True
Windows + clang + compiler.runtime=dynamic (clang-cl) False False
Windows + msvc 193 False False
Windows host → cross to Linux gcc False False

Follow-up

Docs PR to follow at conan-io/docs once this lands.

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
@CLAassistant

CLAassistant commented May 10, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread conan/tools/gnu/mingw.py
compiler = settings.get_safe("compiler")
if compiler == "gcc":
return True
if compiler == "clang" and settings.get_safe("compiler.runtime") is None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Provide is_mingw() recipe helper

3 participants