modules/rust: Add support for string include_directories

Which we support for basically every other case, but not this one.
pull/11024/head
Dylan Baker 2 years ago committed by Eli Schwartz
parent 3a0d6f65b0
commit bb875280b6
  1. 8
      docs/markdown/Rust-module.md
  2. 4
      docs/markdown/snippets/rust_bindgen_str_include.md
  3. 6
      mesonbuild/modules/rust.py
  4. 4
      test cases/rust/12 bindgen/meson.build
  5. 7
      test cases/rust/12 bindgen/test.json

@ -3,7 +3,7 @@ short-description: Rust language integration module
authors: authors:
- name: Dylan Baker - name: Dylan Baker
email: dylan@pnwbakers.com email: dylan@pnwbakers.com
years: [2020, 2021] years: [2020, 2021, 2022]
... ...
# Rust module # Rust module
@ -35,7 +35,7 @@ that automatically.
Additional, test only dependencies may be passed via the dependencies Additional, test only dependencies may be passed via the dependencies
argument. argument.
### bindgen(*, input: string | BuildTarget | [](string | BuildTarget), output: string, include_directories: []include_directories, c_args: []string, args: []string) ### bindgen(*, input: string | BuildTarget | [](string | BuildTarget), output: string, include_directories: [](include_directories | string), c_args: []string, args: []string)
This function wraps bindgen to simplify creating rust bindings around C This function wraps bindgen to simplify creating rust bindings around C
libraries. This has two advantages over hand-rolling ones own with a libraries. This has two advantages over hand-rolling ones own with a
@ -50,8 +50,8 @@ It takes the following keyword arguments
- input — A list of Files, Strings, or CustomTargets. The first element is - input — A list of Files, Strings, or CustomTargets. The first element is
the header bindgen will parse, additional elements are dependencies. the header bindgen will parse, additional elements are dependencies.
- output — the name of the output rust file - output — the name of the output rust file
- include_directories — A list of `include_directories` objects, these are - include_directories — A list of `include_directories` or `string` objects,
passed to clang as `-I` arguments 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 - c_args — A list of string arguments to pass to clang untouched
- args — A list of string arguments to pass to `bindgen` untouched. - args — A list of string arguments to pass to `bindgen` untouched.

@ -0,0 +1,4 @@
## String arguments to the rust.bindgen include_directories argument
Most other cases of include_directories accept strings as well as
`IncludeDirectory` objects, so lets do that here too for consistancy.

@ -19,7 +19,7 @@ from . import ExtensionModule, ModuleReturnValue, ModuleInfo
from .. import mlog from .. import mlog
from ..build import BothLibraries, BuildTarget, CustomTargetIndex, Executable, ExtractedObjects, GeneratedList, IncludeDirs, CustomTarget, StructuredSources from ..build import BothLibraries, BuildTarget, CustomTargetIndex, Executable, ExtractedObjects, GeneratedList, IncludeDirs, CustomTarget, StructuredSources
from ..dependencies import Dependency, ExternalLibrary from ..dependencies import Dependency, ExternalLibrary
from ..interpreter.type_checking import TEST_KWS, OUTPUT_KW from ..interpreter.type_checking import TEST_KWS, OUTPUT_KW, INCLUDE_DIRECTORIES, include_dir_string_new
from ..interpreterbase import ContainerTypeInfo, InterpreterException, KwargInfo, typed_kwargs, typed_pos_args, noPosargs from ..interpreterbase import ContainerTypeInfo, InterpreterException, KwargInfo, typed_kwargs, typed_pos_args, noPosargs
from ..mesonlib import File from ..mesonlib import File
@ -167,7 +167,6 @@ class RustModule(ExtensionModule):
'rust.bindgen', 'rust.bindgen',
KwargInfo('c_args', ContainerTypeInfo(list, str), default=[], listify=True), KwargInfo('c_args', ContainerTypeInfo(list, str), default=[], listify=True),
KwargInfo('args', ContainerTypeInfo(list, str), default=[], listify=True), KwargInfo('args', ContainerTypeInfo(list, str), default=[], listify=True),
KwargInfo('include_directories', ContainerTypeInfo(list, IncludeDirs), default=[], listify=True),
KwargInfo( KwargInfo(
'input', 'input',
ContainerTypeInfo(list, (File, GeneratedList, BuildTarget, BothLibraries, ExtractedObjects, CustomTargetIndex, CustomTarget, str), allow_empty=False), ContainerTypeInfo(list, (File, GeneratedList, BuildTarget, BothLibraries, ExtractedObjects, CustomTargetIndex, CustomTarget, str), allow_empty=False),
@ -175,6 +174,7 @@ class RustModule(ExtensionModule):
listify=True, listify=True,
required=True, required=True,
), ),
INCLUDE_DIRECTORIES.evolve(feature_validator=include_dir_string_new),
OUTPUT_KW, OUTPUT_KW,
) )
def bindgen(self, state: 'ModuleState', args: T.List, kwargs: 'FuncBindgen') -> ModuleReturnValue: def bindgen(self, state: 'ModuleState', args: T.List, kwargs: 'FuncBindgen') -> ModuleReturnValue:
@ -195,7 +195,7 @@ class RustModule(ExtensionModule):
depends.append(d) depends.append(d)
inc_strs: T.List[str] = [] inc_strs: T.List[str] = []
for i in kwargs['include_directories']: for i in state.process_include_dirs(kwargs['include_directories']):
# bindgen always uses clang, so it's safe to hardcode -I here # bindgen always uses clang, so it's safe to hardcode -I here
inc_strs.extend([f'-I{x}' for x in i.to_string_list( inc_strs.extend([f'-I{x}' for x in i.to_string_list(
state.environment.get_source_dir(), state.environment.get_build_dir())]) state.environment.get_source_dir(), state.environment.get_build_dir())])

@ -1,7 +1,7 @@
# SPDX-license-identifer: Apache-2.0 # SPDX-license-identifer: Apache-2.0
# Copyright © 2021 Intel Corporation # Copyright © 2021 Intel Corporation
project('rustmod bindgen', ['c', 'rust']) project('rustmod bindgen', ['c', 'rust'], meson_version : '>= 0.63')
prog_bindgen = find_program('bindgen', required : false) prog_bindgen = find_program('bindgen', required : false)
if not prog_bindgen.found() if not prog_bindgen.found()
@ -27,7 +27,7 @@ rust = import('unstable-rust')
gen = rust.bindgen( gen = rust.bindgen(
input : 'src/header.h', input : 'src/header.h',
output : 'header.rs', output : 'header.rs',
include_directories : inc, include_directories : 'include',
) )
# see: https://github.com/mesonbuild/meson/issues/8160 # see: https://github.com/mesonbuild/meson/issues/8160

@ -0,0 +1,7 @@
{
"stdout": [
{
"line": "test cases/rust/12 bindgen/meson.build:30: WARNING: Project targets '>= 0.63' but uses feature introduced in '1.0.0': include_directories kwarg of type string. Use include_directories('include') instead"
}
]
}
Loading…
Cancel
Save