ObjCExport: remove KotlinUnit from suspend funs returning Unit (#4635)
With `unitSuspendFunctionObjCExport=proper` binary option, for Unit-returning suspend functions ObjCExport now generates completion handlers without redundant `KotlinUnit*` result parameter. So Swift (5.5+) can import these functions as Void-returning async functions. ^KT-47399 Fixed
This commit is contained in:
@@ -5321,7 +5321,7 @@ if (isAppleTarget(project)) {
|
||||
framework(frameworkName) {
|
||||
sources = ['objcexport']
|
||||
library = libraryName
|
||||
opts = ["-Xemit-lazy-objc-header=$lazyHeader", "-Xexport-kdoc", "-Xbundle-id=foo.bar"]
|
||||
opts = ["-Xemit-lazy-objc-header=$lazyHeader", "-Xexport-kdoc", "-Xbundle-id=foo.bar", "-Xbinary=unitSuspendFunctionObjCExport=proper"]
|
||||
}
|
||||
swiftSources = ['objcexport']
|
||||
if (isNoopGC) {
|
||||
@@ -5375,7 +5375,7 @@ if (isAppleTarget(project)) {
|
||||
sources = ['objcexport']
|
||||
artifact = frameworkArtifactName
|
||||
library = libraryName
|
||||
opts = ["-Xemit-lazy-objc-header=$lazyHeader", "-Xno-objc-generics"]
|
||||
opts = ["-Xemit-lazy-objc-header=$lazyHeader", "-Xno-objc-generics", "-Xbinary=unitSuspendFunctionObjCExport=proper"]
|
||||
}
|
||||
swiftSources = ['objcexport']
|
||||
swiftExtraOpts = [ '-D', 'NO_GENERICS' ]
|
||||
@@ -5384,6 +5384,61 @@ if (isAppleTarget(project)) {
|
||||
}
|
||||
}
|
||||
|
||||
frameworkTest('testObjCExportLegacySuspendUnit') {
|
||||
final String frameworkName = 'KtLegacySuspendUnit'
|
||||
final String frameworkArtifactName = 'Kt'
|
||||
final String dir = "$testOutputFramework/testObjCExportLegacySuspendUnit"
|
||||
final File lazyHeader = file("$dir/$target-lazy.h")
|
||||
|
||||
doLast {
|
||||
final String expectedLazyHeaderName = "expectedLazyLegacySuspendUnit.h"
|
||||
final String expectedLazyHeaderDir = file("objcexport/")
|
||||
final File expectedLazyHeader = new File(expectedLazyHeaderDir, expectedLazyHeaderName)
|
||||
|
||||
if (expectedLazyHeader.readLines() != lazyHeader.readLines()) {
|
||||
exec {
|
||||
commandLine 'diff', '-u', expectedLazyHeader, lazyHeader
|
||||
ignoreExitValue = true
|
||||
}
|
||||
|
||||
copy {
|
||||
from(lazyHeader)
|
||||
into(expectedLazyHeaderDir)
|
||||
rename { expectedLazyHeaderName }
|
||||
}
|
||||
|
||||
throw new Error("$expectedLazyHeader file patched;\nre-run the test and don't forget to commit the patch")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
def libraryName = frameworkName + "Library"
|
||||
konanArtifacts {
|
||||
library(libraryName, targets: [target.name]) {
|
||||
srcDir "objcexport/library"
|
||||
artifactName "test-library"
|
||||
|
||||
if (!useCustomDist) {
|
||||
dependsOn ":${target.name}CrossDistRuntime", ':distCompiler'
|
||||
}
|
||||
|
||||
extraOpts "-Xshort-module-name=MyLibrary"
|
||||
extraOpts "-module-name", "org.jetbrains.kotlin.native.test-library"
|
||||
}
|
||||
}
|
||||
framework(frameworkName) {
|
||||
sources = ['objcexport']
|
||||
artifact = frameworkArtifactName
|
||||
library = libraryName
|
||||
opts = ["-Xemit-lazy-objc-header=$lazyHeader"]
|
||||
}
|
||||
swiftSources = ['objcexport']
|
||||
swiftExtraOpts = [ '-D', 'LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT' ]
|
||||
if (isNoopGC) {
|
||||
swiftExtraOpts += ["-D", "NOOP_GC"]
|
||||
}
|
||||
}
|
||||
|
||||
frameworkTest('testObjCExportStatic') {
|
||||
final String frameworkName = 'KtStatic'
|
||||
final String frameworkArtifactName = 'Kt'
|
||||
@@ -5410,6 +5465,7 @@ if (isAppleTarget(project)) {
|
||||
artifact = frameworkArtifactName
|
||||
library = libraryName
|
||||
isStatic = true
|
||||
opts = ["-Xbinary=unitSuspendFunctionObjCExport=proper"]
|
||||
}
|
||||
swiftSources = ['objcexport']
|
||||
if (isNoopGC) {
|
||||
|
||||
Reference in New Issue
Block a user