Support Native binary options in Gradle

Both project properties and per-binary DSL are available.
This commit is contained in:
Svyatoslav Scherbina
2021-08-10 12:06:12 +03:00
committed by Space
parent 9877a7271a
commit 5e789f86ee
2 changed files with 27 additions and 0 deletions
@@ -71,6 +71,13 @@ sealed class NativeBinary(
linkerOpts.addAll(options)
}
var binaryOptions: MutableMap<String, String> = mutableMapOf()
fun binaryOption(name: String, value: String) {
// TODO: report if $name is unknown?
binaryOptions[name] = value
}
/** Additional arguments passed to the Kotlin/Native compiler. */
var freeCompilerArgs: List<String>
get() = linkTask.kotlinOptions.freeCompilerArgs
@@ -585,6 +585,19 @@ constructor(
val linkerOpts: List<String>
@Input get() = binary.linkerOpts
val binaryOptions: Map<String, String>
@Input get() = binary.binaryOptions
val projectWideBinaryOptions: Map<String, String>
@Input get() = project.properties.mapNotNull { (name, value) ->
val prefix = KOTLIN_NATIVE_BINARY_OPTION_PREFIX
if (name.startsWith(prefix) && value is String) {
name.removePrefix(prefix) to value
} else {
null
}
}.toMap()
val processTests: Boolean
@Input get() = binary is TestExecutable
@@ -628,6 +641,9 @@ constructor(
linkerOpts.forEach {
addArg("-linker-option", it)
}
(projectWideBinaryOptions + binaryOptions).forEach { (name, value) ->
add("-Xbinary=$name=$value")
}
exportLibraries.files.filterKlibsPassedToCompiler().forEach {
add("-Xexport-library=${it.absolutePath}")
}
@@ -689,6 +705,10 @@ constructor(
validatedExportedLibraries()
super.compile()
}
private companion object {
const val KOTLIN_NATIVE_BINARY_OPTION_PREFIX = "kotlin.native.binary."
}
}
private class ExternalDependenciesBuilder(