From 491c2bfa26fc5a96f7a49af969a24d69bf090671 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Sun, 17 Sep 2023 12:12:13 +0200 Subject: [PATCH] meson/rust: wrap `bindgen`s `wrap-static-fns` functionality This way the `rust.bindgen` can generate a second output being a C file, which contains wrapper functions for static inline ones. This output file can then be compiled via C targets. --- docs/markdown/Rust-module.md | 4 ++++ mesonbuild/modules/rust.py | 24 ++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/markdown/Rust-module.md b/docs/markdown/Rust-module.md index bbc92fc2582c..d433a4e710bd 100644 --- a/docs/markdown/Rust-module.md +++ b/docs/markdown/Rust-module.md @@ -57,6 +57,10 @@ It takes the following keyword arguments - `input`: a list of Files, Strings, or CustomTargets. The first element is the header bindgen will parse, additional elements are dependencies. - `output`: the name of the output rust file +- `output_inline_wrapper`: the name of the optional output c file containing + wrappers for static inline function. Setting this will instruct `bindgen` to + generate it by adding the relevant arguments to `args`. This requires + `bindgen` `0.64` or newer (*since 1.3.0*). - `include_directories`: A list of `include_directories` or `string` objects, these are passed to clang as `-I` arguments *(string since 1.0.0)* - `c_args`: a list of string arguments to pass to clang untouched diff --git a/mesonbuild/modules/rust.py b/mesonbuild/modules/rust.py index 0bda2c250bce..a8ae0fa5716c 100644 --- a/mesonbuild/modules/rust.py +++ b/mesonbuild/modules/rust.py @@ -191,6 +191,12 @@ def test(self, state: ModuleState, args: T.Tuple[str, BuildTarget], kwargs: Func ), INCLUDE_DIRECTORIES.evolve(since_values={ContainerTypeInfo(list, str): '1.0.0'}), OUTPUT_KW, + KwargInfo( + 'output_inline_wrapper', + str, + default='', + since='1.3.0', + ), DEPENDENCIES_KW.evolve(since='1.0.0'), ) def bindgen(self, state: ModuleState, args: T.List, kwargs: FuncBindgen) -> ModuleReturnValue: @@ -243,12 +249,22 @@ def bindgen(self, state: ModuleState, args: T.List, kwargs: FuncBindgen) -> Modu else: name = header.get_outputs()[0] + inline_wrapper_args = [] + outputs = [kwargs['output']] + if kwargs['output_inline_wrapper']: + outputs.append(kwargs['output_inline_wrapper']) + inline_wrapper_args = [ + '--experimental', '--wrap-static-fns', + '--wrap-static-fns-path', os.path.join(state.environment.build_dir, state.subdir, kwargs['output_inline_wrapper']) + ] + cmd = self._bindgen_bin.get_command() + \ [ '@INPUT@', '--output', - os.path.join(state.environment.build_dir, '@OUTPUT@') + os.path.join(state.environment.build_dir, '@OUTPUT0@') ] + \ - kwargs['args'] + ['--'] + kwargs['c_args'] + clang_args + \ + kwargs['args'] + inline_wrapper_args + ['--'] + \ + kwargs['c_args'] + clang_args + \ ['-MD', '-MQ', '@INPUT@', '-MF', '@DEPFILE@'] target = CustomTarget( @@ -258,7 +274,7 @@ def bindgen(self, state: ModuleState, args: T.List, kwargs: FuncBindgen) -> Modu state.environment, cmd, [header], - [kwargs['output']], + outputs, depfile='@PLAINNAME@.d', extra_depends=depends, depend_files=depend_files, @@ -266,7 +282,7 @@ def bindgen(self, state: ModuleState, args: T.List, kwargs: FuncBindgen) -> Modu description='Generating bindings for Rust {}', ) - return ModuleReturnValue([target], [target]) + return ModuleReturnValue(target, [target]) def initialize(interp: Interpreter) -> RustModule: