aboutsummaryrefslogtreecommitdiff
path: root/test cases
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2023-06-22 11:43:35 -0700
committerDylan Baker <dylan@pnwbakers.com>2023-06-27 11:53:18 -0700
commit772cb926243e6c3506c48d4e636359f8de397135 (patch)
treea7463328b35010003de276b7ee0bbc3327522152 /test cases
parent5d16bd5308f0edd9d53b82ff6a961241c7188423 (diff)
downloadmeson-772cb926243e6c3506c48d4e636359f8de397135.zip
meson-772cb926243e6c3506c48d4e636359f8de397135.tar.gz
meson-772cb926243e6c3506c48d4e636359f8de397135.tar.bz2
rust: get stdlib arguments for non-rust languages when linking
Otherwise we might not get things like libstdc++, which we need.
Diffstat (limited to 'test cases')
-rw-r--r--test cases/rust/20 rust and cpp/lib.cpp18
-rw-r--r--test cases/rust/20 rust and cpp/lib.hpp8
-rw-r--r--test cases/rust/20 rust and cpp/main.rs19
-rw-r--r--test cases/rust/20 rust and cpp/meson.build14
4 files changed, 59 insertions, 0 deletions
diff --git a/test cases/rust/20 rust and cpp/lib.cpp b/test cases/rust/20 rust and cpp/lib.cpp
new file mode 100644
index 0000000..b08f870
--- /dev/null
+++ b/test cases/rust/20 rust and cpp/lib.cpp
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright © 2023 Intel Corporation
+
+#include "lib.hpp"
+
+#include <string>
+
+namespace {
+
+uint64_t priv_length(const std::string & str) {
+ return str.length();
+}
+
+}
+
+extern "C" uint64_t lib_length(const char * str) {
+ return priv_length(str);
+}
diff --git a/test cases/rust/20 rust and cpp/lib.hpp b/test cases/rust/20 rust and cpp/lib.hpp
new file mode 100644
index 0000000..63093c4
--- /dev/null
+++ b/test cases/rust/20 rust and cpp/lib.hpp
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright © 2023 Intel Corporation
+
+#include <cstddef>
+#include <cstdint>
+
+extern "C" uint64_t lib_length(const char * str);
+
diff --git a/test cases/rust/20 rust and cpp/main.rs b/test cases/rust/20 rust and cpp/main.rs
new file mode 100644
index 0000000..b048cac
--- /dev/null
+++ b/test cases/rust/20 rust and cpp/main.rs
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright © 2023 Intel Corporation
+
+use std::ffi::CString;
+use std::os::raw::c_char;
+
+extern "C" {
+ fn lib_length(s: *const c_char) -> u64;
+}
+
+fn main() {
+ let len: u64;
+ unsafe {
+ let c_str = CString::new("Hello, world!").unwrap();
+ len = lib_length(c_str.as_ptr());
+ }
+
+ std::process::exit(if len == 13 { 0 } else { 1 })
+}
diff --git a/test cases/rust/20 rust and cpp/meson.build b/test cases/rust/20 rust and cpp/meson.build
new file mode 100644
index 0000000..c301012
--- /dev/null
+++ b/test cases/rust/20 rust and cpp/meson.build
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: Apache-2.0
+# Copyright © 2023 Intel Corporation
+
+project(
+ 'Rust and C++',
+ 'rust', 'cpp',
+ default_options : ['cpp_std=c++14'],
+ meson_version : '>= 1.2.0',
+)
+
+cpplib = static_library('cpp', 'lib.cpp')
+exe = executable('main', 'main.rs', link_with : cpplib)
+
+test('main', exe)