summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-02-20 22:43:57 +0800
committerruki <[email protected]>2025-02-20 22:43:57 +0800
commit12e6b2e55738d259561da396f0fc63c468fd6147 (patch)
tree1f4fdc9b42b9e0310d1cbaec2295398795293e80
parent48065b9580ec329b67a48ce4c7dd79c606ac2aa2 (diff)
add template for kotlin
-rw-r--r--xmake/templates/kotlin/shared_library/project/src/foo.kt8
-rw-r--r--xmake/templates/kotlin/shared_library/project/src/main.c7
-rw-r--r--xmake/templates/kotlin/shared_library/project/xmake.lua13
-rw-r--r--xmake/templates/kotlin/shared_library/template.lua2
-rw-r--r--xmake/templates/kotlin/static_library/project/src/foo.kt8
-rw-r--r--xmake/templates/kotlin/static_library/project/src/main.c7
-rw-r--r--xmake/templates/kotlin/static_library/project/xmake.lua13
-rw-r--r--xmake/templates/kotlin/static_library/template.lua2
8 files changed, 60 insertions, 0 deletions
diff --git a/xmake/templates/kotlin/shared_library/project/src/foo.kt b/xmake/templates/kotlin/shared_library/project/src/foo.kt
new file mode 100644
index 000000000..64ed2a016
--- /dev/null
+++ b/xmake/templates/kotlin/shared_library/project/src/foo.kt
@@ -0,0 +1,8 @@
+@file:OptIn(ExperimentalNativeApi::class)
+
+import kotlin.experimental.ExperimentalNativeApi
+import kotlinx.cinterop.*
+
+@ExperimentalNativeApi
+@CName("kotlin_add")
+fun add(a: Int, b: Int): Int = a + b
diff --git a/xmake/templates/kotlin/shared_library/project/src/main.c b/xmake/templates/kotlin/shared_library/project/src/main.c
new file mode 100644
index 000000000..55e16305d
--- /dev/null
+++ b/xmake/templates/kotlin/shared_library/project/src/main.c
@@ -0,0 +1,7 @@
+#include "libfoo_api.h"
+#include <stdio.h>
+
+int main(int argc, char** argv) {
+ printf("add(1, 2) = %d\n", kotlin_add(1, 2));
+ return 0;
+}
diff --git a/xmake/templates/kotlin/shared_library/project/xmake.lua b/xmake/templates/kotlin/shared_library/project/xmake.lua
new file mode 100644
index 000000000..491a8f835
--- /dev/null
+++ b/xmake/templates/kotlin/shared_library/project/xmake.lua
@@ -0,0 +1,13 @@
+add_rules("mode.debug", "mode.release")
+add_requires("kotlin-native")
+target("foo")
+ set_kind("shared")
+ add_files("src/foo.kt")
+ set_toolchains("@kotlin-native")
+
+target("${TARGETNAME}")
+ set_kind("binary")
+ add_files("src/main.c")
+ add_deps("foo")
+
+${FAQ}
diff --git a/xmake/templates/kotlin/shared_library/template.lua b/xmake/templates/kotlin/shared_library/template.lua
new file mode 100644
index 000000000..d7ec5bae4
--- /dev/null
+++ b/xmake/templates/kotlin/shared_library/template.lua
@@ -0,0 +1,2 @@
+template("shared")
+ add_configfiles("xmake.lua")
diff --git a/xmake/templates/kotlin/static_library/project/src/foo.kt b/xmake/templates/kotlin/static_library/project/src/foo.kt
new file mode 100644
index 000000000..64ed2a016
--- /dev/null
+++ b/xmake/templates/kotlin/static_library/project/src/foo.kt
@@ -0,0 +1,8 @@
+@file:OptIn(ExperimentalNativeApi::class)
+
+import kotlin.experimental.ExperimentalNativeApi
+import kotlinx.cinterop.*
+
+@ExperimentalNativeApi
+@CName("kotlin_add")
+fun add(a: Int, b: Int): Int = a + b
diff --git a/xmake/templates/kotlin/static_library/project/src/main.c b/xmake/templates/kotlin/static_library/project/src/main.c
new file mode 100644
index 000000000..55e16305d
--- /dev/null
+++ b/xmake/templates/kotlin/static_library/project/src/main.c
@@ -0,0 +1,7 @@
+#include "libfoo_api.h"
+#include <stdio.h>
+
+int main(int argc, char** argv) {
+ printf("add(1, 2) = %d\n", kotlin_add(1, 2));
+ return 0;
+}
diff --git a/xmake/templates/kotlin/static_library/project/xmake.lua b/xmake/templates/kotlin/static_library/project/xmake.lua
new file mode 100644
index 000000000..2667c26fd
--- /dev/null
+++ b/xmake/templates/kotlin/static_library/project/xmake.lua
@@ -0,0 +1,13 @@
+add_rules("mode.debug", "mode.release")
+add_requires("kotlin-native")
+target("foo")
+ set_kind("static")
+ add_files("src/foo.kt")
+ set_toolchains("@kotlin-native")
+
+target("${TARGETNAME}")
+ set_kind("binary")
+ add_files("src/main.c")
+ add_deps("foo")
+
+${FAQ}
diff --git a/xmake/templates/kotlin/static_library/template.lua b/xmake/templates/kotlin/static_library/template.lua
new file mode 100644
index 000000000..abfe91a4b
--- /dev/null
+++ b/xmake/templates/kotlin/static_library/template.lua
@@ -0,0 +1,2 @@
+template("static")
+ add_configfiles("xmake.lua")