modules/rust: inject a C/C++ standard for bindgen

Especially for C++ this is very important.
pull/12263/head
Dylan Baker 1 year ago
parent 05d49c6990
commit a75ced6d50
  1. 3
      docs/markdown/snippets/rust-bindgen-std.md
  2. 17
      mesonbuild/modules/rust.py
  3. 8
      test cases/rust/12 bindgen/meson.build
  4. 2
      test cases/rust/12 bindgen/test.json

@ -0,0 +1,3 @@
## Bindgen now uses the same C/C++ as the project as a whole
Which is very important for C++ bindings.

@ -268,6 +268,23 @@ class RustModule(ExtensionModule):
if language == 'cpp':
clang_args.extend(['-x', 'c++'])
# Add the C++ standard to the clang arguments. Attempt to translate VS
# extension versions into the nearest standard version
std = state.get_option('std', lang=language)
assert isinstance(std, str), 'for mypy'
if std.startswith('vc++'):
if std.endswith('latest'):
mlog.warning('Attempting to translate vc++latest into a clang compatible version.',
'Currently this is hardcoded for c++20', once=True, fatal=False)
std = 'c++20'
else:
mlog.debug('The current C++ standard is a Visual Studio extension version.',
'bindgen will use a the nearest C++ standard instead')
std = std[1:]
if std != 'none':
clang_args.append(f'-std={std}')
cmd = self._bindgen_bin.get_command() + \
[
'@INPUT@', '--output',

@ -1,7 +1,11 @@
# SPDX-license-identifer: Apache-2.0
# Copyright © 2021-2022 Intel Corporation
# Copyright © 2021-2024 Intel Corporation
project('rustmod bindgen', ['c', 'cpp', 'rust'], meson_version : '>= 0.63')
project(
'rustmod bindgen',
['c', 'cpp', 'rust'],
meson_version : '>= 0.63',
default_options : ['cpp_std=c++17'])
prog_bindgen = find_program('bindgen', required : false)
if not prog_bindgen.found()

@ -4,7 +4,7 @@
},
"stdout": [
{
"line": "test cases/rust/12 bindgen/meson.build:38: 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:42: 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