Skip to content

Commit

Permalink
dependencies: add custom atomic dependency
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dudemanguy committed Apr 11, 2023
1 parent eb472a1 commit 4a56692
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/markdown/Dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@ dep = dependency('appleframeworks', modules : 'foundation')

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

## atomic (stdatomic)

*(added 1.2.0)*

Provides access to the atomic operations library. On systems where
this is not provided by compiler-rt (i.e. gcc), this tries to find
an external library instead.

`method` may be `auto`, `builtin` or `system`.

## Blocks

Enable support for Clang's blocks extension.
Expand Down
9 changes: 9 additions & 0 deletions docs/markdown/snippets/atomic-dependency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## New custom dependency for atomic

```
dependency('atomic')
```

checks for the availability of the atomic operation library. First, it checks
if stdatomic is provided by compiler-rt (e.g. when using clang). If not, it
looks for the atomic library specifically.
3 changes: 2 additions & 1 deletion mesonbuild/dependencies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
BlocksDependency, OpenMPDependency, cups_factory, curses_factory, gpgme_factory,
libgcrypt_factory, libwmf_factory, netcdf_factory, pcap_factory,
shaderc_factory, threads_factory, ThreadDependency, iconv_factory, intl_factory,
dl_factory, openssl_factory, libcrypto_factory, libssl_factory,
atomic_factory, dl_factory, openssl_factory, libcrypto_factory, libssl_factory,
)
from .platform import AppleFrameworks
from .python import python_factory as python3_factory, pybind11_factory
Expand Down Expand Up @@ -260,6 +260,7 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
'shaderc': shaderc_factory,
'iconv': iconv_factory,
'intl': intl_factory,
'atomic': atomic_factory,
'dl': dl_factory,
'openssl': openssl_factory,
'libcrypto': libcrypto_factory,
Expand Down
28 changes: 28 additions & 0 deletions mesonbuild/dependencies/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ def netcdf_factory(env: 'Environment',
return candidates


class AtomicBuiltinDependency(BuiltinDependency):
def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
super().__init__(name, env, kwargs)
self.feature_since = ('1.2.0', "consider checking for `atomic_flag_clear` with and without `find_library('atomic')`")

if self.clib_compiler.has_function('atomic_flag_clear', '#include <stdatomic.h>', env)[0]:
self.is_found = True


class AtomicSystemDependency(SystemDependency):
def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
super().__init__(name, env, kwargs)
self.feature_since = ('1.2.0', "consider checking for `atomic_flag_clear` with and without `find_library('atomic')`")

h = self.clib_compiler.has_header('stdatomic.h', '', env)
self.link_args = self.clib_compiler.find_library('atomic', env, [], self.libtype)

if h[0] and self.link_args:
self.is_found = True


class DlBuiltinDependency(BuiltinDependency):
def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
super().__init__(name, env, kwargs)
Expand Down Expand Up @@ -526,6 +547,13 @@ def shaderc_factory(env: 'Environment',
return candidates


atomic_factory = DependencyFactory(
'atomic',
[DependencyMethods.BUILTIN, DependencyMethods.SYSTEM],
builtin_class=AtomicBuiltinDependency,
system_class=AtomicSystemDependency,
)

cups_factory = DependencyFactory(
'cups',
[DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.EXTRAFRAMEWORK, DependencyMethods.CMAKE],
Expand Down

0 comments on commit 4a56692

Please sign in to comment.