Files
kotlin-fork/kotlin-native/performance/framework/build.gradle
T
Svyatoslav Scherbina e22d9821e2 Native: fix kotlin-native/performance/framework build script for K2
The build script manually specifies which directories are parts of
which source sets. And it did that wrong: all directories were just
added to the nativeMain source set.
This was an incorrect configuration (matching expect and actual were
getting into the same source set), and K2 compiler was not really happy
with that.

This commit fixes the correspondence between source sets and source
directories in kotlin-native/performance/framework build script, thus
fixes the build for that benchmark with K2.
2023-10-05 09:17:58 +00:00

130 lines
4.6 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 {
ext.rootBuildDirectory = file('../..')
apply from: "$rootProject.projectDir/../gradle/kotlinGradlePlugin.gradle"
}
apply plugin: 'kotlin-multiplatform'
def toolsPath = '../../tools'
def frameworkName = 'benchmarksAnalyzer'
def buildType = NativeBuildType.valueOf(findProperty('nativeBuildType') ?: 'DEBUG')
def archSuffix = PlatformInfo.hostName.substring(PlatformInfo.hostName.lastIndexOf('_') + 1).capitalize()
kotlin {
sourceSets {
commonMain {
kotlin.srcDir "$toolsPath/benchmarks/shared/src"
kotlin.srcDir "$toolsPath/benchmarksAnalyzer/src/main/kotlin"
kotlin.srcDir "$rootProject.projectDir/../endorsedLibraries/kotlinx.cli/src/main/kotlin"
}
nativeMain {
dependsOn commonMain
kotlin.srcDir "$rootProject.projectDir/../endorsedLibraries/kotlinx.cli/src/main/kotlin-native"
kotlin.srcDir "$toolsPath/benchmarksAnalyzer/src/main/kotlin-native"
}
macosX64Main { dependsOn nativeMain }
macosArm64Main { dependsOn nativeMain }
}
configure([macosX64(), macosArm64()]) {
compilations.main.cinterops {
libcurl {
defFile "$toolsPath/benchmarksAnalyzer/src/nativeInterop/cinterop/libcurl.def"
}
}
}
macosX64().binaries {
framework(frameworkName, [buildType])
}
macosArm64().binaries {
framework(frameworkName, [buildType])
}
}
MPPTools.addTimeListener(project)
task konanRun {
if (PlatformInfo.isMac()) {
dependsOn "linkBenchmarksAnalyzerDebugFrameworkMacos${archSuffix}"
}
}
/**
* 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
}
def getMacTarget() {
if (PlatformInfo.isMac()) {
if (PlatformInfo.hostName == "macos_x64")
return kotlin.macosX64("macosX64")
else return kotlin.macosArm64("macosArm64")
}
throw new GradleException('Current host isn\'t run with Mac OS')
}
task konanJsonReport {
doLast {
if (PlatformInfo.isMac()) {
def applicationName = "FrameworkBenchmarksAnalyzer"
def macTarget = getMacTarget()
def frameworkPath = macTarget.binaries.
getFramework(frameworkName, macTarget.binaries.DEBUG).outputFile.absolutePath
def nativeExecutable = new File("$frameworkPath/$frameworkName").canonicalPath
def nativeCompileTime = MPPTools.getNativeCompileTime(project, applicationName, ["compileKotlinMacos${archSuffix}".toString(),
"linkBenchmarksAnalyzerDebugFrameworkMacos${archSuffix}".toString(),
"cinteropLibcurlMacos${archSuffix}".toString()])
def properties = getCommonProperties() + ['type' : 'native',
'compilerVersion': "${kotlinVersion}".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()]
}