summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/c-from-rust/TARGETS2
-rw-r--r--test/c-from-rust/main.rs12
-rw-r--r--test/c-from-rust/rust_interface/TARGETS8
-rw-r--r--test/c-from-rust/rust_interface/foo.rs11
4 files changed, 22 insertions, 11 deletions
diff --git a/test/c-from-rust/TARGETS b/test/c-from-rust/TARGETS
index 9bec7d9..8547aa7 100644
--- a/test/c-from-rust/TARGETS
+++ b/test/c-from-rust/TARGETS
@@ -2,7 +2,7 @@
{ "type": ["@", "rules-rust", "rust", "binary"]
, "name": ["main"]
, "crate_root": ["main.rs"]
- , "deps": [["./", "clib", "foo"]]
+ , "deps": [["./", "rust_interface", "foo_rust"]]
}
, "c-from-rust":
{ "type": ["@", "rules-cc", "shell/test", "script"]
diff --git a/test/c-from-rust/main.rs b/test/c-from-rust/main.rs
index 961150a..081c9d9 100644
--- a/test/c-from-rust/main.rs
+++ b/test/c-from-rust/main.rs
@@ -1,19 +1,11 @@
use std::env;
-extern "C" {
- fn c_func(input: i32) -> i32;
-}
-
-fn c_call(i:i32) -> i32{
- unsafe {
- return c_func(i);
- }
-}
+extern crate foo_rust;
fn main() {
let args: Vec<String> = env::args().collect();
match args[1].parse::<i32>() {
- Ok(i) => println!("Absolute value of {} is {}",i, c_call(i)),
+ Ok(i) => println!("Absolute value of {} is {}", i, foo_rust::c_call(i)),
Err(..) => println!("Wrong argument {}",args[1]),
};
diff --git a/test/c-from-rust/rust_interface/TARGETS b/test/c-from-rust/rust_interface/TARGETS
new file mode 100644
index 0000000..2404f2b
--- /dev/null
+++ b/test/c-from-rust/rust_interface/TARGETS
@@ -0,0 +1,8 @@
+{ "foo_rust":
+ { "type": ["@", "rules-rust", "rust", "library"]
+ , "name": ["foo_rust"]
+ , "crate_root": ["foo.rs"]
+ , "stage": ["foo_rust"]
+ , "deps": [["./", "../clib", "foo"]]
+ }
+}
diff --git a/test/c-from-rust/rust_interface/foo.rs b/test/c-from-rust/rust_interface/foo.rs
new file mode 100644
index 0000000..acfe2a7
--- /dev/null
+++ b/test/c-from-rust/rust_interface/foo.rs
@@ -0,0 +1,11 @@
+// declaration of the function implemented in the C library
+extern "C" {
+ pub fn c_func(input: i32) -> i32;
+}
+
+// wrapper to call the C function
+pub fn c_call(i:i32) -> i32{
+ unsafe {
+ return c_func(i);
+ }
+}