summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2023-10-16 16:02:28 -0700
committerDylan Baker <dylan@pnwbakers.com>2024-02-23 09:48:32 -0800
commite7f20efc8bd123bfc2c325198866850694612a23 (patch)
treef4c08b4bf94d9a429322f25a3ab9b1e1f39c539e
parent9752b89100a9ffc42a6eb4a788f806958bda1107 (diff)
downloadmeson-e7f20efc8bd123bfc2c325198866850694612a23.tar.gz
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.
-rw-r--r--docs/markdown/Rust-module.md1
-rw-r--r--mesonbuild/interpreter/interpreter.py2
-rw-r--r--mesonbuild/modules/rust.py4
-rw-r--r--test cases/rust/12 bindgen/meson.build9
-rw-r--r--test cases/rust/12 bindgen/test.json2
5 files changed, 13 insertions, 5 deletions
diff --git a/docs/markdown/Rust-module.md b/docs/markdown/Rust-module.md
index 0ed5410c7..11966ca8c 100644
--- a/docs/markdown/Rust-module.md
+++ b/docs/markdown/Rust-module.md
@@ -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')
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index 7e9fe4a55..5603b9937 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -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
diff --git a/mesonbuild/modules/rust.py b/mesonbuild/modules/rust.py
index 6a00fb3ce..fb8528088 100644
--- a/mesonbuild/modules/rust.py
+++ b/mesonbuild/modules/rust.py
@@ -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):
diff --git a/test cases/rust/12 bindgen/meson.build b/test cases/rust/12 bindgen/meson.build
index 09575815c..a88ed81de 100644
--- a/test cases/rust/12 bindgen/meson.build
+++ b/test cases/rust/12 bindgen/meson.build
@@ -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',
diff --git a/test cases/rust/12 bindgen/test.json b/test cases/rust/12 bindgen/test.json
index 25fafd2e1..a3b7e29f3 100644
--- a/test cases/rust/12 bindgen/test.json
+++ b/test cases/rust/12 bindgen/test.json
@@ -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]."
}
]
}