Skip to content

Commit ccca7fe

Browse files
committed
dependencies: support custom stdatomic lookup for MSVC
Closes: #14233 Fixes: f070670
1 parent 5412f61 commit ccca7fe

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Custom dependency for atomic now works on MSVC
2+
3+
`dependency('atomic')` now works on MSVC >=19.35.32124.
4+
It requires `c_std=c11` or later, otherwise the dependency will return not found.

mesonbuild/dependencies/misc.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ def __init__(self, name: str, env: Environment, kwargs: DependencyObjectKWs):
6161

6262
if self.clib_compiler.has_function('atomic_flag_clear', '#include <stdatomic.h>')[0]:
6363
self.is_found = True
64+
elif self.clib_compiler.get_id() == 'msvc':
65+
feature_flag = '/experimental:c11atomics'
66+
std_args = self.clib_compiler.get_option_std_args(None, None)
67+
# atomic_flag_clear forwards to __c11_atomic_store in msvc,
68+
# which behaves like __builtin_* in gcc, and we're unable to detect it with .has_function().
69+
if self.clib_compiler.has_function(
70+
"_Atomic_thread_fence", "#include <stdatomic.h>", extra_args=std_args
71+
)[0]:
72+
self.is_found = True
73+
elif self.clib_compiler.has_function(
74+
"_Atomic_thread_fence",
75+
"#include <stdatomic.h>",
76+
extra_args=std_args + [feature_flag],
77+
)[0]:
78+
self.compile_args = [feature_flag]
79+
self.is_found = True
6480

6581

6682
class AtomicSystemDependency(SystemDependency):

0 commit comments

Comments
 (0)