Otherwise we might not get things like libstdc++, which we need.pull/11902/head
parent
5d16bd5308
commit
772cb92624
6 changed files with 83 additions and 12 deletions
@ -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); |
||||
} |
@ -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); |
||||
|
@ -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 }) |
||||
} |
@ -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) |
Loading…
Reference in new issue