diff options
author | Matti Picus <matti.picus@gmail.com> | 2022-03-31 19:20:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-31 19:20:56 +0300 |
commit | 3f9fada45852a8f1b3fd9e0b760f34425099896c (patch) | |
tree | 38696460c1885533208a0e30a898863422018d59 /numpy/core/setup.py | |
parent | 04bf4057d565f3d47e984fa0f21929bbb8d9ab7c (diff) | |
parent | 28e62acca23652b9e70476ff732422b05121517f (diff) | |
download | numpy-3f9fada45852a8f1b3fd9e0b760f34425099896c.tar.gz |
Merge pull request #21154 from hoodmane/feature-detection-sigs
ENH, BLD: Fix math feature detection for wasm
Diffstat (limited to 'numpy/core/setup.py')
-rw-r--r-- | numpy/core/setup.py | 79 |
1 files changed, 61 insertions, 18 deletions
diff --git a/numpy/core/setup.py b/numpy/core/setup.py index c4222d7c0..5b946d0d4 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -129,32 +129,48 @@ def win32_checks(deflist): deflist.append('FORCE_NO_LONG_DOUBLE_FORMATTING') def check_math_capabilities(config, ext, moredefs, mathlibs): - def check_func(func_name): - return config.check_func(func_name, libraries=mathlibs, - decl=True, call=True) - - def check_funcs_once(funcs_name): - decl = dict([(f, True) for f in funcs_name]) - st = config.check_funcs_once(funcs_name, libraries=mathlibs, - decl=decl, call=decl) + def check_func( + func_name, + decl=False, + headers=["feature_detection_math.h"], + ): + return config.check_func( + func_name, + libraries=mathlibs, + decl=decl, + call=True, + call_args=FUNC_CALL_ARGS[func_name], + headers=headers, + ) + + def check_funcs_once(funcs_name, headers=["feature_detection_math.h"]): + call = dict([(f, True) for f in funcs_name]) + call_args = dict([(f, FUNC_CALL_ARGS[f]) for f in funcs_name]) + st = config.check_funcs_once( + funcs_name, + libraries=mathlibs, + decl=False, + call=call, + call_args=call_args, + headers=headers, + ) if st: moredefs.extend([(fname2def(f), 1) for f in funcs_name]) return st - def check_funcs(funcs_name): + def check_funcs(funcs_name, headers=["feature_detection_math.h"]): # Use check_funcs_once first, and if it does not work, test func per # func. Return success only if all the functions are available - if not check_funcs_once(funcs_name): + if not check_funcs_once(funcs_name, headers=headers): # Global check failed, check func per func for f in funcs_name: - if check_func(f): + if check_func(f, headers=headers): moredefs.append((fname2def(f), 1)) return 0 else: return 1 #use_msvc = config.check_decl("_MSC_VER") - if not check_funcs_once(MANDATORY_FUNCS): raise SystemError("One of the required function to build numpy is not" " available (the list is %s)." % str(MANDATORY_FUNCS)) @@ -169,15 +185,34 @@ def check_math_capabilities(config, ext, moredefs, mathlibs): for f in OPTIONAL_STDFUNCS_MAYBE: if config.check_decl(fname2def(f), headers=["Python.h", "math.h"]): - OPTIONAL_STDFUNCS.remove(f) + if f in OPTIONAL_STDFUNCS: + OPTIONAL_STDFUNCS.remove(f) + else: + OPTIONAL_FILE_FUNCS.remove(f) + check_funcs(OPTIONAL_STDFUNCS) + check_funcs(OPTIONAL_FILE_FUNCS, headers=["feature_detection_stdio.h"]) + check_funcs(OPTIONAL_MISC_FUNCS, headers=["feature_detection_misc.h"]) + + for h in OPTIONAL_HEADERS: if config.check_func("", decl=False, call=False, headers=[h]): h = h.replace(".", "_").replace(os.path.sep, "_") moredefs.append((fname2def(h), 1)) + # Try with both "locale.h" and "xlocale.h" + locale_headers = [ + "stdlib.h", + "xlocale.h", + "feature_detection_locale.h", + ] + if not check_funcs(OPTIONAL_LOCALE_FUNCS, headers=locale_headers): + # It didn't work with xlocale.h, maybe it will work with locale.h? + locale_headers[1] = "locale.h" + check_funcs(OPTIONAL_LOCALE_FUNCS, headers=locale_headers) + for tup in OPTIONAL_INTRINSICS: headers = None if len(tup) == 2: @@ -398,20 +433,28 @@ def check_types(config_cmd, ext, build_dir): def check_mathlib(config_cmd): # Testing the C math library mathlibs = [] - mathlibs_choices = [[], ['m'], ['cpml']] - mathlib = os.environ.get('MATHLIB') + mathlibs_choices = [[], ["m"], ["cpml"]] + mathlib = os.environ.get("MATHLIB") if mathlib: - mathlibs_choices.insert(0, mathlib.split(',')) + mathlibs_choices.insert(0, mathlib.split(",")) for libs in mathlibs_choices: - if config_cmd.check_func("exp", libraries=libs, decl=True, call=True): + if config_cmd.check_func( + "log", + libraries=libs, + call_args="0", + decl="double log(double);", + call=True + ): mathlibs = libs break else: raise RuntimeError( "math library missing; rerun setup.py after setting the " - "MATHLIB env variable") + "MATHLIB env variable" + ) return mathlibs + def visibility_define(config): """Return the define value to use for NPY_VISIBILITY_HIDDEN (may be empty string).""" |