From 0453b923c122c63b8137a455c36556518f07c164 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Fri, 20 Oct 2023 13:59:56 +0200 Subject: [PATCH 1/2] BLD: Skip MSVC compatibility when building against mingw-w64 Python In MSYS2 we build numpy like Linux distros, so we prefer dynamic linking and it needs to be ABI compatible with all other packages. numpy by default statically links ucrt and changes the ABI to match MSVC, which makes it incompatible with other packages. To differentiate the two use cases detect if we are building against a mingww-64 Python build, and if we are skip all the special adjustments. Note that mingw-w64 is not officially supported by upstream CPython. --- numpy/meson.build | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/numpy/meson.build b/numpy/meson.build index 5d07b89679e4..2d1a1a101570 100644 --- a/numpy/meson.build +++ b/numpy/meson.build @@ -13,12 +13,17 @@ is_windows = host_machine.system() == 'windows' is_mingw = is_windows and cc.get_id() == 'gcc' if is_mingw - # For mingw-w64, link statically against the UCRT. - gcc_link_args = ['-lucrt', '-static'] - add_project_link_arguments(gcc_link_args, language: ['c', 'cpp']) - # Force gcc to float64 long doubles for compatibility with MSVC - # builds, for C only. - add_project_arguments('-mlong-double-64', language: 'c') + is_mingw_built_python = run_command( + py, ['-c', 'import sysconfig; print(sysconfig.get_platform())'], + check: true).stdout().strip().startswith('mingw') + if not is_mingw_built_python + # For mingw-w64, link statically against the UCRT. + gcc_link_args = ['-lucrt', '-static'] + add_project_link_arguments(gcc_link_args, language: ['c', 'cpp']) + # Force gcc to float64 long doubles for compatibility with MSVC + # builds, for C only. + add_project_arguments('-mlong-double-64', language: 'c') + endif # Make fprintf("%zd") work (see https://github.com/rgommers/scipy/issues/118) add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: ['c', 'cpp']) endif From 9123d4380ea24243ab843356e3bf4f50a8c58554 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Fri, 20 Oct 2023 14:00:55 +0200 Subject: [PATCH 2/2] BLD: Fix mingw detection when building with Clang mingw-w64 nowadays is also available in combination with Clang, for example https://github.com/mstorsjo/llvm-mingw or MSYS2 provide Clang builds using mingw-w64. Instead of testing for GCC check that __MINGW32__ is defined. --- numpy/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy/meson.build b/numpy/meson.build index 2d1a1a101570..ada88d490aa3 100644 --- a/numpy/meson.build +++ b/numpy/meson.build @@ -10,7 +10,7 @@ endif # Platform detection is_windows = host_machine.system() == 'windows' -is_mingw = is_windows and cc.get_id() == 'gcc' +is_mingw = is_windows and cc.get_define('__MINGW32__') != '' if is_mingw is_mingw_built_python = run_command(