Support -Xstatic-framework in DSL

In Kotlin/Native 1.3.30 EAP1 an ability to build
a static ObjC framework has been added. This patch
adds support for this feature in the kotlin-multiplatform
plugin.
This commit is contained in:
Ilya Matveev
2019-02-28 18:56:30 +03:00
parent 60026c8aa1
commit 3cd20fab75
6 changed files with 15 additions and 3 deletions
@@ -990,12 +990,13 @@ class NewMultiplatformIT : BaseGradleIT() {
}
}
// Check manual disabling bitcode embedding and custom command line args.
// Check manual disabling bitcode embedding, custom command line args and building a static framework.
build("linkCustomReleaseFrameworkIos") {
assertSuccessful()
checkFrameworkCompilationCommandLine {
assertTrue(it.contains("-linker-options -L."))
assertTrue(it.contains("-Xtime"))
assertTrue(it.contains("-Xstatic-framework"))
assertFalse(it.contains("-Xembed-bitcode-marker"))
assertFalse(it.contains("-Xembed-bitcode"))
}
@@ -73,6 +73,7 @@ kotlin {
embedBitcode = 'DISABLE'
linkerOpts = ['-L.']
freeCompilerArgs = ["-Xtime"]
isStatic = true
}
}
}
@@ -65,6 +65,7 @@ kotlin {
embedBitcode("disable")
linkerOpts = mutableListOf("-L.")
freeCompilerArgs = mutableListOf("-Xtime")
isStatic = true
}
}
}
@@ -102,8 +102,7 @@ open class KotlinCocoapodsPlugin: Plugin<Project> {
private fun createDefaultFrameworks(kotlinExtension: KotlinMultiplatformExtension) {
kotlinExtension.supportedTargets().all { target ->
target.binaries.framework {
// TODO: Add in the framework DSL.
this.freeCompilerArgs.add("-Xstatic-framework")
isStatic = true
}
}
}
@@ -234,6 +234,11 @@ class Framework(
*/
fun embedBitcode(mode: String) = embedBitcode(BitcodeEmbeddingMode.valueOf(mode.toUpperCase()))
/**
* Specifies if the framework is linked as a static library (false by default).
*/
var isStatic = false
enum class BitcodeEmbeddingMode {
/** Don't embed LLVM IR bitcode. */
DISABLE,
@@ -370,6 +370,10 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile() {
}
}
@get:Input
val isStaticFramework: Boolean
get() = binary.let { it is Framework && it.isStatic }
@get:Input
val embedBitcode: Framework.BitcodeEmbeddingMode
get() = (binary as? Framework)?.embedBitcode ?: Framework.BitcodeEmbeddingMode.DISABLE
@@ -392,6 +396,7 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile() {
exportLibraries.files.filterExternalKlibs(project).forEach {
add("-Xexport-library=${it.absolutePath}")
}
addKey("-Xstatic-framework", isStaticFramework)
addAll(freeCompilerArgs)
}
}