1+ @file:OptIn(KotlinxBenchmarkPluginInternalApi ::class )
2+
13import kotlinx.benchmark.gradle.*
24import de.undercouch.gradle.tasks.download.Download
5+ import kotlinx.benchmark.gradle.internal.KotlinxBenchmarkPluginInternalApi
36import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile
47import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
58import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
@@ -9,7 +12,6 @@ import org.jetbrains.kotlin.gradle.targets.js.ir.JsIrBinary
912import org.jetbrains.kotlin.gradle.targets.js.d8.D8RootPlugin
1013import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
1114import org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenRootPlugin
12- import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
1315import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
1416import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
1517
@@ -62,27 +64,16 @@ repositories {
6264 maven(uri(" https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/" ))
6365}
6466
65- val distinguishAttribute = Attribute .of(" kotlinx-benchmark-distinguishAttribute" , String ::class .java)
66-
6767kotlin {
6868 js(IR ) {
6969 this as KotlinJsIrTarget
7070 // d8()
7171 nodejs()
7272 }
73- @OptIn(ExperimentalWasmDsl ::class )
74- wasmJs(" wasm" ) {
75- d8()
76- attributes.attribute(distinguishAttribute, " wasm" )
77- // nodejs()
78- }
7973
80- @OptIn(ExperimentalWasmDsl ::class )
81- wasmJs(" wasmOpt" ) {
74+ wasmJs(" wasm" ) {
8275 d8()
8376 // nodejs()
84- applyBinaryen()
85- attributes.attribute(distinguishAttribute, " wasmOpt" )
8677 }
8778
8879 sourceSets {
@@ -98,13 +89,6 @@ kotlin {
9889 }
9990 }
10091
101- val wasmOptMain by getting {
102- dependencies {
103- implementation(files(" ./kotlinx-benchmarks/kotlinx-benchmark-runtime-wasm-js-0.5.0.klib" ))
104- kotlin.srcDirs(" $rootDir /src/wasmMain" )
105- }
106- }
107-
10892 val jsMain by getting {
10993 dependencies {
11094 implementation(files(" ./kotlinx-benchmarks/kotlinx-benchmark-runtime-jsir-0.5.0.klib" ))
@@ -178,27 +162,39 @@ benchmark {
178162 }
179163
180164 val reportDir = project.buildDir.resolve(reportsDir)
165+ val compileSyncDir = project.buildDir.resolve(" compileSync" )
181166 targets {
182- val bundleSizeList = mutableListOf<String >()
167+ val bundleSizeList = mutableListOf<Pair < String , File > >()
183168 val reportTasks = mutableListOf<TaskProvider <Task >>()
184169 register(" wasm" ) {
185170 reportTasks.add(createReportTargetToTC(reportDir, name))
186- bundleSizeList.add(name)
187171 reportTasks.add(createReportTargetToTC(reportDir, " jsShell_$name " ))
188- bundleSizeList.add(" jsShell_$name " )
172+
173+ val wasmCompileSyncDir = compileSyncDir
174+ .resolve(" wasm" )
175+ .resolve(" wasmBenchmark" )
176+ .resolve(" wasmBenchmarkDevelopmentExecutable" )
177+ .resolve(" kotlin" )
178+ bundleSizeList.add(" wasm" to wasmCompileSyncDir)
189179 }
190180 register(" wasmOpt" ) {
191181 reportTasks.add(createReportTargetToTC(reportDir, name))
192- bundleSizeList.add(name)
193182 reportTasks.add(createReportTargetToTC(reportDir, " jsShell_$name " ))
194- bundleSizeList.add(" jsShell_$name " )
183+ val wasmCompileSyncDir = compileSyncDir
184+ .resolve(" wasm" )
185+ .resolve(" wasmBenchmark" )
186+ .resolve(" wasmBenchmarkProductionExecutable" )
187+ .resolve(" optimized" )
188+ bundleSizeList.add(" wasmOpt" to wasmCompileSyncDir)
195189 }
196190 register(" js" ) {
197191 (this as JsBenchmarkTarget ).jsBenchmarksExecutor = JsBenchmarksExecutor .BuiltIn
198192 reportTasks.add(createReportTargetToTC(reportDir, name))
199- bundleSizeList.add(name)
200193 reportTasks.add(createReportTargetToTC(reportDir, " jsShell_$name " ))
201- bundleSizeList.add(" jsShell_$name " )
194+ val wasmCompileSyncDir = compileSyncDir
195+ .resolve(" js" )
196+ .resolve(" jsBenchmark" )
197+ bundleSizeList.add(" js" to wasmCompileSyncDir)
202198 }
203199
204200 reportTasks.add(registerReportBundleSizes(bundleSizeList))
@@ -245,13 +241,15 @@ fun tryGetBinary(compilation: KotlinJsCompilation, mode: KotlinJsBinaryMode): Js
245241 (compilation.target as ? KotlinJsIrTarget )
246242 ?.binaries
247243 ?.executable(compilation)
248- ?.first { it.mode == mode } as ? JsIrBinary
244+ ?.first { it.mode == mode }
249245
250246fun Project.createJsShellExec (
251247 config : BenchmarkConfiguration ,
252248 target : BenchmarkTarget ,
253249 compilation : KotlinJsCompilation ,
254- taskName : String
250+ taskName : String ,
251+ mode : KotlinJsBinaryMode ,
252+ fileNamePostfix : String ,
255253): TaskProvider <Exec > = tasks.register(taskName, Exec ::class ) {
256254 dependsOn(compilation.runtimeDependencyFiles)
257255 dependsOn(unzipJsShell)
@@ -265,7 +263,7 @@ fun Project.createJsShellExec(
265263 newArgs.add(" --wasm-gc" )
266264 newArgs.add(" --wasm-function-references" )
267265
268- val productionBinary = tryGetBinary(compilation, KotlinJsBinaryMode . PRODUCTION ) ? : error(" Not found production binary" )
266+ val productionBinary = tryGetBinary(compilation, mode ) ? : error(" Not found production binary" )
269267 dependsOn(productionBinary.linkSyncTask)
270268
271269 val inputFile = productionBinary.mainFile
@@ -277,10 +275,9 @@ fun Project.createJsShellExec(
277275 } else {
278276 newArgs.add(" --file=${inputFileAsFile.absolutePath} " )
279277 }
280- val reportFile = setupReporting(target, config)
281- val jsShellReportFile = File (reportFile.parentFile, " jsShell_" + reportFile.name)
278+ val reportFile = setupReporting(target, config, " jsShell_" , fileNamePostfix)
282279 newArgs.add(" --" )
283- newArgs.add(writeParameters(target.name, jsShellReportFile , traceFormat(), config).absolutePath)
280+ newArgs.add(writeParameters(target.name, reportFile , traceFormat(), config).absolutePath)
284281 args = newArgs
285282 standardOutput = ConsoleAndFilesOutputStream ()
286283}
@@ -289,13 +286,14 @@ fun Project.createJsShellExec(
289286fun Project.createJsEngineBenchmarkExecTask (
290287 config : BenchmarkConfiguration ,
291288 target : BenchmarkTarget ,
292- compilation : KotlinJsCompilation
289+ compilation : KotlinJsCompilation ,
290+ mode : KotlinJsBinaryMode ,
293291) {
294- val taskName = " jsShell_${target.name}${config.capitalizedName()}${BenchmarksPlugin .BENCHMARK_EXEC_SUFFIX } "
292+ val postfix = if (mode == KotlinJsBinaryMode .DEVELOPMENT ) " " else " Opt"
293+ val taskName = " jsShell_${target.name}$postfix${config.capitalizedName()}${BenchmarksPlugin .BENCHMARK_EXEC_SUFFIX } "
295294 val compilationTarget = compilation.target
296295 if (compilationTarget is KotlinWasmSubTargetContainerDsl ) {
297- check(compilation is KotlinJsCompilation ) { " Legacy Kotlin/JS is does not supported by JsShell engine" }
298- val execTask = createJsShellExec(config, target, compilation, taskName)
296+ val execTask = createJsShellExec(config, target, compilation, taskName, mode, postfix)
299297 tasks.getByName(config.prefixName(BenchmarksPlugin .RUN_BENCHMARKS_TASKNAME )).dependsOn(execTask)
300298 }
301299}
@@ -311,7 +309,8 @@ afterEvaluate {
311309 if (compilation != null ) {
312310 target.extension.configurations.forEach { config ->
313311 val benchmarkCompilation = compilation.target.compilations.maybeCreate(target.name + BenchmarksPlugin .BENCHMARK_COMPILATION_SUFFIX ) as KotlinJsCompilation
314- createJsEngineBenchmarkExecTask(config, target, benchmarkCompilation)
312+ createJsEngineBenchmarkExecTask(config, target, benchmarkCompilation, KotlinJsBinaryMode .PRODUCTION )
313+ createJsEngineBenchmarkExecTask(config, target, benchmarkCompilation, KotlinJsBinaryMode .DEVELOPMENT )
315314 }
316315 }
317316 }
0 commit comments