From d97f00f0eb183bc8479e46909b055677c8d0d45d Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Mon, 10 Feb 2020 20:11:20 +0300 Subject: [PATCH] Added reproducer for https://github.com/JetBrains/kotlin-native/issues/3343 --- backend.native/tests/build.gradle | 41 +++++++++++++++++++ .../tests/framework/gh3343/ktlib.kt | 15 +++++++ .../tests/framework/gh3343/objclib.def | 3 ++ .../tests/framework/gh3343/objclib.h | 11 +++++ .../tests/framework/gh3343/uselib.swift | 23 +++++++++++ 5 files changed, 93 insertions(+) create mode 100644 backend.native/tests/framework/gh3343/ktlib.kt create mode 100644 backend.native/tests/framework/gh3343/objclib.def create mode 100644 backend.native/tests/framework/gh3343/objclib.h create mode 100644 backend.native/tests/framework/gh3343/uselib.swift diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 936597d7912..8cae4e02231 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -3374,6 +3374,11 @@ if (PlatformInfo.isAppleTarget(project)) { def includePath = file("interop/objc/kt34467").absolutePath it.compilerOpts "-fmodule-map-file=$moduleMap", "-I$includePath" } + createInterop("objcGh3343") { + it.defFile 'framework/gh3343/objclib.def' + it.headers "$projectDir/framework/gh3343/objclib.h" + it.linkerOpts "-L$buildDir", "-lobjcgh3343" + } } createInterop("withSpaces") { @@ -3876,6 +3881,42 @@ if (isAppleTarget(project)) { } swiftSources = ['framework/multiple/multiple.swift'] } + + task testGh3343Framework(type: FrameworkTest) { + final String frameworkName = 'Gh3343' + testName = frameworkName + frameworkNames = [frameworkName] + + def mainTask = it + + konanArtifacts { + def lib = "objcGh3343" + def libTask = "compileKonan${lib.capitalize()}${target.name.capitalize()}" + UtilsKt.dependsOnDist(project, libTask) + UtilsKt.sameDependenciesAs(libTask, mainTask) + mainTask.dependsOn(libTask) + + def lnOpts = (project.tasks.getByName(libTask)).linkerOpts + + framework(frameworkName, targets: [ target ]) { + libraries { + artifact lib + } + srcDir 'framework/gh3343' + baseDir "$testOutputFramework/$testName" + + if (!useCustomDist) { + dependsOn ":${target}CrossDistRuntime", ':commonDistRuntime', ':distCompiler' + } + + linkerOpts lnOpts + extraOpts "-Xembed-bitcode-marker" + extraOpts project.globalTestArgs + } + } + swiftSources = ['framework/gh3343/uselib.swift'] + } + } /** diff --git a/backend.native/tests/framework/gh3343/ktlib.kt b/backend.native/tests/framework/gh3343/ktlib.kt new file mode 100644 index 00000000000..b20316f4c4d --- /dev/null +++ b/backend.native/tests/framework/gh3343/ktlib.kt @@ -0,0 +1,15 @@ +import kotlinx.cinterop.* +import objclib.* +import kotlin.native.ref.* + +fun run(): List { + val result = mutableListOf() + result.add(foo1(42)) + val list = foo2(117) + if (list != null) { + result.add(list.size) + for (x in list) + result.add(x) + } + return result +} \ No newline at end of file diff --git a/backend.native/tests/framework/gh3343/objclib.def b/backend.native/tests/framework/gh3343/objclib.def new file mode 100644 index 00000000000..5372fd7a975 --- /dev/null +++ b/backend.native/tests/framework/gh3343/objclib.def @@ -0,0 +1,3 @@ +language = Objective-C +headers = Foundation/NSArray.h Foundation/NSValue.h Foundation/NSString.h +headerFilter = **/objclib.h Foundation/NSArray.h Foundation/NSValue.h Foundation/NSString.h diff --git a/backend.native/tests/framework/gh3343/objclib.h b/backend.native/tests/framework/gh3343/objclib.h new file mode 100644 index 00000000000..38574c72a92 --- /dev/null +++ b/backend.native/tests/framework/gh3343/objclib.h @@ -0,0 +1,11 @@ +#import + +NSString* foo1(int x) { + return [NSString stringWithFormat:@"%d", x]; +} + +NSArray* foo2(int x) { + NSValue* xx = @(x); + NSString* s = @"zzz"; + return [NSArray arrayWithObjects: xx, s, nil]; +} \ No newline at end of file diff --git a/backend.native/tests/framework/gh3343/uselib.swift b/backend.native/tests/framework/gh3343/uselib.swift new file mode 100644 index 00000000000..4acf47e9965 --- /dev/null +++ b/backend.native/tests/framework/gh3343/uselib.swift @@ -0,0 +1,23 @@ +import Foundation +import Gh3343 + +func testGh3343() throws { + let list = KtlibKt.run() + try assertEquals(actual: list[0] as? String, expected: "42") + try assertEquals(actual: list[1] as? Int, expected: 2) + try assertEquals(actual: list[2] as? Int, expected: 117) + try assertEquals(actual: list[3] as? String, expected: "zzz") +} + +// -------- Execution of the test -------- + +class Gh3343Tests : TestProvider { + var tests: [TestCase] = [] + + init() { + providers.append(self) + tests = [ + TestCase(name: "Gh3343", method: withAutorelease(testGh3343)), + ] + } +} \ No newline at end of file