diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2023-10-16 10:00:52 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2024-02-23 09:48:32 -0800 |
commit | 6a8330af598753d5982a37933beeac2d6b565386 (patch) | |
tree | 8d1ffe03bc0b110f4f6e0389bfd4c73c051523f4 /test cases/rust | |
parent | 2c7833b1c9e77d244bdbfc2b96422854f36fc68c (diff) | |
download | meson-6a8330af598753d5982a37933beeac2d6b565386.zip meson-6a8330af598753d5982a37933beeac2d6b565386.tar.gz meson-6a8330af598753d5982a37933beeac2d6b565386.tar.bz2 |
rust/bindgen: Use Meson rules for C++ headers
Bindgen natively only considers .hpp to be C++ headers, but Meson
considers some additional extensions including .hh and .hxx to be C++.
Diffstat (limited to 'test cases/rust')
-rw-r--r-- | test cases/rust/12 bindgen/meson.build | 16 | ||||
-rw-r--r-- | test cases/rust/12 bindgen/src/cpp.rs | 19 | ||||
-rw-r--r-- | test cases/rust/12 bindgen/src/header.hpp | 9 | ||||
-rw-r--r-- | test cases/rust/12 bindgen/src/impl.cpp | 7 |
4 files changed, 50 insertions, 1 deletions
diff --git a/test cases/rust/12 bindgen/meson.build b/test cases/rust/12 bindgen/meson.build index e36e9e2..840a8af 100644 --- a/test cases/rust/12 bindgen/meson.build +++ b/test cases/rust/12 bindgen/meson.build @@ -1,7 +1,7 @@ # SPDX-license-identifer: Apache-2.0 # Copyright © 2021-2022 Intel Corporation -project('rustmod bindgen', ['c', 'rust'], meson_version : '>= 0.63') +project('rustmod bindgen', ['c', 'cpp', 'rust'], meson_version : '>= 0.63') prog_bindgen = find_program('bindgen', required : false) if not prog_bindgen.found() @@ -107,3 +107,17 @@ gp_exe = executable( ) test('global and project arguments', gp_exe) + +cpp_lib = static_library('cpplib', 'src/impl.cpp') + +cpp_bind = rust.bindgen( + input : 'src/header.hpp', + output : 'generated-cpp.rs', +) + +cpp_exe = executable( + 'cpp_exe', + structured_sources(['src/cpp.rs', cpp_bind]), + link_with : cpp_lib, +) +test('cpp', cpp_exe) diff --git a/test cases/rust/12 bindgen/src/cpp.rs b/test cases/rust/12 bindgen/src/cpp.rs new file mode 100644 index 0000000..51a594c --- /dev/null +++ b/test cases/rust/12 bindgen/src/cpp.rs @@ -0,0 +1,19 @@ +// SPDX-license-identifer: Apache-2.0 +// Copyright © 2023 Intel Corporation + +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] + +include!("generated-cpp.rs"); + +fn main() { + let mut instance = std::mem::MaybeUninit::<MyClass>::uninit(); + let val: i32; + unsafe { + MyClass_MyClass(instance.as_mut_ptr()); + val = instance.assume_init_mut().method(); + } + let success = val == 7; + std::process::exit(!success as i32); +} diff --git a/test cases/rust/12 bindgen/src/header.hpp b/test cases/rust/12 bindgen/src/header.hpp new file mode 100644 index 0000000..3f01c5f --- /dev/null +++ b/test cases/rust/12 bindgen/src/header.hpp @@ -0,0 +1,9 @@ +#pragma once + +class MyClass { + public: + MyClass(); + int method() const; + private: + int val; +}; diff --git a/test cases/rust/12 bindgen/src/impl.cpp b/test cases/rust/12 bindgen/src/impl.cpp new file mode 100644 index 0000000..39c8f2e --- /dev/null +++ b/test cases/rust/12 bindgen/src/impl.cpp @@ -0,0 +1,7 @@ +#include "header.hpp" + +MyClass::MyClass() : val{7} {}; + +int MyClass::method() const { + return val; +} |