fix_highs_atomic_PR17777
authorDebian Python Team <team+python@tracker.debian.org>
Tue, 7 Feb 2023 08:49:03 +0000 (08:49 +0000)
committerDrew Parsons <dparsons@debian.org>
Tue, 7 Feb 2023 08:49:03 +0000 (08:49 +0000)
===================================================================

Gbp-Pq: Name fix_highs_atomic_PR17777.patch

scipy/meson.build
scipy/optimize/_highs/meson.build

index 87f7afca2313aa143a5d10d0b43b01ded175d3c8..64515495bbc1be1f030d18f039bba8e9b79da54c 100644 (file)
@@ -292,6 +292,25 @@ else
   use_math_defines = []
 endif
 
+# Determine whether it is necessary to link libatomic. This could be the case
+# e.g. on 32-bit platforms when atomic operations are used on 64-bit types.
+# The check is copied from Mesa <https://www.mesa3d.org/>.
+atomic_dep = dependency('', required : false)
+if cc.get_id() != 'msvc'
+  if not cc.links('''
+      #include <stdint.h>
+      int main() {
+       struct {
+         uint64_t *v;
+       } x;
+       return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
+              (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
+      }''',
+      name : 'GCC atomic builtins required -latomic')
+    atomic_dep = cc.find_library('atomic')
+  endif
+endif
+
 # Suppress warning for deprecated Numpy API.
 # (Suppress warning messages emitted by #warning directives).
 # Replace with numpy_nodepr_api after Cython 3.0 is out
index 0d9ffba0b50d3652fdb4897038e27e96ac0868b9..5051a08b979aeca9ef3c9e8365dbdb429ae03af4 100644 (file)
@@ -237,7 +237,7 @@ _highs_wrapper = py3.extension_module('_highs_wrapper',
     '../../_lib/highs/src/lp_data/',
     '../../_lib/highs/src/util/'
   ],
-  dependencies: thread_dep,
+  dependencies: [thread_dep, atomic_dep],
   link_args: version_link_args,
   link_with: [highs_lib, ipx_lib, basiclu_lib],
   cpp_args: [highs_flags, highs_define_macros, cython_c_args],