[gradle-plugin] Support custom linker options for binaries
This commit is contained in:
committed by
Ilya Matveev
parent
c012aa5d32
commit
62e3145ca9
+8
@@ -71,6 +71,14 @@ interface KotlinNativeBinary: ComponentWithDependencies, BuildableComponent {
|
||||
*/
|
||||
val additionalCompilerOptions: Collection<String>
|
||||
|
||||
// DSL.
|
||||
/**
|
||||
* Additional options passed to a linker when this binary is built.
|
||||
*/
|
||||
val linkerOpts: MutableList<String>
|
||||
fun linkerOpts(values: List<String>)
|
||||
fun linkerOpts(vararg values: String)
|
||||
|
||||
companion object {
|
||||
val KONAN_TARGET_ATTRIBUTE = Attribute.of("org.gradle.native.kotlin.platform", String::class.java)
|
||||
}
|
||||
|
||||
+9
@@ -61,6 +61,9 @@ interface KotlinNativeComponent: ComponentWithBinaries, ComponentWithDependencie
|
||||
|
||||
// region DSL
|
||||
|
||||
/** Allows a user to specify targets this component is built for. */
|
||||
var targets: List<String>
|
||||
|
||||
/** Provides an access to component's dependencies including cinterop and jsinterop DSL */
|
||||
override fun getDependencies(): KotlinNativeDependencies
|
||||
|
||||
@@ -69,8 +72,14 @@ interface KotlinNativeComponent: ComponentWithBinaries, ComponentWithDependencie
|
||||
fun dependencies(action: Action<KotlinNativeDependencies>)
|
||||
|
||||
/** Set native targets for this component. */
|
||||
@Deprecated("Use the 'targets' property instead. E.g. targets = ['macos_x64', 'linux_x64']")
|
||||
fun target(vararg targets: String)
|
||||
|
||||
/** Provide a way to configure binaries included in this component for a particular target. */
|
||||
fun target(target: String, action: KotlinNativeBinary.() -> Unit)
|
||||
fun target(target: String, action: Closure<Unit>)
|
||||
fun target(target: String, action: Action<KotlinNativeBinary>)
|
||||
|
||||
/** Set additional compiler options for this component. */
|
||||
val extraOpts: Collection<String>
|
||||
|
||||
|
||||
+6
@@ -135,4 +135,10 @@ abstract class AbstractKotlinNativeBinary(
|
||||
|
||||
override val additionalCompilerOptions: Collection<String>
|
||||
get() = component.extraOpts
|
||||
|
||||
override val linkerOpts = mutableListOf<String>()
|
||||
override fun linkerOpts(values: List<String>) = linkerOpts(*values.toTypedArray())
|
||||
override fun linkerOpts(vararg values: String) {
|
||||
linkerOpts.addAll(values)
|
||||
}
|
||||
}
|
||||
+27
-3
@@ -77,11 +77,35 @@ abstract class AbstractKotlinNativeComponent @Inject constructor(
|
||||
|
||||
override fun getImplementationDependencies(): Configuration = dependencies.implementationDependencies
|
||||
|
||||
// region DSL
|
||||
// region DSL.
|
||||
|
||||
override var targets: List<String>
|
||||
get() = konanTargets.get().map { it.name }
|
||||
set(value) {
|
||||
val hostManager = HostManager()
|
||||
konanTargets.set(targets.map { hostManager.targetByName(it) })
|
||||
}
|
||||
|
||||
override fun target(target: String, action: KotlinNativeBinary.() -> Unit) =
|
||||
binaries.whenElementKnown {
|
||||
if (it.konanTarget == HostManager().targetByName(target)) {
|
||||
it.action()
|
||||
}
|
||||
}
|
||||
|
||||
override fun target(target: String, action: Closure<Unit>) =
|
||||
target(target, ConfigureUtil.configureUsing(action))
|
||||
|
||||
override fun target(target: String, action: Action<KotlinNativeBinary>) =
|
||||
target(target) { action.execute(this) }
|
||||
|
||||
@Deprecated("Use the 'targets' property instead. E.g. targets = ['macos_x64', 'linux_x64']")
|
||||
override fun target(vararg targets: String) {
|
||||
val hostManager = HostManager()
|
||||
konanTargets.set(targets.map { hostManager.targetByName(it) })
|
||||
project.logger.warn("""
|
||||
Kotlin/Native component's method 'target' is deprecated. Use the 'targets' property instead.
|
||||
E.g. targets = ['macos_x64', 'linux_x64']
|
||||
""".trimIndent())
|
||||
this.targets = targets.toList()
|
||||
}
|
||||
|
||||
override val extraOpts = mutableListOf<String>()
|
||||
|
||||
+4
-3
@@ -32,8 +32,8 @@ import org.gradle.nativeplatform.test.tasks.RunTestExecutable
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.KonanPlugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.CInteropSettings
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeLibrary
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.cinterop.CInteropSettingsImpl
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.tasks.CInteropTask
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.tasks.KotlinNativeCompile
|
||||
import org.jetbrains.kotlin.gradle.plugin.hasProperty
|
||||
@@ -184,9 +184,7 @@ class KotlinNativeBasePlugin: Plugin<ProjectInternal> {
|
||||
}
|
||||
|
||||
private fun Project.addInteropTasks() {
|
||||
|
||||
val settingsToTask = mutableMapOf<CInteropSettings, CInteropTask>()
|
||||
|
||||
components.withType(AbstractKotlinNativeBinary::class.java) { binary ->
|
||||
binary.component.dependencies.cinterops.all { cinterop ->
|
||||
val konanTarget = binary.konanTarget
|
||||
@@ -204,6 +202,9 @@ class KotlinNativeBasePlugin: Plugin<ProjectInternal> {
|
||||
}
|
||||
|
||||
binary.klibraries.dependencies.add(dependencies.create(files(interopTask.outputFileProvider)))
|
||||
if (binary is KotlinNativeLibrary) {
|
||||
binary.linkElements.get().outgoing.artifact(interopTask.outputFileProvider)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -24,10 +24,7 @@ import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFiles
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.jetbrains.kotlin.gradle.plugin.KonanCompilerRunner
|
||||
import org.jetbrains.kotlin.gradle.plugin.KonanPlugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.addArg
|
||||
import org.jetbrains.kotlin.gradle.plugin.addKey
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.AbstractKotlinNativeBinary
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind.*
|
||||
@@ -59,6 +56,9 @@ open class KotlinNativeCompile @Inject constructor(internal val binary: Abstract
|
||||
|
||||
val additionalCompilerOptions: Collection<String> @Input get() = binary.additionalCompilerOptions
|
||||
|
||||
val linkerOpts: List<String>
|
||||
@Input get() = binary.linkerOpts
|
||||
|
||||
val outputFile: File
|
||||
get() = outputLocationProvider.get().asFile
|
||||
|
||||
@@ -120,6 +120,8 @@ open class KotlinNativeCompile @Inject constructor(internal val binary: Abstract
|
||||
addArg("-l", library.nameWithoutExtension)
|
||||
}
|
||||
|
||||
addListArg("-linkerOpts", linkerOpts)
|
||||
|
||||
addAll(sources.files.map { it.absolutePath })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user