From 94533aa7bbd12e39fa8da158427d0fcb3a5c5739 Mon Sep 17 00:00:00 2001 From: Sayed Adel Date: Fri, 12 Nov 2021 07:54:07 +0200 Subject: [PATCH 1/2] BLD: Verify the ability to compile C++ sources before initiating the build --- numpy/core/setup.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/numpy/core/setup.py b/numpy/core/setup.py index b03e9f99005e..56955262fdd1 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -654,16 +654,29 @@ def get_mathlib_info(*args): # but we cannot use add_installed_pkg_config here either, so we only # update the substitution dictionary during npymath build config_cmd = config.get_config_cmd() - # Check that the toolchain works, to fail early if it doesn't # (avoid late errors with MATHLIB which are confusing if the # compiler does not work). - st = config_cmd.try_link('int main(void) { return 0;}') - if not st: - # rerun the failing command in verbose mode - config_cmd.compiler.verbose = True - config_cmd.try_link('int main(void) { return 0;}') - raise RuntimeError("Broken toolchain: cannot link a simple C program") + for lang, test_code, note in ( + ('c', 'int main(void) { return 0;}', ''), + ('c++', ( + 'int main(void)' + '{ auto x = 0.0; return static_cast(x); }' + ), ( + 'note: A compiler with support for C++11 language ' + 'features is required.' + ) + ), + ): + st = config_cmd.try_link(test_code, lang=lang) + if not st: + # rerun the failing command in verbose mode + config_cmd.compiler.verbose = True + config_cmd.try_link(test_code, lang=lang) + raise RuntimeError( + f"Broken toolchain: cannot link a simple {lang.upper()} " + f"program. {note}" + ) mlibs = check_mathlib(config_cmd) posix_mlib = ' '.join(['-l%s' % l for l in mlibs]) From 6a893b9e2b80c39b5e53f235e0dc11ba629bde9b Mon Sep 17 00:00:00 2001 From: Sayed Adel Date: Sun, 14 Nov 2021 05:14:00 +0200 Subject: [PATCH 2/2] DIST: Workaround ignore invalid C++ flags for config/try_link --- numpy/core/setup.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/numpy/core/setup.py b/numpy/core/setup.py index 56955262fdd1..ae8081d1b92b 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -668,6 +668,13 @@ def get_mathlib_info(*args): ) ), ): + is_cpp = lang == 'c++' + if is_cpp: + # this a workround to get rid of invalid c++ flags + # without doing big changes to config. + # c tested first, compiler should be here + bk_c = config_cmd.compiler + config_cmd.compiler = bk_c.cxx_compiler() st = config_cmd.try_link(test_code, lang=lang) if not st: # rerun the failing command in verbose mode @@ -677,6 +684,8 @@ def get_mathlib_info(*args): f"Broken toolchain: cannot link a simple {lang.upper()} " f"program. {note}" ) + if is_cpp: + config_cmd.compiler = bk_c mlibs = check_mathlib(config_cmd) posix_mlib = ' '.join(['-l%s' % l for l in mlibs])