summaryrefslogtreecommitdiff
path: root/tests/projects/csharp
diff options
context:
space:
mode:
authorruki <[email protected]>2026-03-19 23:15:48 +0800
committerruki <[email protected]>2026-03-19 23:15:48 +0800
commit930be83656eb0e6dc968f672e889d43aaa166550 (patch)
tree3628c9923964f6360c531daec57a45812452ecea /tests/projects/csharp
parent879355cb0236593d8b73b4141f547585f37134e0 (diff)
add native aot
Diffstat (limited to 'tests/projects/csharp')
-rw-r--r--tests/projects/csharp/native_aot/src/app/main.cpp12
-rw-r--r--tests/projects/csharp/native_aot/src/cslib/MathLib.cs9
-rw-r--r--tests/projects/csharp/native_aot/test.lua13
-rw-r--r--tests/projects/csharp/native_aot/xmake.lua11
4 files changed, 45 insertions, 0 deletions
diff --git a/tests/projects/csharp/native_aot/src/app/main.cpp b/tests/projects/csharp/native_aot/src/app/main.cpp
new file mode 100644
index 000000000..070ad7de6
--- /dev/null
+++ b/tests/projects/csharp/native_aot/src/app/main.cpp
@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+extern "C" {
+ int cs_add(int a, int b);
+ int cs_multiply(int a, int b);
+}
+
+int main() {
+ printf("cs_add(3,4)=%d\n", cs_add(3, 4));
+ printf("cs_multiply(5,6)=%d\n", cs_multiply(5, 6));
+ return 0;
+}
diff --git a/tests/projects/csharp/native_aot/src/cslib/MathLib.cs b/tests/projects/csharp/native_aot/src/cslib/MathLib.cs
new file mode 100644
index 000000000..83255a4b3
--- /dev/null
+++ b/tests/projects/csharp/native_aot/src/cslib/MathLib.cs
@@ -0,0 +1,9 @@
+using System.Runtime.InteropServices;
+
+public static class MathLib {
+ [UnmanagedCallersOnly(EntryPoint = "cs_add")]
+ public static int Add(int a, int b) => a + b;
+
+ [UnmanagedCallersOnly(EntryPoint = "cs_multiply")]
+ public static int Multiply(int a, int b) => a * b;
+}
diff --git a/tests/projects/csharp/native_aot/test.lua b/tests/projects/csharp/native_aot/test.lua
new file mode 100644
index 000000000..d909316b7
--- /dev/null
+++ b/tests/projects/csharp/native_aot/test.lua
@@ -0,0 +1,13 @@
+import("detect.sdks.find_dotnet")
+
+function test_build(t)
+ if is_subhost("msys") then
+ return t:skip("csharp not supported on msys")
+ end
+ local dotnet = find_dotnet()
+ if dotnet and dotnet.sdkver then
+ t:build()
+ else
+ return t:skip("dotnet sdk not found")
+ end
+end
diff --git a/tests/projects/csharp/native_aot/xmake.lua b/tests/projects/csharp/native_aot/xmake.lua
new file mode 100644
index 000000000..92f264095
--- /dev/null
+++ b/tests/projects/csharp/native_aot/xmake.lua
@@ -0,0 +1,11 @@
+add_rules("mode.debug", "mode.release")
+
+target("cslib")
+ set_kind("shared")
+ add_files("src/cslib/*.cs")
+ set_values("csharp.publish_aot", "true")
+
+target("app")
+ set_kind("binary")
+ add_deps("cslib")
+ add_files("src/app/*.cpp")