Gradle, native: Support exporting dependencies for static and shared libs
Issue #KT-35352 fixed
This commit is contained in:
+19
-6
@@ -1037,8 +1037,8 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
val prefix = outputKind.prefix(HostManager.host)
|
val prefix = outputKind.prefix(HostManager.host)
|
||||||
val suffix = outputKind.suffix(HostManager.host)
|
val suffix = outputKind.suffix(HostManager.host)
|
||||||
val fileName = "$prefix$fileBaseName$suffix"
|
val fileName = "$prefix$fileBaseName$suffix"
|
||||||
"build/bin/$nativeHostTargetName/$name/$fileName"
|
name to "build/bin/$nativeHostTargetName/$name/$fileName"
|
||||||
}
|
}.toMap()
|
||||||
|
|
||||||
val runTasks = listOf(
|
val runTasks = listOf(
|
||||||
"runDebugExecutable",
|
"runDebugExecutable",
|
||||||
@@ -1060,12 +1060,22 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTasksExecuted(linkTasks.map { ":$it" })
|
assertTasksExecuted(linkTasks.map { ":$it" })
|
||||||
assertTasksExecuted(":$compileTask", ":$compileTestTask")
|
assertTasksExecuted(":$compileTask", ":$compileTestTask")
|
||||||
outputFiles.forEach {
|
outputFiles.forEach { (_, file) ->
|
||||||
assertFileExists(it)
|
assertFileExists(file)
|
||||||
}
|
}
|
||||||
// Check that getters work fine.
|
// Check that getters work fine.
|
||||||
assertTrue(output.contains("Check link task: linkReleaseShared$hostSuffix"))
|
assertTrue(output.contains("Check link task: linkReleaseShared$hostSuffix"))
|
||||||
assertTrue(output.contains("Check run task: runFooReleaseExecutable$hostSuffix"))
|
assertTrue(output.contains("Check run task: runFooReleaseExecutable$hostSuffix"))
|
||||||
|
|
||||||
|
// Check that dependency export works for static and shared libs.
|
||||||
|
val staticSuffix = CompilerOutputKind.STATIC.suffix(HostManager.host)
|
||||||
|
val sharedSuffix = CompilerOutputKind.DYNAMIC.suffix(HostManager.host)
|
||||||
|
val staticPrefix = CompilerOutputKind.STATIC.prefix(HostManager.host)
|
||||||
|
val sharedPrefix = CompilerOutputKind.DYNAMIC.prefix(HostManager.host)
|
||||||
|
val staticHeader = outputFiles.getValue("releaseStatic").removeSuffix(staticSuffix) + "_api.h"
|
||||||
|
val sharedHeader = outputFiles.getValue("releaseShared").removeSuffix(sharedSuffix) + "_api.h"
|
||||||
|
assertTrue(fileInWorkingDir(staticHeader).readText().contains("${staticPrefix}native_binary_KInt (*exported)();"))
|
||||||
|
assertTrue(fileInWorkingDir(sharedHeader).readText().contains("${sharedPrefix}native_binary_KInt (*exported)();"))
|
||||||
}
|
}
|
||||||
|
|
||||||
build("tasks") {
|
build("tasks") {
|
||||||
@@ -1140,8 +1150,11 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
build("linkDebugFrameworkIos") {
|
build("linkDebugFrameworkIos") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertFileExists("build/bin/ios/debugFramework/native_binary.framework")
|
assertFileExists("build/bin/ios/debugFramework/native_binary.framework")
|
||||||
fileInWorkingDir("build/bin/ios/debugFramework/native_binary.framework/Headers/native_binary.h")
|
assertTrue(
|
||||||
.readText().contains("+ (int32_t)exported")
|
fileInWorkingDir("build/bin/ios/debugFramework/native_binary.framework/Headers/native_binary.h")
|
||||||
|
.readText()
|
||||||
|
.contains("+ (int32_t)exported")
|
||||||
|
)
|
||||||
// Check that by default debug frameworks have bitcode marker embedded.
|
// Check that by default debug frameworks have bitcode marker embedded.
|
||||||
checkNativeCommandLineFor(":linkDebugFrameworkIos") {
|
checkNativeCommandLineFor(":linkDebugFrameworkIos") {
|
||||||
assertTrue(it.contains("-Xembed-bitcode-marker"))
|
assertTrue(it.contains("-Xembed-bitcode-marker"))
|
||||||
|
|||||||
+6
-2
@@ -61,8 +61,12 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sharedLib([RELEASE])
|
sharedLib([RELEASE]) {
|
||||||
staticLib([RELEASE])
|
export project(':exported')
|
||||||
|
}
|
||||||
|
staticLib([RELEASE]) {
|
||||||
|
export project(':exported')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Check that we can access binaries/tasks:
|
// Check that we can access binaries/tasks:
|
||||||
// Just by name:
|
// Just by name:
|
||||||
|
|||||||
+6
-2
@@ -51,8 +51,12 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sharedLib(listOf(RELEASE))
|
sharedLib(listOf(RELEASE)) {
|
||||||
staticLib(listOf(RELEASE))
|
export(project(":exported"))
|
||||||
|
}
|
||||||
|
staticLib(listOf(RELEASE)) {
|
||||||
|
export(project(":exported"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Check that we can access binaries/tasks:
|
// Check that we can access binaries/tasks:
|
||||||
// Just by name:
|
// Just by name:
|
||||||
|
|||||||
+1
-1
@@ -304,7 +304,7 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
target.binaries.withType(Framework::class.java).all { framework ->
|
target.binaries.withType(AbstractNativeLibrary::class.java).all { framework ->
|
||||||
val exportConfiguration = project.configurations.maybeCreate(framework.exportConfigurationName).apply {
|
val exportConfiguration = project.configurations.maybeCreate(framework.exportConfigurationName).apply {
|
||||||
isVisible = false
|
isVisible = false
|
||||||
isTransitive = false
|
isTransitive = false
|
||||||
|
|||||||
+32
-25
@@ -155,37 +155,13 @@ class TestExecutable(
|
|||||||
get() = NativeOutputKind.TEST
|
get() = NativeOutputKind.TEST
|
||||||
}
|
}
|
||||||
|
|
||||||
class StaticLibrary(
|
abstract class AbstractNativeLibrary(
|
||||||
name: String,
|
|
||||||
baseName: String,
|
|
||||||
buildType: NativeBuildType,
|
|
||||||
compilation: KotlinNativeCompilation
|
|
||||||
) : NativeBinary(name, baseName, buildType, compilation) {
|
|
||||||
override val outputKind: NativeOutputKind
|
|
||||||
get() = NativeOutputKind.STATIC
|
|
||||||
}
|
|
||||||
|
|
||||||
class SharedLibrary(
|
|
||||||
name: String,
|
|
||||||
baseName: String,
|
|
||||||
buildType: NativeBuildType,
|
|
||||||
compilation: KotlinNativeCompilation
|
|
||||||
) : NativeBinary(name, baseName, buildType, compilation) {
|
|
||||||
override val outputKind: NativeOutputKind
|
|
||||||
get() = NativeOutputKind.DYNAMIC
|
|
||||||
}
|
|
||||||
|
|
||||||
class Framework(
|
|
||||||
name: String,
|
name: String,
|
||||||
baseName: String,
|
baseName: String,
|
||||||
buildType: NativeBuildType,
|
buildType: NativeBuildType,
|
||||||
compilation: KotlinNativeCompilation
|
compilation: KotlinNativeCompilation
|
||||||
) : NativeBinary(name, baseName, buildType, compilation) {
|
) : NativeBinary(name, baseName, buildType, compilation) {
|
||||||
|
|
||||||
override val outputKind: NativeOutputKind
|
|
||||||
get() = NativeOutputKind.FRAMEWORK
|
|
||||||
|
|
||||||
// Export symbols from klibraries.
|
|
||||||
val exportConfigurationName: String
|
val exportConfigurationName: String
|
||||||
get() = target.disambiguateName(lowerCamelCaseName(name, "export"))
|
get() = target.disambiguateName(lowerCamelCaseName(name, "export"))
|
||||||
|
|
||||||
@@ -220,6 +196,37 @@ class Framework(
|
|||||||
configure.execute(it)
|
configure.execute(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class StaticLibrary(
|
||||||
|
name: String,
|
||||||
|
baseName: String,
|
||||||
|
buildType: NativeBuildType,
|
||||||
|
compilation: KotlinNativeCompilation
|
||||||
|
) : AbstractNativeLibrary(name, baseName, buildType, compilation) {
|
||||||
|
override val outputKind: NativeOutputKind
|
||||||
|
get() = NativeOutputKind.STATIC
|
||||||
|
}
|
||||||
|
|
||||||
|
class SharedLibrary(
|
||||||
|
name: String,
|
||||||
|
baseName: String,
|
||||||
|
buildType: NativeBuildType,
|
||||||
|
compilation: KotlinNativeCompilation
|
||||||
|
) : AbstractNativeLibrary(name, baseName, buildType, compilation) {
|
||||||
|
override val outputKind: NativeOutputKind
|
||||||
|
get() = NativeOutputKind.DYNAMIC
|
||||||
|
}
|
||||||
|
|
||||||
|
class Framework(
|
||||||
|
name: String,
|
||||||
|
baseName: String,
|
||||||
|
buildType: NativeBuildType,
|
||||||
|
compilation: KotlinNativeCompilation
|
||||||
|
) : AbstractNativeLibrary(name, baseName, buildType, compilation) {
|
||||||
|
|
||||||
|
override val outputKind: NativeOutputKind
|
||||||
|
get() = NativeOutputKind.FRAMEWORK
|
||||||
|
|
||||||
// Embedding bitcode.
|
// Embedding bitcode.
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -493,7 +493,7 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
|||||||
@get:InputFiles
|
@get:InputFiles
|
||||||
val exportLibraries: FileCollection
|
val exportLibraries: FileCollection
|
||||||
get() = binary.let {
|
get() = binary.let {
|
||||||
if (it is Framework) {
|
if (it is AbstractNativeLibrary) {
|
||||||
project.configurations.getByName(it.exportConfigurationName)
|
project.configurations.getByName(it.exportConfigurationName)
|
||||||
} else {
|
} else {
|
||||||
project.files()
|
project.files()
|
||||||
|
|||||||
Reference in New Issue
Block a user