diff options
author | Alberto Sartori <alberto.sartori@huawei.com> | 2024-07-22 12:20:46 +0200 |
---|---|---|
committer | Alberto Sartori <alberto.sartori@huawei.com> | 2024-07-23 15:41:45 +0200 |
commit | ed652442176aea086104479bb31aced501df48a2 (patch) | |
tree | 582322cce152505eaac16aff5442fcbefbbe3938 | |
parent | cda960a4cd846ca97f90b172014fd02206eb74a0 (diff) | |
download | rules-rust-ed652442176aea086104479bb31aced501df48a2.tar.gz |
rules-rust: bugfix: correctly propagate link args of C dependencies
-rw-r--r-- | rules/rust/EXPRESSIONS | 48 | ||||
-rw-r--r-- | test/c-from-rust/TARGETS | 2 | ||||
-rw-r--r-- | test/c-from-rust/main.rs | 12 | ||||
-rw-r--r-- | test/c-from-rust/rust_interface/TARGETS | 8 | ||||
-rw-r--r-- | test/c-from-rust/rust_interface/foo.rs | 11 |
5 files changed, 46 insertions, 35 deletions
diff --git a/rules/rust/EXPRESSIONS b/rules/rust/EXPRESSIONS index 3f23d41..7c5b922 100644 --- a/rules/rust/EXPRESSIONS +++ b/rules/rust/EXPRESSIONS @@ -1243,35 +1243,35 @@ } , "else": {"type": "empty_map"} } - , { "type": "if" - , "cond": - { "type": "==" - , "$1": {"type": "var", "name": "crate_type"} - , "$2": "staticlib" - } - , "then": - { "type": "singleton_map" - , "key": "link-args" - , "value": - { "type": "++" - , "$1": - [ [ { "type": "lookup" + , { "type": "singleton_map" + , "key": "link-args" + , "value": + { "type": "++" + , "$1": + [ { "type": "if" + , "cond": + { "type": "==" + , "$1": {"type": "var", "name": "crate_type"} + , "$2": "staticlib" + } + , "then": + [ { "type": "lookup" , "key": "artifact-name" , "map": {"type": "var", "name": "link result"} } ] - , { "type": "lookup" - , "key": "c-deps-link-args" - , "map": {"type": "var", "name": "link result"} - } - , { "type": "lookup" - , "key": "c-deps-run-libs-args" - , "map": {"type": "var", "name": "link result"} - } - ] - } + , "else": [] + } + , { "type": "lookup" + , "key": "c-deps-link-args" + , "map": {"type": "var", "name": "link result"} + } + , { "type": "lookup" + , "key": "c-deps-run-libs-args" + , "map": {"type": "var", "name": "link result"} + } + ] } - , "else": {"type": "empty_map"} } ] } 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); + } +} |