forked from mesonbuild/meson
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rust: get stdlib arguments for non-rust languages when linking
Otherwise we might not get things like libstdc++, which we need.
- Loading branch information
Showing
6 changed files
with
83 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |