From 6807d5763f16e779697af79764b4ea6dd79b6fef Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 20 Feb 2025 22:45:35 +0800 Subject: improve cname for kotlin --- tests/projects/kotlin-native/shared_library/src/foo.kt | 6 ------ tests/projects/kotlin-native/static_library/src/foo.kt | 6 ------ xmake/rules/kotlin-native/xmake.lua | 2 ++ xmake/templates/kotlin/shared_library/project/src/foo.kt | 6 ------ xmake/templates/kotlin/static_library/project/src/foo.kt | 6 ------ 5 files changed, 2 insertions(+), 24 deletions(-) diff --git a/tests/projects/kotlin-native/shared_library/src/foo.kt b/tests/projects/kotlin-native/shared_library/src/foo.kt index 64ed2a016..cc5184bd7 100644 --- a/tests/projects/kotlin-native/shared_library/src/foo.kt +++ b/tests/projects/kotlin-native/shared_library/src/foo.kt @@ -1,8 +1,2 @@ -@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/tests/projects/kotlin-native/static_library/src/foo.kt b/tests/projects/kotlin-native/static_library/src/foo.kt index 64ed2a016..cc5184bd7 100644 --- a/tests/projects/kotlin-native/static_library/src/foo.kt +++ b/tests/projects/kotlin-native/static_library/src/foo.kt @@ -1,8 +1,2 @@ -@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/rules/kotlin-native/xmake.lua b/xmake/rules/kotlin-native/xmake.lua index be3c39bac..69fcb6027 100644 --- a/xmake/rules/kotlin-native/xmake.lua +++ b/xmake/rules/kotlin-native/xmake.lua @@ -24,11 +24,13 @@ rule("kotlin-native.build") if target:is_static() then target:add("arflags", {"-produce", "static"}, {force = true}) target:add("includedirs", target:targetdir(), {interface = true}) + target:add("kcflags", "-opt-in=kotlin.experimental.ExperimentalNativeApi", {force = true}) if target:is_plat("macosx") then target:add("frameworks", "Foundation", "CoreFoundation", {interface = true}) end elseif target:is_shared() then target:add("shflags", {"-produce", "dynamic"}, {force = true}) + target:add("kcflags", "-opt-in=kotlin.experimental.ExperimentalNativeApi", {force = true}) target:add("includedirs", target:targetdir(), {interface = true}) end target:set("policy", "build.fence", true) diff --git a/xmake/templates/kotlin/shared_library/project/src/foo.kt b/xmake/templates/kotlin/shared_library/project/src/foo.kt index 64ed2a016..cc5184bd7 100644 --- a/xmake/templates/kotlin/shared_library/project/src/foo.kt +++ b/xmake/templates/kotlin/shared_library/project/src/foo.kt @@ -1,8 +1,2 @@ -@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/foo.kt b/xmake/templates/kotlin/static_library/project/src/foo.kt index 64ed2a016..cc5184bd7 100644 --- a/xmake/templates/kotlin/static_library/project/src/foo.kt +++ b/xmake/templates/kotlin/static_library/project/src/foo.kt @@ -1,8 +1,2 @@ -@file:OptIn(ExperimentalNativeApi::class) - -import kotlin.experimental.ExperimentalNativeApi -import kotlinx.cinterop.* - -@ExperimentalNativeApi @CName("kotlin_add") fun add(a: Int, b: Int): Int = a + b -- cgit v1.3.1