diff options
| -rw-r--r-- | docs/markdown/snippets/rust-bindgen-std.md | 3 | ||||
| -rw-r--r-- | mesonbuild/modules/rust.py | 17 | ||||
| -rw-r--r-- | test cases/rust/12 bindgen/meson.build | 8 | ||||
| -rw-r--r-- | test cases/rust/12 bindgen/test.json | 2 |
4 files changed, 27 insertions, 3 deletions
diff --git a/docs/markdown/snippets/rust-bindgen-std.md b/docs/markdown/snippets/rust-bindgen-std.md new file mode 100644 index 000000000..2c94f9c2c --- /dev/null +++ b/docs/markdown/snippets/rust-bindgen-std.md @@ -0,0 +1,3 @@ +## Bindgen now uses the same C/C++ as the project as a whole + +Which is very important for C++ bindings. diff --git a/mesonbuild/modules/rust.py b/mesonbuild/modules/rust.py index 4978f1205..6a00fb3ce 100644 --- a/mesonbuild/modules/rust.py +++ b/mesonbuild/modules/rust.py @@ -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', diff --git a/test cases/rust/12 bindgen/meson.build b/test cases/rust/12 bindgen/meson.build index 840a8afab..09575815c 100644 --- a/test cases/rust/12 bindgen/meson.build +++ b/test cases/rust/12 bindgen/meson.build @@ -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() diff --git a/test cases/rust/12 bindgen/test.json b/test cases/rust/12 bindgen/test.json index d45543b13..25fafd2e1 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: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]." } ] } |
