Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/markdown/snippets/atomic-now-supports-msvc.md
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 16 additions & 0 deletions mesonbuild/dependencies/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ def __init__(self, name: str, env: Environment, kwargs: DependencyObjectKWs):

if self.clib_compiler.has_function('atomic_flag_clear', '#include <stdatomic.h>')[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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this call is acceptable in dependency lookup.

<vcruntime_c11_stdatomic.h> rejects __STDC_VERSION__ < 201112L, and MSVC defaults to C99

Copy link
Contributor Author

@mochaaP mochaaP Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't care about the symbol being available, just test for compiler version >=19.35.32124 + the header being there, and always provide /experimental:c11atomics

# 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 <stdatomic.h>", extra_args=std_args
)[0]:
self.is_found = True
elif self.clib_compiler.has_function(
"_Atomic_thread_fence",
"#include <stdatomic.h>",
extra_args=std_args + [feature_flag],
)[0]:
self.compile_args = [feature_flag]
self.is_found = True


class AtomicSystemDependency(SystemDependency):
Expand Down
Loading