Skip to content

Commit f070670

Browse files
Dudemanguyeli-schwartz
authored andcommitted
dependencies: add custom atomic dependency
Almost exactly the same as how the dl dependency works. On certain systems (like BSDs that use clang), stdatomic is provided by compiler-rt and doesn't need a separate library explictly linked. On a typical GNU/LINUX system, atomic is a separate library that must be explictly found and linked against. So just add a builtin and system method for these two use cases.
1 parent a004672 commit f070670

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

docs/markdown/Dependencies.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,16 @@ dep = dependency('appleframeworks', modules : 'foundation')
317317

318318
These dependencies can never be found for non-OSX hosts.
319319

320+
## atomic (stdatomic)
321+
322+
*(added 1.7.0)*
323+
324+
Provides access to the atomic operations library. This first attempts
325+
to look for a valid atomic external library before trying to fallback
326+
to what is provided by the C runtime libraries.
327+
328+
`method` may be `auto`, `builtin` or `system`.
329+
320330
## Blocks
321331

322332
Enable support for Clang's blocks extension.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## New custom dependency for atomic
2+
3+
```
4+
dependency('atomic')
5+
```
6+
7+
checks for the availability of the atomic operation library. First, it looks
8+
for the atomic library. If that is not found, then it will try to use what is
9+
provided by the libc.

mesonbuild/dependencies/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
220220
'shaderc': 'misc',
221221
'iconv': 'misc',
222222
'intl': 'misc',
223+
'atomic': 'misc',
223224
'dl': 'misc',
224225
'openssl': 'misc',
225226
'libcrypto': 'misc',

mesonbuild/dependencies/misc.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@ def netcdf_factory(env: 'Environment',
5151
packages['netcdf'] = netcdf_factory
5252

5353

54+
class AtomicBuiltinDependency(BuiltinDependency):
55+
def __init__(self, name: str, env: Environment, kwargs: T.Dict[str, T.Any]):
56+
super().__init__(name, env, kwargs)
57+
self.feature_since = ('1.7.0', "consider checking for `atomic_flag_clear` with and without `find_library('atomic')`")
58+
59+
if self.clib_compiler.has_function('atomic_flag_clear', '#include <stdatomic.h>', env)[0]:
60+
self.is_found = True
61+
62+
63+
class AtomicSystemDependency(SystemDependency):
64+
def __init__(self, name: str, env: Environment, kwargs: T.Dict[str, T.Any]):
65+
super().__init__(name, env, kwargs)
66+
self.feature_since = ('1.7.0', "consider checking for `atomic_flag_clear` with and without `find_library('atomic')`")
67+
68+
h = self.clib_compiler.has_header('stdatomic.h', '', env)
69+
self.link_args = self.clib_compiler.find_library('atomic', env, [], self.libtype)
70+
71+
if h[0] and self.link_args:
72+
self.is_found = True
73+
74+
5475
class DlBuiltinDependency(BuiltinDependency):
5576
def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
5677
super().__init__(name, env, kwargs)
@@ -564,6 +585,13 @@ def shaderc_factory(env: 'Environment',
564585
packages['shaderc'] = shaderc_factory
565586

566587

588+
packages['atomic'] = atomic_factory = DependencyFactory(
589+
'atomic',
590+
[DependencyMethods.SYSTEM, DependencyMethods.BUILTIN],
591+
system_class=AtomicSystemDependency,
592+
builtin_class=AtomicBuiltinDependency,
593+
)
594+
567595
packages['cups'] = cups_factory = DependencyFactory(
568596
'cups',
569597
[DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.EXTRAFRAMEWORK, DependencyMethods.CMAKE],

0 commit comments

Comments
 (0)