Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dependencies: add custom atomic dependency #11445

Merged
merged 1 commit into from
Dec 30, 2024
Merged
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
10 changes: 10 additions & 0 deletions docs/markdown/Dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ dep = dependency('appleframeworks', modules : 'foundation')

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

## atomic (stdatomic)

*(added 1.7.0)*

Provides access to the atomic operations library. This first attempts
to look for a valid atomic external library before trying to fallback
to what is provided by the C runtime libraries.

`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 looks
for the atomic library. If that is not found, then it will try to use what is
provided by the libc.
1 change: 1 addition & 0 deletions mesonbuild/dependencies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
'shaderc': 'misc',
'iconv': 'misc',
'intl': 'misc',
'atomic': 'misc',
'dl': 'misc',
'openssl': 'misc',
'libcrypto': 'misc',
Expand Down
28 changes: 28 additions & 0 deletions mesonbuild/dependencies/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ def netcdf_factory(env: 'Environment',
packages['netcdf'] = netcdf_factory


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.7.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.7.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 @@ -564,6 +585,13 @@ def shaderc_factory(env: 'Environment',
packages['shaderc'] = shaderc_factory


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

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