summaryrefslogtreecommitdiff
path: root/mesonbuild/modules/rust.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-02-26 09:48:52 -0800
committerEli Schwartz <eschwartz93@gmail.com>2025-02-27 15:27:42 -0500
commita7d248d58054b763fd6114d73a0587565a0d1646 (patch)
tree69d10cdf65b0b6c0968f1bbf2b98139294173186 /mesonbuild/modules/rust.py
parent95dd7499f32742011523ec763be53eefa221f883 (diff)
downloadmeson-a7d248d58054b763fd6114d73a0587565a0d1646.tar.gz
modules/rust: set --rust-edition for bindgen >= 0.71
But only if the user hasn't manually set it.
Diffstat (limited to 'mesonbuild/modules/rust.py')
-rw-r--r--mesonbuild/modules/rust.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/mesonbuild/modules/rust.py b/mesonbuild/modules/rust.py
index 34a3f68d8..0891243eb 100644
--- a/mesonbuild/modules/rust.py
+++ b/mesonbuild/modules/rust.py
@@ -66,6 +66,7 @@ class RustModule(ExtensionModule):
self._bindgen_rust_target: T.Optional[str] = interpreter.compilers.host['rust'].version
else:
self._bindgen_rust_target = None
+ self._bindgen_set_std = False
self.methods.update({
'test': self.test,
'bindgen': self.bindgen,
@@ -266,6 +267,10 @@ class RustModule(ExtensionModule):
if 'Got an invalid' in err or 'is not a valid Rust target' in err:
self._bindgen_rust_target = None
+ # TODO: Executable needs to learn about get_version
+ if isinstance(self._bindgen_bin, ExternalProgram):
+ self._bindgen_set_std = mesonlib.version_compare(self._bindgen_bin.get_version(), '>= 0.71')
+
name: str
if isinstance(header, File):
name = header.fname
@@ -335,6 +340,11 @@ class RustModule(ExtensionModule):
kwargs['args'] + inline_wrapper_args
if self._bindgen_rust_target and '--rust-target' not in cmd:
cmd.extend(['--rust-target', self._bindgen_rust_target])
+ if self._bindgen_set_std and '--rust-edition' not in cmd:
+ rust_std = state.environment.coredata.optstore.get_value('rust_std')
+ assert isinstance(rust_std, str), 'for mypy'
+ if rust_std != 'none':
+ cmd.extend(['--rust-edition', rust_std])
cmd.append('--')
cmd.extend(kwargs['c_args'])
cmd.extend(clang_args)