summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-11-10 22:43:37 +0800
committerruki <[email protected]>2021-11-10 22:43:37 +0800
commitb6ed301feb4b223a8c0faa9dd979a722b6e04555 (patch)
tree5acf1e397805852f5c05194a251c3d1066400471
parente99fa03712fb749bd1e689b3df63b98daa1210cc (diff)
improve rust tests
-rw-r--r--tests/projects/rust/console_with_cxx_library/src/foo.cc4
-rw-r--r--tests/projects/rust/console_with_cxx_library/src/main.rs9
-rw-r--r--tests/projects/rust/console_with_cxx_library/test.lua10
-rw-r--r--tests/projects/rust/console_with_cxx_library/xmake.lua12
-rw-r--r--tests/projects/rust/static_library/src/foo.rs (renamed from tests/projects/rust/static_library/src/interfaces.rs)0
-rw-r--r--tests/projects/rust/static_library/src/main.rs6
-rw-r--r--tests/projects/rust/static_library/xmake.lua6
-rw-r--r--xmake/templates/rust/static/project/src/foo.rs (renamed from xmake/templates/rust/static/project/src/interfaces.rs)0
-rw-r--r--xmake/templates/rust/static/project/src/main.rs4
-rw-r--r--xmake/templates/rust/static/project/xmake.lua7
10 files changed, 46 insertions, 12 deletions
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/interfaces.rs b/tests/projects/rust/static_library/src/foo.rs
index 277008ba4..277008ba4 100644
--- a/tests/projects/rust/static_library/src/interfaces.rs
+++ b/tests/projects/rust/static_library/src/foo.rs
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/interfaces.rs b/xmake/templates/rust/static/project/src/foo.rs
index 277008ba4..277008ba4 100644
--- a/xmake/templates/rust/static/project/src/interfaces.rs
+++ b/xmake/templates/rust/static/project/src/foo.rs
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}