-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
e7f20ef
commit 0837553
Showing
2 changed files
with
32 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
from mesonbuild.interpreterbase.decorators import FeatureNew | ||
|
||
from . import ExtensionModule, ModuleReturnValue, ModuleInfo | ||
from .. import mlog | ||
from .. import mesonlib, mlog | ||
from ..build import (BothLibraries, BuildTarget, CustomTargetIndex, Executable, ExtractedObjects, GeneratedList, | ||
CustomTarget, InvalidArguments, Jar, StructuredSources, SharedLibrary) | ||
from ..compilers.compilers import are_asserts_disabled, lang_suffixes | ||
|
@@ -19,6 +19,7 @@ | |
) | ||
from ..interpreterbase import ContainerTypeInfo, InterpreterException, KwargInfo, typed_kwargs, typed_pos_args, noPosargs, permittedKwargs | ||
from ..mesonlib import File | ||
from ..programs import ExternalProgram | ||
|
||
if T.TYPE_CHECKING: | ||
from . import ModuleState | ||
|
@@ -27,7 +28,7 @@ | |
from ..interpreter import Interpreter | ||
from ..interpreter import kwargs as _kwargs | ||
from ..interpreter.interpreter import SourceInputs, SourceOutputs | ||
from ..programs import ExternalProgram, OverrideProgram | ||
from ..programs import OverrideProgram | ||
from ..interpreter.type_checking import SourcesVarargsType | ||
|
||
from typing_extensions import TypedDict, Literal | ||
|
@@ -46,6 +47,7 @@ class FuncBindgen(TypedDict): | |
include_directories: T.List[IncludeDirs] | ||
input: T.List[SourceInputs] | ||
output: str | ||
output_inline_wrapper: str | ||
dependencies: T.List[T.Union[Dependency, ExternalLibrary]] | ||
language: T.Optional[Literal['c', 'cpp']] | ||
bindgen_version: T.List[str] | ||
|
@@ -196,6 +198,12 @@ def test(self, state: ModuleState, args: T.Tuple[str, BuildTarget], kwargs: Func | |
KwargInfo('bindgen_version', ContainerTypeInfo(list, str), default=[], listify=True, since='1.4.0'), | ||
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: | ||
|
@@ -287,12 +295,27 @@ def bindgen(self, state: ModuleState, args: T.List, kwargs: FuncBindgen) -> Modu | |
if std != 'none': | ||
clang_args.append(f'-std={std}') | ||
|
||
inline_wrapper_args: T.List[str] = [] | ||
outputs = [kwargs['output']] | ||
if kwargs['output_inline_wrapper']: | ||
# Todo drop this isinstance once Executable supports version_compare | ||
if isinstance(self._bindgen_bin, ExternalProgram): | ||
if mesonlib.version_compare(self._bindgen_bin.get_version(), '< 0.65'): | ||
raise InterpreterException('\'output_inline_wrapper\' parameter of rust.bindgen requires bindgen-0.65 or newer') | ||
|
||
outputs.append(kwargs['output_inline_wrapper']) | ||
inline_wrapper_args = [ | ||
'--experimental', '--wrap-static-fns', | ||
'--wrap-static-fns-path', os.path.join(state.environment.build_dir, '@OUTPUT1@') | ||
] | ||
|
||
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( | ||
|
@@ -302,15 +325,15 @@ def bindgen(self, state: ModuleState, args: T.List, kwargs: FuncBindgen) -> Modu | |
state.environment, | ||
cmd, | ||
[header], | ||
[kwargs['output']], | ||
outputs, | ||
depfile='@[email protected]', | ||
extra_depends=depends, | ||
depend_files=depend_files, | ||
backend=state.backend, | ||
description='Generating bindings for Rust {}', | ||
) | ||
|
||
return ModuleReturnValue([target], [target]) | ||
return ModuleReturnValue(target, [target]) | ||
|
||
# Allow a limited set of kwargs, but still use the full set of typed_kwargs() | ||
# because it could be setting required default values. | ||
|