Skip to content

Commit 337e633

Browse files
authored
[libcxx] [test] Detect mingw-w64 headers compatible with C++ module builds (llvm#92893)
This fixes running the tests/CI with a newer mingw toolchain that has been fixed to work with building libc++ as a module.
1 parent 87a6865 commit 337e633

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

libcxx/utils/libcxx/test/features.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,39 @@ def _getAndroidDeviceApi(cfg):
3838
)
3939
)
4040

41+
42+
def _mingwSupportsModules(cfg):
43+
# Only mingw headers are known to work with libc++ built as a module,
44+
# at the moment.
45+
if not "__MINGW32__" in compilerMacros(cfg):
46+
return False
47+
# For mingw headers, check for a version known to support being built
48+
# as a module.
49+
return sourceBuilds(
50+
cfg,
51+
"""
52+
#include <_mingw_mac.h>
53+
#if __MINGW64_VERSION_MAJOR < 12
54+
#error Headers known to be incompatible
55+
#elif __MINGW64_VERSION_MAJOR == 12
56+
// The headers were fixed to work with libc++ modules during
57+
// __MINGW64_VERSION_MAJOR == 12. The headers became compatible
58+
// with libc++ built as a module in
59+
// 1652e9241b5d8a5a779c6582b1c3c4f4a7cc66e5 (Apr 2024), but the
60+
// following commit 8c13b28ace68f2c0094d45121d59a4b951b533ed
61+
// removed the now unused __mingw_static_ovr define. Use this
62+
// as indicator for whether we've got new enough headers.
63+
#ifdef __mingw_static_ovr
64+
#error Headers too old
65+
#endif
66+
#else
67+
// __MINGW64_VERSION_MAJOR > 12 should be ok.
68+
#endif
69+
int main() { return 0; }
70+
""",
71+
)
72+
73+
4174
# Lit features are evaluated in order. Some checks may require the compiler detection to have
4275
# run first in order to work properly.
4376
DEFAULT_FEATURES = [
@@ -281,7 +314,7 @@ def _getAndroidDeviceApi(cfg):
281314
# Any declaration of a library function shall have external linkage.
282315
when=lambda cfg: "__ANDROID__" in compilerMacros(cfg)
283316
or "__FreeBSD__" in compilerMacros(cfg)
284-
or "_WIN32" in compilerMacros(cfg)
317+
or ("_WIN32" in compilerMacros(cfg) and not _mingwSupportsModules(cfg))
285318
or platform.system().lower().startswith("aix")
286319
# Avoid building on platforms that don't support modules properly.
287320
or not hasCompileFlag(cfg, "-Wno-reserved-module-identifier"),

0 commit comments

Comments
 (0)