From fbc39fcab17be9b9c7a778879682cfccb2b16bff Mon Sep 17 00:00:00 2001 From: Pavel Kunyavskiy Date: Mon, 16 Jan 2023 16:58:57 +0100 Subject: [PATCH] [K/N] Make a reproducer test for KT-55938 ^KT-55938 --- .../backend.native/tests/build.gradle | 33 +++++++++++++++++++ .../tests/interop/objc/kt55938/lib.kt | 10 ++++++ .../tests/interop/objc/kt55938/main.kt | 10 ++++++ .../tests/interop/objc/kt55938/main.out | 1 + .../tests/interop/objc/kt55938/objclib.def | 3 ++ .../tests/interop/objc/kt55938/objclib.h | 5 +++ .../tests/interop/objc/kt55938/objclib.m | 11 +++++++ 7 files changed, 73 insertions(+) create mode 100644 kotlin-native/backend.native/tests/interop/objc/kt55938/lib.kt create mode 100644 kotlin-native/backend.native/tests/interop/objc/kt55938/main.kt create mode 100644 kotlin-native/backend.native/tests/interop/objc/kt55938/main.out create mode 100644 kotlin-native/backend.native/tests/interop/objc/kt55938/objclib.def create mode 100644 kotlin-native/backend.native/tests/interop/objc/kt55938/objclib.h create mode 100644 kotlin-native/backend.native/tests/interop/objc/kt55938/objclib.m diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index f799c6c1d1c..e1f56ab1145 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -4443,6 +4443,10 @@ if (PlatformInfo.isAppleTarget(project)) { it.defFile 'interop/objc/kt53151/objclib.def' it.compilerOpts "-F$projectDir/interop/objc/kt53151/testFramework" } + createInterop("objc_kt55938") { + it.defFile 'interop/objc/kt55938/objclib.def' + it.headers "$projectDir/interop/objc/kt55938/objclib.h" + } createInterop("kt49034_struct") { it.defFile 'interop/objc/kt49034/struct/kt49034.def' @@ -5166,6 +5170,7 @@ if (PlatformInfo.isAppleTarget(project)) { UtilsKt.codesign(project, "$buildDir/libobjc_kt42172.dylib") } } + } interopTest("interop_objc_kt48816_without_lazy_ir_for_caches") { @@ -5197,6 +5202,34 @@ if (PlatformInfo.isAppleTarget(project)) { interop = "objc_kt53151" } + interopTest("interop_objc_kt55938") { + source = "interop/objc/kt55938/main.kt" + lib = "interop/objc/kt55938/lib.kt" + interop = "objc_kt55938" + useGoldenData = true + enabled = cacheTesting != null + flags = [ + "-Xauto-cache-from=$testOutputRoot/local/objc_kt55938", + "-Xauto-cache-from=$testOutputRoot/local/interop_objc_kt55938", + "-Xauto-cache-dir=$testOutputRoot/local/interop_objc_kt55938/cache", + "-Werror" // to forbid retry with auto-cache disabled + ] + + doBeforeBuild { + mkdir(buildDir) + def cacheDir = new File("-Xauto-cache-dir=$testOutputRoot/local/interop_objc_kt55938/cache") + cacheDir.deleteDir() + project.extensions.execClang.execClangForCompilerTests(project.target) { + args "$projectDir/interop/objc/kt55938/objclib.m" + args "-lobjc", '-fobjc-arc' + args '-fPIC', '-shared', '-o', "$buildDir/libobjc_kt55938.dylib" + } + if (UtilsKt.isSimulatorTarget(project, project.target)) { + UtilsKt.codesign(project, "$buildDir/libobjc_kt55938.dylib") + } + } + } + standaloneTest("objc_arc_contract") { doBeforeBuild { mkdir(buildDir) diff --git a/kotlin-native/backend.native/tests/interop/objc/kt55938/lib.kt b/kotlin-native/backend.native/tests/interop/objc/kt55938/lib.kt new file mode 100644 index 00000000000..7cf158ec6c0 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt55938/lib.kt @@ -0,0 +1,10 @@ +/* + * Copyright 2010-2023 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. + */ + +package kt55938lib + +import objclib.* + +inline fun foo() = ObjCClass.foo() diff --git a/kotlin-native/backend.native/tests/interop/objc/kt55938/main.kt b/kotlin-native/backend.native/tests/interop/objc/kt55938/main.kt new file mode 100644 index 00000000000..d8c0c7b0432 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt55938/main.kt @@ -0,0 +1,10 @@ +/* + * Copyright 2010-2023 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 kt55938lib.* + +fun main() { + print("foo() call result is ${foo()}") +} \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt55938/main.out b/kotlin-native/backend.native/tests/interop/objc/kt55938/main.out new file mode 100644 index 00000000000..7b82c159e9f --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt55938/main.out @@ -0,0 +1 @@ +foo() call result is 42 \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt55938/objclib.def b/kotlin-native/backend.native/tests/interop/objc/kt55938/objclib.def new file mode 100644 index 00000000000..de366f8dd4c --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt55938/objclib.def @@ -0,0 +1,3 @@ +language = Objective-C +headerFilter = **/objclib.h +linkerOpts = -lobjc_kt55938 diff --git a/kotlin-native/backend.native/tests/interop/objc/kt55938/objclib.h b/kotlin-native/backend.native/tests/interop/objc/kt55938/objclib.h new file mode 100644 index 00000000000..5103e881985 --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt55938/objclib.h @@ -0,0 +1,5 @@ +#import + +@interface ObjCClass : NSObject ++ (int)foo; +@end \ No newline at end of file diff --git a/kotlin-native/backend.native/tests/interop/objc/kt55938/objclib.m b/kotlin-native/backend.native/tests/interop/objc/kt55938/objclib.m new file mode 100644 index 00000000000..a0f318fb45a --- /dev/null +++ b/kotlin-native/backend.native/tests/interop/objc/kt55938/objclib.m @@ -0,0 +1,11 @@ +#include "objclib.h" + + +@implementation ObjCClass { +} + ++ (int)foo { + return 42; +} + +@end \ No newline at end of file