Gradle, native: Support exporting dependencies for static and shared libs

Issue #KT-35352 fixed
This commit is contained in:
Ilya Matveev
2019-12-11 19:46:37 +07:00
parent c7e3df506d
commit 01622f069e
6 changed files with 65 additions and 37 deletions
@@ -1037,8 +1037,8 @@ class NewMultiplatformIT : BaseGradleIT() {
val prefix = outputKind.prefix(HostManager.host)
val suffix = outputKind.suffix(HostManager.host)
val fileName = "$prefix$fileBaseName$suffix"
"build/bin/$nativeHostTargetName/$name/$fileName"
}
name to "build/bin/$nativeHostTargetName/$name/$fileName"
}.toMap()
val runTasks = listOf(
"runDebugExecutable",
@@ -1060,12 +1060,22 @@ class NewMultiplatformIT : BaseGradleIT() {
assertSuccessful()
assertTasksExecuted(linkTasks.map { ":$it" })
assertTasksExecuted(":$compileTask", ":$compileTestTask")
outputFiles.forEach {
assertFileExists(it)
outputFiles.forEach { (_, file) ->
assertFileExists(file)
}
// Check that getters work fine.
assertTrue(output.contains("Check link task: linkReleaseShared$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") {
@@ -1140,8 +1150,11 @@ class NewMultiplatformIT : BaseGradleIT() {
build("linkDebugFrameworkIos") {
assertSuccessful()
assertFileExists("build/bin/ios/debugFramework/native_binary.framework")
fileInWorkingDir("build/bin/ios/debugFramework/native_binary.framework/Headers/native_binary.h")
.readText().contains("+ (int32_t)exported")
assertTrue(
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.
checkNativeCommandLineFor(":linkDebugFrameworkIos") {
assertTrue(it.contains("-Xembed-bitcode-marker"))
@@ -61,8 +61,12 @@ kotlin {
}
}
sharedLib([RELEASE])
staticLib([RELEASE])
sharedLib([RELEASE]) {
export project(':exported')
}
staticLib([RELEASE]) {
export project(':exported')
}
}
// Check that we can access binaries/tasks:
// Just by name:
@@ -51,8 +51,12 @@ kotlin {
}
}
sharedLib(listOf(RELEASE))
staticLib(listOf(RELEASE))
sharedLib(listOf(RELEASE)) {
export(project(":exported"))
}
staticLib(listOf(RELEASE)) {
export(project(":exported"))
}
}
// Check that we can access binaries/tasks:
// Just by name:
@@ -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 {
isVisible = false
isTransitive = false
@@ -155,37 +155,13 @@ class TestExecutable(
get() = NativeOutputKind.TEST
}
class StaticLibrary(
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(
abstract class AbstractNativeLibrary(
name: String,
baseName: String,
buildType: NativeBuildType,
compilation: KotlinNativeCompilation
) : NativeBinary(name, baseName, buildType, compilation) {
override val outputKind: NativeOutputKind
get() = NativeOutputKind.FRAMEWORK
// Export symbols from klibraries.
val exportConfigurationName: String
get() = target.disambiguateName(lowerCamelCaseName(name, "export"))
@@ -220,6 +196,37 @@ class Framework(
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.
/**
@@ -493,7 +493,7 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
@get:InputFiles
val exportLibraries: FileCollection
get() = binary.let {
if (it is Framework) {
if (it is AbstractNativeLibrary) {
project.configurations.getByName(it.exportConfigurationName)
} else {
project.files()