[WASM] Add binaryen dsl
This commit is contained in:
+8
-2
@@ -18,7 +18,7 @@ interface KotlinWasmSubTargetContainerDsl : KotlinTarget {
|
||||
|
||||
fun whenD8Configured(body: KotlinWasmD8Dsl.() -> Unit)
|
||||
|
||||
fun whenBinaryenApplied(body: () -> Unit)
|
||||
fun whenBinaryenApplied(body: (BinaryenExec.() -> Unit) -> Unit)
|
||||
}
|
||||
|
||||
interface KotlinWasmTargetDsl : KotlinJsTargetDsl {
|
||||
@@ -30,7 +30,13 @@ interface KotlinWasmTargetDsl : KotlinJsTargetDsl {
|
||||
}
|
||||
}
|
||||
|
||||
fun applyBinaryen()
|
||||
fun applyBinaryen() = applyBinaryen { }
|
||||
fun applyBinaryen(body: BinaryenExec.() -> Unit)
|
||||
fun applyBinaryen(fn: Closure<*>) {
|
||||
applyBinaryen {
|
||||
ConfigureUtil.configure(fn, this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface KotlinWasmD8Dsl : KotlinJsSubTargetDsl {
|
||||
|
||||
+3
-2
@@ -40,7 +40,7 @@ constructor(
|
||||
private val defaultCompilation: KotlinJsCompilation
|
||||
get() = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
||||
|
||||
private fun configureBinaryen(binary: JsIrBinary) {
|
||||
private fun configureBinaryen(binary: JsIrBinary, binaryenDsl: BinaryenExec.() -> Unit) {
|
||||
val linkTask = binary.linkTask
|
||||
|
||||
val compiledMjsFile = linkTask.map { link ->
|
||||
@@ -56,6 +56,7 @@ constructor(
|
||||
val binaryenTask = BinaryenExec.create(binary.compilation, "${linkTask.name}Optimize") {
|
||||
inputFileProperty.fileProvider(compiledWasmFile)
|
||||
outputFileProperty.fileProvider(compiledWasmFile)
|
||||
binaryenDsl()
|
||||
}
|
||||
|
||||
binary.compilation.compileKotlinTask.finalizedBy(binaryenTask)
|
||||
@@ -203,7 +204,7 @@ constructor(
|
||||
|
||||
if (compilation.platformType == KotlinPlatformType.wasm && target is KotlinJsIrTarget && binary is JsIrBinary) {
|
||||
target.whenBinaryenApplied {
|
||||
configureBinaryen(binary)
|
||||
configureBinaryen(binary, it)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-8
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinTargetWithBinaries
|
||||
import org.jetbrains.kotlin.gradle.targets.js.JsAggregatingExecutionSource
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsReportAggregatingTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenExec
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
|
||||
@@ -149,22 +150,23 @@ constructor(
|
||||
}
|
||||
|
||||
//Binaryen
|
||||
private val applyBinaryenHandlers = mutableListOf<() -> Unit>()
|
||||
private val applyBinaryenHandlers = mutableListOf<(BinaryenExec.() -> Unit) -> Unit>()
|
||||
|
||||
private var binaryenApplied: Boolean = false
|
||||
private var binaryenApplied: (BinaryenExec.() -> Unit)? = null
|
||||
|
||||
override fun whenBinaryenApplied(body: () -> Unit) {
|
||||
if (binaryenApplied) {
|
||||
body()
|
||||
override fun whenBinaryenApplied(body: (BinaryenExec.() -> Unit) -> Unit) {
|
||||
val binaryenApplied = binaryenApplied
|
||||
if (binaryenApplied != null) {
|
||||
body(binaryenApplied)
|
||||
} else {
|
||||
applyBinaryenHandlers += body
|
||||
}
|
||||
}
|
||||
|
||||
override fun applyBinaryen() {
|
||||
binaryenApplied = true
|
||||
override fun applyBinaryen(body: BinaryenExec.() -> Unit) {
|
||||
binaryenApplied = body
|
||||
applyBinaryenHandlers.forEach { handler ->
|
||||
handler()
|
||||
handler(body)
|
||||
}
|
||||
browserConfiguredHandlers.clear()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user