diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-10-26 09:15:54 +0100 |
|---|---|---|
| committer | Paolo Bonzini <pbonzini@redhat.com> | 2025-12-22 12:01:05 +0100 |
| commit | 254d7e1c48f3a2d0837439f07628cfd54e47367b (patch) | |
| tree | 7c5deb63b2c3ae70db943d450d123e60645c9f78 /mesonbuild/modules | |
| parent | 2a5370fa85397473e98a09779fc4c7a56e048959 (diff) | |
| download | meson-254d7e1c48f3a2d0837439f07628cfd54e47367b.tar.gz | |
rust: add to_system_dependency
Move the logic for system dependencies outside Cargo.interpreter and
into the rust module, so that it can be reused by the workspace object.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild/modules')
| -rw-r--r-- | mesonbuild/modules/rust.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/mesonbuild/modules/rust.py b/mesonbuild/modules/rust.py index 0ea1c8f7e..5ba2a5f17 100644 --- a/mesonbuild/modules/rust.py +++ b/mesonbuild/modules/rust.py @@ -15,6 +15,7 @@ from .. import mesonlib, mlog from ..build import (BothLibraries, BuildTarget, CustomTargetIndex, Executable, ExtractedObjects, GeneratedList, CustomTarget, InvalidArguments, Jar, StructuredSources, SharedLibrary, StaticLibrary) from ..compilers.compilers import are_asserts_disabled_for_subproject, lang_suffixes +from ..compilers.rust import RustSystemDependency from ..dependencies import Dependency from ..interpreter.type_checking import ( DEPENDENCIES_KW, LINK_WITH_KW, LINK_WHOLE_KW, SHARED_LIB_KWS, TEST_KWS, TEST_KWS_NO_ARGS, @@ -259,6 +260,7 @@ class RustModule(ExtensionModule): 'doctest': self.doctest, 'bindgen': self.bindgen, 'proc_macro': self.proc_macro, + 'to_system_dependency': self.to_system_dependency, 'workspace': self.workspace, }) @@ -657,6 +659,21 @@ class RustModule(ExtensionModule): target = state._interpreter.build_target(state.current_node, args, kwargs, SharedLibrary) return target + @FeatureNew('rust.to_system_dependency', '1.11.0') + @typed_pos_args('rust.to_system_dependency', Dependency, optargs=[str]) + @noKwargs + def to_system_dependency(self, state: ModuleState, args: T.Tuple[Dependency, T.Optional[str]], kwargs: TYPE_kwargs) -> Dependency: + dep, depname = args + if not dep.found(): + return dep + if not depname: + if not dep.name: + raise MesonException("rust.to_system_dependency() called with an unnamed dependency and no explicit name") + depname = dep.name + depname = re.sub(r'[^a-zA-Z0-9]', '_', depname) + rust_args = ['--cfg', f'system_deps_have_{depname}'] + return RustSystemDependency(dep.version, compile_args=rust_args, ext_deps=[dep], name=dep.name) + @FeatureNew('rust.workspace', '1.11.0') @noPosargs @typed_kwargs( |
