From b6ed301feb4b223a8c0faa9dd979a722b6e04555 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 10 Nov 2021 22:43:37 +0800 Subject: improve rust tests --- tests/projects/rust/console_with_cxx_library/src/foo.cc | 4 ++++ tests/projects/rust/console_with_cxx_library/src/main.rs | 9 +++++++++ tests/projects/rust/console_with_cxx_library/test.lua | 10 ++++++++++ tests/projects/rust/console_with_cxx_library/xmake.lua | 12 ++++++++++++ tests/projects/rust/static_library/src/foo.rs | 5 +++++ tests/projects/rust/static_library/src/interfaces.rs | 5 ----- tests/projects/rust/static_library/src/main.rs | 6 +++--- tests/projects/rust/static_library/xmake.lua | 6 +++--- xmake/templates/rust/static/project/src/foo.rs | 5 +++++ xmake/templates/rust/static/project/src/interfaces.rs | 5 ----- xmake/templates/rust/static/project/src/main.rs | 4 ++-- xmake/templates/rust/static/project/xmake.lua | 7 +++---- 12 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 tests/projects/rust/console_with_cxx_library/src/foo.cc create mode 100644 tests/projects/rust/console_with_cxx_library/src/main.rs create mode 100644 tests/projects/rust/console_with_cxx_library/test.lua create mode 100644 tests/projects/rust/console_with_cxx_library/xmake.lua create mode 100644 tests/projects/rust/static_library/src/foo.rs delete mode 100644 tests/projects/rust/static_library/src/interfaces.rs create mode 100644 xmake/templates/rust/static/project/src/foo.rs delete mode 100644 xmake/templates/rust/static/project/src/interfaces.rs diff --git a/tests/projects/rust/console_with_cxx_library/src/foo.cc b/tests/projects/rust/console_with_cxx_library/src/foo.cc new file mode 100644 index 000000000..9d989119e --- /dev/null +++ b/tests/projects/rust/console_with_cxx_library/src/foo.cc @@ -0,0 +1,4 @@ +extern "C" int add(int a, int b) +{ + return a + b; +} diff --git a/tests/projects/rust/console_with_cxx_library/src/main.rs b/tests/projects/rust/console_with_cxx_library/src/main.rs new file mode 100644 index 000000000..1eac379d2 --- /dev/null +++ b/tests/projects/rust/console_with_cxx_library/src/main.rs @@ -0,0 +1,9 @@ +extern "C" { + fn add(a: i32, b: i32) -> i32; +} + +fn main() { + unsafe { + println!("add(1, 2) = {}", add(1, 2)); + } +} diff --git a/tests/projects/rust/console_with_cxx_library/test.lua b/tests/projects/rust/console_with_cxx_library/test.lua new file mode 100644 index 000000000..92168a8c1 --- /dev/null +++ b/tests/projects/rust/console_with_cxx_library/test.lua @@ -0,0 +1,10 @@ +-- main entry +function main(t) + + -- build project + if is_host("macosx") and os.arch() ~= "arm64" then + t:build() + else + return t:skip("wrong host platform") + end +end diff --git a/tests/projects/rust/console_with_cxx_library/xmake.lua b/tests/projects/rust/console_with_cxx_library/xmake.lua new file mode 100644 index 000000000..e150aca4a --- /dev/null +++ b/tests/projects/rust/console_with_cxx_library/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.debug", "mode.release") + +target("foo") + set_kind("static") + add_files("src/foo.cc") + +target("test") + set_kind("binary") + add_deps("foo") + add_files("src/main.rs") + + diff --git a/tests/projects/rust/static_library/src/foo.rs b/tests/projects/rust/static_library/src/foo.rs new file mode 100644 index 000000000..277008ba4 --- /dev/null +++ b/tests/projects/rust/static_library/src/foo.rs @@ -0,0 +1,5 @@ +pub fn add(a: i32, b: i32) -> i32 +{ + return a + b; +} + diff --git a/tests/projects/rust/static_library/src/interfaces.rs b/tests/projects/rust/static_library/src/interfaces.rs deleted file mode 100644 index 277008ba4..000000000 --- a/tests/projects/rust/static_library/src/interfaces.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub fn add(a: i32, b: i32) -> i32 -{ - return a + b; -} - diff --git a/tests/projects/rust/static_library/src/main.rs b/tests/projects/rust/static_library/src/main.rs index 0cd4449d1..24f23d84b 100644 --- a/tests/projects/rust/static_library/src/main.rs +++ b/tests/projects/rust/static_library/src/main.rs @@ -1,7 +1,7 @@ -extern crate interfaces; +extern crate foo; -fn main() +fn main() { println!("hello xmake!"); - println!("add: {}", interfaces::add(1, 1)); + println!("add: {}", foo::add(1, 1)); } diff --git a/tests/projects/rust/static_library/xmake.lua b/tests/projects/rust/static_library/xmake.lua index fa38d17e5..c50e50874 100644 --- a/tests/projects/rust/static_library/xmake.lua +++ b/tests/projects/rust/static_library/xmake.lua @@ -1,12 +1,12 @@ add_rules("mode.debug", "mode.release") -target("interfaces") +target("foo") set_kind("static") - add_files("src/interfaces.rs") + add_files("src/foo.rs") target("test") set_kind("binary") - add_deps("interfaces") + add_deps("foo") add_files("src/main.rs") diff --git a/xmake/templates/rust/static/project/src/foo.rs b/xmake/templates/rust/static/project/src/foo.rs new file mode 100644 index 000000000..277008ba4 --- /dev/null +++ b/xmake/templates/rust/static/project/src/foo.rs @@ -0,0 +1,5 @@ +pub fn add(a: i32, b: i32) -> i32 +{ + return a + b; +} + diff --git a/xmake/templates/rust/static/project/src/interfaces.rs b/xmake/templates/rust/static/project/src/interfaces.rs deleted file mode 100644 index 277008ba4..000000000 --- a/xmake/templates/rust/static/project/src/interfaces.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub fn add(a: i32, b: i32) -> i32 -{ - return a + b; -} - diff --git a/xmake/templates/rust/static/project/src/main.rs b/xmake/templates/rust/static/project/src/main.rs index 24049d150..24f23d84b 100644 --- a/xmake/templates/rust/static/project/src/main.rs +++ b/xmake/templates/rust/static/project/src/main.rs @@ -1,7 +1,7 @@ -extern crate interfaces; +extern crate foo; fn main() { println!("hello xmake!"); - println!("add: {}", interfaces::add(1, 1)); + println!("add: {}", foo::add(1, 1)); } diff --git a/xmake/templates/rust/static/project/xmake.lua b/xmake/templates/rust/static/project/xmake.lua index a4761d2dc..79a9ac569 100644 --- a/xmake/templates/rust/static/project/xmake.lua +++ b/xmake/templates/rust/static/project/xmake.lua @@ -1,11 +1,10 @@ -target("interfaces") +target("foo") set_kind("static") - add_files("src/interfaces.rs") + add_files("src/foo.rs") target("${TARGETNAME}_demo") set_kind("binary") - add_deps("interfaces") + add_deps("foo") add_files("src/main.rs") - add_linkdirs("$(buildir)") ${FAQ} -- cgit v1.3.1