Files
kotlin-fork/kotlin-native/performance/framework/build.gradle
T
2021-04-05 10:52:55 +00:00

116 lines
3.8 KiB
Groovy

import org.jetbrains.kotlin.MPPTools
import org.jetbrains.kotlin.PlatformInfo
import org.jetbrains.kotlin.RunJvmTask
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
buildscript {
apply from: "$rootProject.projectDir/../gradle/kotlinGradlePlugin.gradle"
repositories {
jcenter()
}
}
apply plugin: 'kotlin-multiplatform'
repositories {
jcenter()
}
def toolsPath = '../../tools'
def frameworkName = 'benchmarksAnalyzer'
def buildType = NativeBuildType.valueOf(findProperty('nativeBuildType') ?: 'DEBUG')
kotlin {
sourceSets {
macosMain {
kotlin.srcDir "$toolsPath/benchmarks/shared/src"
kotlin.srcDir "$toolsPath/benchmarksAnalyzer/src/main/kotlin"
kotlin.srcDir "$rootProject.projectDir/../endorsedLibraries/kotlinx.cli/src/main/kotlin"
kotlin.srcDir "$rootProject.projectDir/../endorsedLibraries/kotlinx.cli/src/main/kotlin-native"
kotlin.srcDir "$toolsPath/benchmarksAnalyzer/src/main/kotlin-native"
}
}
configure([macosX64("macos")]) {
compilations.main.cinterops {
libcurl {
defFile "$toolsPath/benchmarksAnalyzer/src/nativeInterop/cinterop/libcurl.def"
}
}
}
macosX64("macos").binaries {
framework(frameworkName, [buildType])
}
}
MPPTools.addTimeListener(project)
task konanRun {
if (PlatformInfo.isMac()) {
dependsOn 'build'
}
}
/**
* TODO: it would be better to make help function generating such nop task in buildSrc.
*/
task jvmRun {
doLast {
println("JVM run is unsupported")
}
}
def compilerFlags(def buildType) {
def result = []
if (buildType.optimized) {
result.add("-opt")
}
if (buildType.debuggable) {
result.add("-g")
}
return result
}
task konanJsonReport {
doLast {
if (PlatformInfo.isMac()) {
def applicationName = "FrameworkBenchmarksAnalyzer"
def frameworkPath = kotlin.macosX64("macos").binaries.
getFramework(frameworkName, kotlin.macosX64("macos").binaries.DEBUG).outputFile.absolutePath
def nativeExecutable = new File("$frameworkPath/$frameworkName").canonicalPath
def nativeCompileTime = MPPTools.getNativeCompileTime(project, applicationName, ['compileKotlinMacos',
'linkBenchmarksAnalyzerDebugFrameworkMacos',
'cinteropLibcurlMacos'])
def properties = getCommonProperties() + ['type' : 'native',
'compilerVersion': "${konanVersion}".toString(),
'flags' : compilerFlags(buildType).sort(),
'benchmarks' : '[]',
'compileTime' : [nativeCompileTime],
'codeSize' : MPPTools.getCodeSizeBenchmark(applicationName, nativeExecutable)]
def output = MPPTools.createJsonReport(properties)
new File("${buildDir.absolutePath}/${nativeJson}").write(output)
}
}
}
task jvmJsonReport {
doLast {
println("JVM run is unsupported")
}
}
jvmRun.finalizedBy jvmJsonReport
konanRun.finalizedBy konanJsonReport
private def getCommonProperties() {
return ['cpu': System.getProperty("os.arch"),
'os': System.getProperty("os.name"), // OperatingSystem.current().getName()
'jdkVersion': System.getProperty("java.version"), // org.gradle.internal.jvm.Jvm.current().javaVersion
'jdkVendor': System.getProperty("java.vendor"),
'kotlinVersion': "${kotlinVersion}".toString()]
}