modules/rust: allow setting a version constraint on bindgen

This allows us to ensure that the bindgen we're using is suitable for
our purpose.
pull/12263/head
Dylan Baker 1 year ago
parent 9752b89100
commit e7f20efc8b
  1. 1
      docs/markdown/Rust-module.md
  2. 2
      mesonbuild/interpreter/interpreter.py
  3. 4
      mesonbuild/modules/rust.py
  4. 9
      test cases/rust/12 bindgen/meson.build
  5. 2
      test cases/rust/12 bindgen/test.json

@ -63,6 +63,7 @@ It takes the following keyword arguments
- `args`: a list of string arguments to pass to `bindgen` untouched.
- `dependencies`: a list of `Dependency` objects to pass to the underlying clang call (*since 1.0.0*)
- `language`: A literal string value of `c` or `cpp`. When set this will force bindgen to treat a source as the given language. Defaults to checking based on the input file extension. *(since 1.4.0)*
- `bindgen_version`: a list of string version values. When set the found bindgen binary must conform to these constraints. *(since 1.4.0)*
```meson
rust = import('unstable-rust')

@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2012-2021 The Meson development team
# Copyright © 2023 Intel Corporation
# Copyright © 2023-2024 Intel Corporation
from __future__ import annotations

@ -48,6 +48,7 @@ if T.TYPE_CHECKING:
output: str
dependencies: T.List[T.Union[Dependency, ExternalLibrary]]
language: T.Optional[Literal['c', 'cpp']]
bindgen_version: T.List[str]
class RustModule(ExtensionModule):
@ -192,6 +193,7 @@ class RustModule(ExtensionModule):
required=True,
),
KwargInfo('language', (str, NoneType), since='1.4.0', validator=in_set_validator({'c', 'cpp'})),
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,
DEPENDENCIES_KW.evolve(since='1.0.0'),
@ -236,7 +238,7 @@ class RustModule(ExtensionModule):
depends.append(s)
if self._bindgen_bin is None:
self._bindgen_bin = state.find_program('bindgen')
self._bindgen_bin = state.find_program('bindgen', wanted=kwargs['bindgen_version'])
name: str
if isinstance(header, File):

@ -32,13 +32,18 @@ if result.returncode() != 0
error('MESON_SKIP_TEST bindgen does not seem to work')
endif
rust = import('unstable-rust')
# Check version, this case is obviously impossible
testcase expect_error('Program \'bindgen\' not found or not executable')
rust.bindgen(input : 'include/other.h', output : 'other.rs', bindgen_version : ['< 0.1', '> 10000'])
endtestcase
# This is to test the include_directories argument to bindgen
inc = include_directories('include')
c_lib = static_library('clib', 'src/source.c', include_directories : inc)
rust = import('unstable-rust')
gen = rust.bindgen(
input : 'src/header.h',
output : 'header.rs',

@ -4,7 +4,7 @@
},
"stdout": [
{
"line": "test cases/rust/12 bindgen/meson.build:42: WARNING: Project targets '>= 0.63' but uses feature introduced in '1.0.0': \"rust.bindgen\" keyword argument \"include_directories\" of type array[str]."
"line": "test cases/rust/12 bindgen/meson.build:47: WARNING: Project targets '>= 0.63' but uses feature introduced in '1.0.0': \"rust.bindgen\" keyword argument \"include_directories\" of type array[str]."
}
]
}

Loading…
Cancel
Save