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