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") { build("linkCustomReleaseFrameworkIos") {
assertSuccessful() assertSuccessful()
checkFrameworkCompilationCommandLine { checkFrameworkCompilationCommandLine {
assertTrue(it.contains("-linker-options -L.")) assertTrue(it.contains("-linker-options -L."))
assertTrue(it.contains("-Xtime")) assertTrue(it.contains("-Xtime"))
assertTrue(it.contains("-Xstatic-framework"))
assertFalse(it.contains("-Xembed-bitcode-marker")) assertFalse(it.contains("-Xembed-bitcode-marker"))
assertFalse(it.contains("-Xembed-bitcode")) assertFalse(it.contains("-Xembed-bitcode"))
} }
@@ -73,6 +73,7 @@ kotlin {
embedBitcode = 'DISABLE' embedBitcode = 'DISABLE'
linkerOpts = ['-L.'] linkerOpts = ['-L.']
freeCompilerArgs = ["-Xtime"] freeCompilerArgs = ["-Xtime"]
isStatic = true
} }
} }
} }
@@ -65,6 +65,7 @@ kotlin {
embedBitcode("disable") embedBitcode("disable")
linkerOpts = mutableListOf("-L.") linkerOpts = mutableListOf("-L.")
freeCompilerArgs = mutableListOf("-Xtime") freeCompilerArgs = mutableListOf("-Xtime")
isStatic = true
} }
} }
} }
@@ -102,8 +102,7 @@ open class KotlinCocoapodsPlugin: Plugin<Project> {
private fun createDefaultFrameworks(kotlinExtension: KotlinMultiplatformExtension) { private fun createDefaultFrameworks(kotlinExtension: KotlinMultiplatformExtension) {
kotlinExtension.supportedTargets().all { target -> kotlinExtension.supportedTargets().all { target ->
target.binaries.framework { target.binaries.framework {
// TODO: Add in the framework DSL. isStatic = true
this.freeCompilerArgs.add("-Xstatic-framework")
} }
} }
} }
@@ -234,6 +234,11 @@ class Framework(
*/ */
fun embedBitcode(mode: String) = embedBitcode(BitcodeEmbeddingMode.valueOf(mode.toUpperCase())) 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 { enum class BitcodeEmbeddingMode {
/** Don't embed LLVM IR bitcode. */ /** Don't embed LLVM IR bitcode. */
DISABLE, DISABLE,
@@ -370,6 +370,10 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile() {
} }
} }
@get:Input
val isStaticFramework: Boolean
get() = binary.let { it is Framework && it.isStatic }
@get:Input @get:Input
val embedBitcode: Framework.BitcodeEmbeddingMode val embedBitcode: Framework.BitcodeEmbeddingMode
get() = (binary as? Framework)?.embedBitcode ?: Framework.BitcodeEmbeddingMode.DISABLE get() = (binary as? Framework)?.embedBitcode ?: Framework.BitcodeEmbeddingMode.DISABLE
@@ -392,6 +396,7 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile() {
exportLibraries.files.filterExternalKlibs(project).forEach { exportLibraries.files.filterExternalKlibs(project).forEach {
add("-Xexport-library=${it.absolutePath}") add("-Xexport-library=${it.absolutePath}")
} }
addKey("-Xstatic-framework", isStaticFramework)
addAll(freeCompilerArgs) addAll(freeCompilerArgs)
} }
} }