From f87ad41f72ca4465a0c5b4ba9fd36a7b09e4d4f4 Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Mon, 24 Jun 2024 15:49:36 +0200 Subject: Initial commit Co-authored-by: Klaus Aehlig --- test/rust-from-c/foo/TARGETS | 15 +++++++++++++++ test/rust-from-c/foo/bar.rs | 3 +++ test/rust-from-c/foo/foo.h | 2 ++ test/rust-from-c/foo/foo.rs | 6 ++++++ test/rust-from-c/foo/foo_test.rs | 11 +++++++++++ 5 files changed, 37 insertions(+) create mode 100644 test/rust-from-c/foo/TARGETS create mode 100644 test/rust-from-c/foo/bar.rs create mode 100644 test/rust-from-c/foo/foo.h create mode 100644 test/rust-from-c/foo/foo.rs create mode 100644 test/rust-from-c/foo/foo_test.rs (limited to 'test/rust-from-c/foo') diff --git a/test/rust-from-c/foo/TARGETS b/test/rust-from-c/foo/TARGETS new file mode 100644 index 0000000..17c66ba --- /dev/null +++ b/test/rust-from-c/foo/TARGETS @@ -0,0 +1,15 @@ +{ "foo": + { "type": ["rules/rust", "library"] + , "name": ["foo"] + , "crate_root": ["foo.rs"] + , "c_hdrs": ["foo.h"] + , "stage": ["foo"] + , "deps": ["bar"] + } +, "bar": + { "type": ["rules/rust", "library"] + , "name": ["bar"] + , "crate_root": ["bar.rs"] + , "stage": ["bar"] + } +} diff --git a/test/rust-from-c/foo/bar.rs b/test/rust-from-c/foo/bar.rs new file mode 100644 index 0000000..61e68f4 --- /dev/null +++ b/test/rust-from-c/foo/bar.rs @@ -0,0 +1,3 @@ +pub fn bar(x: i32) -> i32 { + return x.abs(); +} \ No newline at end of file diff --git a/test/rust-from-c/foo/foo.h b/test/rust-from-c/foo/foo.h new file mode 100644 index 0000000..88deb2e --- /dev/null +++ b/test/rust-from-c/foo/foo.h @@ -0,0 +1,2 @@ +#pragma once +int foo(int); diff --git a/test/rust-from-c/foo/foo.rs b/test/rust-from-c/foo/foo.rs new file mode 100644 index 0000000..8735b67 --- /dev/null +++ b/test/rust-from-c/foo/foo.rs @@ -0,0 +1,6 @@ +extern crate bar; + +#[no_mangle] +pub extern "C" fn foo(x: i32) -> i32 { + return bar::bar(x); +} diff --git a/test/rust-from-c/foo/foo_test.rs b/test/rust-from-c/foo/foo_test.rs new file mode 100644 index 0000000..8b5de77 --- /dev/null +++ b/test/rust-from-c/foo/foo_test.rs @@ -0,0 +1,11 @@ +extern crate foo; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_foo(){ + assert_eq!(foo::foo(-7),7); + } +} \ No newline at end of file -- cgit v1.2.3