diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index beea73672a6..46dec15837c 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -4366,6 +4366,21 @@ if (PlatformInfo.isAppleTarget(project)) { createInterop("objc_kt50648") { it.defFile 'interop/objc/kt50648/objclib.def' } + + createInterop("kt49034_struct") { + it.defFile 'interop/objc/kt49034/struct/kt49034.def' + it.headers "$projectDir/interop/objc/kt49034/struct/kt49034.h" + it.extraOpts "-Xcompile-source", "$projectDir/interop/objc/kt49034/struct/impl.c" + } + + createInterop("kt49034_objcclass") { + it.defFile 'interop/objc/kt49034/objcclass/kt49034.def' + it.headers "$projectDir/interop/objc/kt49034/objcclass/kt49034.h" + } + createInterop("kt49034_objcprotocol") { + it.defFile 'interop/objc/kt49034/objcprotocol/kt49034.def' + it.headers "$projectDir/interop/objc/kt49034/objcprotocol/kt49034.h" + } } createInterop("withSpaces") { @@ -4889,6 +4904,35 @@ if (PlatformInfo.isAppleTarget(project)) { } } + // KT-49034 tests don't need whole compilation pipeline (only frontend) or platform libraries. Consider simplifying them when porting + // to the new test infra. + interopTest("interop_kt49034_struct") { + disabled = (project.testTarget == 'wasm32') + interop = 'kt49034_struct' + source = 'interop/objc/kt49034/struct/main.kt' + + // The test depends on collision between kt49034.JSContext and platform.JavaScriptCore.JSContext + UtilsKt.dependsOnPlatformLibs(it) + } + + interopTest("interop_kt49034_objcclass") { + disabled = (project.testTarget == 'wasm32') + interop = 'kt49034_objcclass' + source = 'interop/objc/kt49034/objcclass/main.kt' + + // The test depends on collision between kt49034.__darwin_fp_control and platform.darwin.__darwin_fp_control + UtilsKt.dependsOnPlatformLibs(it) + } + + interopTest("interop_kt49034_objcprotocol") { + disabled = (project.testTarget == 'wasm32') + interop = 'kt49034_objcprotocol' + source = 'interop/objc/kt49034/objcprotocol/main.kt' + + // The test depends on collision between kt49034.__darwin_fp_control and platform.darwin.__darwin_fp_control + UtilsKt.dependsOnPlatformLibs(it) + } + interopTest("interop_objc_global_initializer") { useGoldenData = true source = "interop/objc_with_initializer/objc_test.kt" diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.def b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.def new file mode 100644 index 00000000000..bc752fc0d3e --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.def @@ -0,0 +1 @@ +language = Objective-C \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.h b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.h new file mode 100644 index 00000000000..66486a40d88 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/kt49034.h @@ -0,0 +1 @@ +@class __darwin_fp_control; \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/main.kt b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/main.kt new file mode 100644 index 00000000000..1030f72a0f5 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcclass/main.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +import objcnames.classes.__darwin_fp_control + +open class C + +class D : C<__darwin_fp_control>() + +fun main() { + println(D()) +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/objcprotocol/kt49034.def b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcprotocol/kt49034.def new file mode 100644 index 00000000000..bc752fc0d3e --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcprotocol/kt49034.def @@ -0,0 +1 @@ +language = Objective-C \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/objcprotocol/kt49034.h b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcprotocol/kt49034.h new file mode 100644 index 00000000000..97e4b2d69e9 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcprotocol/kt49034.h @@ -0,0 +1 @@ +@protocol __darwin_fp_control; \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/objcprotocol/main.kt b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcprotocol/main.kt new file mode 100644 index 00000000000..905089a5be2 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt49034/objcprotocol/main.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +import objcnames.protocols.__darwin_fp_control + +open class C + +class D : C<__darwin_fp_control>() + +fun main() { + println(D()) +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/impl.c b/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/impl.c new file mode 100644 index 00000000000..483ce46e494 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/impl.c @@ -0,0 +1,11 @@ +#include "kt49034.h" + +struct JSContext { + int field; +}; + +struct JSContext global = { 15 }; + +extern "C" struct JSContext* bar() { + return &global; +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/kt49034.def b/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/kt49034.def new file mode 100644 index 00000000000..e69de29bb2d diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/kt49034.h b/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/kt49034.h new file mode 100644 index 00000000000..a14ccf4e6e7 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/kt49034.h @@ -0,0 +1,11 @@ +#ifdef __cplusplus +extern "C" { +#endif + +struct JSContext; + +struct JSContext* bar(); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/main.kt b/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/main.kt new file mode 100644 index 00000000000..2b19035c252 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt49034/struct/main.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +import kt49034.bar +import cnames.structs.JSContext +import kotlinx.cinterop.CPointer + +fun baz(s: CPointer) { + println(s) +} + +fun main() { + baz(bar()!!) +} \ No newline at end of file