Support bitcode embedding for frameworks
This commit is contained in:
+1
-1
@@ -492,7 +492,7 @@ open class KotlinNativeTargetConfigurator(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
group = RUN_GROUP
|
group = RUN_GROUP
|
||||||
description = "Executes Kotlin/Native executable ${binary.baseName} for target ${binary.target.name}"
|
description = "Executes Kotlin/Native executable ${binary.name} for target ${binary.target.name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
enabled = binary.target.konanTarget.isCurrentHost
|
enabled = binary.target.konanTarget.isCurrentHost
|
||||||
|
|||||||
+49
-2
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator
|
|||||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinNativeCompile
|
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinNativeCompile
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
|
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
|
import org.jetbrains.kotlin.konan.target.Family
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
// TODO: Should the baseName be a var?
|
// TODO: Should the baseName be a var?
|
||||||
@@ -42,8 +43,8 @@ sealed class NativeBinary(
|
|||||||
abstract val outputKind: NativeOutputKind
|
abstract val outputKind: NativeOutputKind
|
||||||
|
|
||||||
// Configuration DSL.
|
// Configuration DSL.
|
||||||
var debuggable: Boolean = false
|
var debuggable: Boolean = buildType.debuggable
|
||||||
var optimized: Boolean = false
|
var optimized: Boolean = buildType.optimized
|
||||||
|
|
||||||
var linkerOpts: MutableList<String> = mutableListOf()
|
var linkerOpts: MutableList<String> = mutableListOf()
|
||||||
|
|
||||||
@@ -149,22 +150,68 @@ class Framework(
|
|||||||
override val outputKind: NativeOutputKind
|
override val outputKind: NativeOutputKind
|
||||||
get() = NativeOutputKind.FRAMEWORK
|
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"))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If dependencies added by the [export] method are resolved transitively or not.
|
||||||
|
*/
|
||||||
var transitiveExport: Boolean
|
var transitiveExport: Boolean
|
||||||
get() = project.configurations.maybeCreate(exportConfigurationName).isTransitive
|
get() = project.configurations.maybeCreate(exportConfigurationName).isTransitive
|
||||||
set(value) {
|
set(value) {
|
||||||
project.configurations.maybeCreate(exportConfigurationName).isTransitive = value
|
project.configurations.maybeCreate(exportConfigurationName).isTransitive = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a dependency to be exported in the framework.
|
||||||
|
*/
|
||||||
fun export(dependency: Any) {
|
fun export(dependency: Any) {
|
||||||
project.dependencies.add(exportConfigurationName, dependency)
|
project.dependencies.add(exportConfigurationName, dependency)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a dependency to be exported in the framework.
|
||||||
|
*/
|
||||||
fun export(dependency: Any, configure: Closure<*>) {
|
fun export(dependency: Any, configure: Closure<*>) {
|
||||||
project.dependencies.add(exportConfigurationName, dependency, configure)
|
project.dependencies.add(exportConfigurationName, dependency, configure)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Embedding bitcode.
|
||||||
|
/**
|
||||||
|
* Embed bitcode for the framework or not. See [BitcodeEmbeddingMode].
|
||||||
|
*/
|
||||||
|
var embedBitcode: BitcodeEmbeddingMode = if (target.konanTarget.family == Family.IOS) {
|
||||||
|
buildType.iosEmbedBitcode
|
||||||
|
} else {
|
||||||
|
BitcodeEmbeddingMode.DISABLE
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable embedding bitcode for the framework. See [BitcodeEmbeddingMode].
|
||||||
|
*/
|
||||||
|
fun embedBitcode(mode: BitcodeEmbeddingMode) {
|
||||||
|
embedBitcode = mode
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable embedding bitcode for the framework.
|
||||||
|
*
|
||||||
|
* @param mode - one of the following string constants:
|
||||||
|
* disable - Don't embed LLVM IR bitcode.
|
||||||
|
* bitcode - Embed LLVM IR bitcode as data. Has the same effect as the -Xembed-bitcode command line option.
|
||||||
|
* marker - Embed placeholder LLVM IR data as a marker. Has the same effect as the -Xembed-bitcode-marker command line option.
|
||||||
|
*/
|
||||||
|
fun embedBitcode(mode: String) = embedBitcode(BitcodeEmbeddingMode.valueOf(mode.toUpperCase()))
|
||||||
|
|
||||||
|
enum class BitcodeEmbeddingMode {
|
||||||
|
/** Don't embed LLVM IR bitcode. */
|
||||||
|
DISABLE,
|
||||||
|
/** Embed LLVM IR bitcode as data. */
|
||||||
|
BITCODE,
|
||||||
|
/** Embed placeholder LLVM IR data as a marker. */
|
||||||
|
MARKER,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+7
-8
@@ -5,14 +5,13 @@ import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
|||||||
import org.jetbrains.kotlin.konan.target.Family
|
import org.jetbrains.kotlin.konan.target.Family
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
|
|
||||||
object KotlinNativeUsage {
|
enum class NativeBuildType(
|
||||||
const val KLIB = "kotlin-native-klib"
|
val optimized: Boolean,
|
||||||
const val FRAMEWORK = "kotlin-native-framework"
|
val debuggable: Boolean,
|
||||||
}
|
internal val iosEmbedBitcode: Framework.BitcodeEmbeddingMode
|
||||||
|
) : Named {
|
||||||
enum class NativeBuildType(val optimized: Boolean, val debuggable: Boolean) : Named {
|
RELEASE(true, false, Framework.BitcodeEmbeddingMode.BITCODE),
|
||||||
RELEASE(true, false),
|
DEBUG(false, true, Framework.BitcodeEmbeddingMode.MARKER);
|
||||||
DEBUG(false, true);
|
|
||||||
|
|
||||||
override fun getName(): String = name.toLowerCase()
|
override fun getName(): String = name.toLowerCase()
|
||||||
|
|
||||||
|
|||||||
+9
@@ -370,11 +370,20 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@get:Input
|
||||||
|
val embedBitcode: Framework.BitcodeEmbeddingMode
|
||||||
|
get() = (binary as? Framework)?.embedBitcode ?: Framework.BitcodeEmbeddingMode.DISABLE
|
||||||
|
|
||||||
override fun buildArgs(defaultsOnly: Boolean): List<String> {
|
override fun buildArgs(defaultsOnly: Boolean): List<String> {
|
||||||
val superArgs = super.buildArgs(defaultsOnly)
|
val superArgs = super.buildArgs(defaultsOnly)
|
||||||
return mutableListOf<String>().apply {
|
return mutableListOf<String>().apply {
|
||||||
addAll(superArgs)
|
addAll(superArgs)
|
||||||
addArgIfNotNull("-entry", entryPoint)
|
addArgIfNotNull("-entry", entryPoint)
|
||||||
|
when (embedBitcode) {
|
||||||
|
Framework.BitcodeEmbeddingMode.MARKER -> add("-Xembed-bitcode-marker")
|
||||||
|
Framework.BitcodeEmbeddingMode.BITCODE -> add("-Xembed-bitcode")
|
||||||
|
else -> { /* Do nothing. */ }
|
||||||
|
}
|
||||||
addListArg("-linker-options", linkerOpts)
|
addListArg("-linker-options", linkerOpts)
|
||||||
exportLibraries.files.filterExternalKlibs(project).forEach {
|
exportLibraries.files.filterExternalKlibs(project).forEach {
|
||||||
add("-Xexport-library=${it.absolutePath}")
|
add("-Xexport-library=${it.absolutePath}")
|
||||||
|
|||||||
Reference in New Issue
Block a user