diff --git a/docs/markdown/snippets/atomic-now-supports-msvc.md b/docs/markdown/snippets/atomic-now-supports-msvc.md new file mode 100644 index 000000000000..8d3d30044b5b --- /dev/null +++ b/docs/markdown/snippets/atomic-now-supports-msvc.md @@ -0,0 +1,4 @@ +## Custom dependency for atomic now works on MSVC + +`dependency('atomic')` now works on MSVC >=19.35.32124. +It requires `c_std=c11` or later, otherwise the dependency will return not found. diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index b1b8b8e1319b..61f94c00eef2 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -61,6 +61,22 @@ def __init__(self, name: str, env: Environment, kwargs: DependencyObjectKWs): if self.clib_compiler.has_function('atomic_flag_clear', '#include ')[0]: self.is_found = True + elif self.clib_compiler.get_id() == 'msvc': + feature_flag = '/experimental:c11atomics' + std_args = self.clib_compiler.get_option_std_args(None, None) + # atomic_flag_clear forwards to __c11_atomic_store in msvc, + # which behaves like __builtin_* in gcc, and we're unable to detect it with .has_function(). + if self.clib_compiler.has_function( + "_Atomic_thread_fence", "#include ", extra_args=std_args + )[0]: + self.is_found = True + elif self.clib_compiler.has_function( + "_Atomic_thread_fence", + "#include ", + extra_args=std_args + [feature_flag], + )[0]: + self.compile_args = [feature_flag] + self.is_found = True class AtomicSystemDependency(SystemDependency):