diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2023-02-22 23:33:51 -0500 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2023-03-09 15:13:46 -0500 |
commit | 62c269d08859747ba558e90bc98505e6325ef678 (patch) | |
tree | fde98d5a628c0ce9d81a2e50538dbce3f7031531 | |
parent | 162ac25beb001b52d741d7b8c6f13e26c937b1e3 (diff) | |
download | meson-62c269d08859747ba558e90bc98505e6325ef678.zip meson-62c269d08859747ba558e90bc98505e6325ef678.tar.gz meson-62c269d08859747ba558e90bc98505e6325ef678.tar.bz2 |
dependencies: add pybind11 custom factory
This works with pkg-config and cmake without any special support. The
custom factory adds further support for config-tool, via
`pybind11-config`. This is useful because the config-tool will work out
of the box when pybind11 is installed, but the pkg-config and cmake
files are shoved into python's site-packages, which is an unfortunate
distribution model and makes it impossible to use in an out of the box
manner.
It's possible to manually set up the PKG_CONFIG_PATH to detect it
anyway, but in case that does not happen, having the config-tool
fallback is extremely useful.
-rw-r--r-- | docs/markdown/Dependencies.md | 6 | ||||
-rw-r--r-- | docs/markdown/snippets/pybind11_dep.md | 9 | ||||
-rw-r--r-- | mesonbuild/dependencies/__init__.py | 3 | ||||
-rw-r--r-- | mesonbuild/dependencies/python.py | 23 |
4 files changed, 40 insertions, 1 deletions
diff --git a/docs/markdown/Dependencies.md b/docs/markdown/Dependencies.md index 88a1dbd..d95b835 100644 --- a/docs/markdown/Dependencies.md +++ b/docs/markdown/Dependencies.md @@ -659,6 +659,12 @@ The `language` keyword may used. `method` may be `auto`, `config-tool` or `pkg-config`. +## Pybind11 + +*(added 1.1.0)* + +`method` may be `auto`, `pkg-config`, `config-tool`, or `cmake`. + ## Python3 Python3 is handled specially by Meson: diff --git a/docs/markdown/snippets/pybind11_dep.md b/docs/markdown/snippets/pybind11_dep.md new file mode 100644 index 0000000..ac19701 --- /dev/null +++ b/docs/markdown/snippets/pybind11_dep.md @@ -0,0 +1,9 @@ +## New pybind11 custom dependency + +`dependency('pybind11')` works with pkg-config and cmake without any special +support, but did not handle the `pybind11-config` script. + +This is useful because the config-tool will work out of the box when pybind11 +is installed, but the pkg-config and cmake files are shoved into python's +site-packages, which makes it impossible to use in an out of the box manner. + diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py index 406228d..36f4e72 100644 --- a/mesonbuild/dependencies/__init__.py +++ b/mesonbuild/dependencies/__init__.py @@ -39,7 +39,7 @@ from .misc import ( dl_factory, openssl_factory, libcrypto_factory, libssl_factory, ) from .platform import AppleFrameworks -from .python import python_factory as python3_factory +from .python import python_factory as python3_factory, pybind11_factory from .qt import qt4_factory, qt5_factory, qt6_factory from .ui import GnuStepDependency, WxDependency, gl_factory, sdl2_factory, vulkan_factory @@ -270,6 +270,7 @@ packages.update({ # from python: 'python3': python3_factory, + 'pybind11': pybind11_factory, # From ui: 'gl': gl_factory, diff --git a/mesonbuild/dependencies/python.py b/mesonbuild/dependencies/python.py index 478df6a..eaa9067 100644 --- a/mesonbuild/dependencies/python.py +++ b/mesonbuild/dependencies/python.py @@ -19,6 +19,8 @@ import typing as T from .. import mesonlib, mlog from .base import process_method_kw, DependencyMethods, DependencyTypeName, ExternalDependency, SystemDependency +from .configtool import ConfigToolDependency +from .factory import DependencyFactory from .framework import ExtraFrameworkDependency from .pkgconfig import PkgConfigDependency from ..environment import detect_cpu_family @@ -49,6 +51,21 @@ else: _Base = object +class Pybind11ConfigToolDependency(ConfigToolDependency): + + tools = ['pybind11-config'] + + # pybind11 in 2.10.4 added --version, sanity-check another flag unique to it + # in the meantime + skip_version = '--pkgconfigdir' + + def __init__(self, name: str, environment: Environment, kwargs: T.Dict[str, T.Any]): + super().__init__(name, environment, kwargs) + if not self.is_found: + return + self.compile_args = self.get_config_value(['--includes'], 'compile_args') + + class BasicPythonExternalProgram(ExternalProgram): def __init__(self, name: str, command: T.Optional[T.List[str]] = None, ext_prog: T.Optional[ExternalProgram] = None): @@ -371,3 +388,9 @@ def python_factory(env: 'Environment', for_machine: 'MachineChoice', candidates.append(functools.partial(PythonFrameworkDependency, 'Python', env, nkwargs, installation)) return candidates + +pybind11_factory = DependencyFactory( + 'pybind11', + [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.CMAKE], + configtool_class=Pybind11ConfigToolDependency, +) |