Files
kotlin-fork/runtime/build.gradle
T
2020-05-06 13:53:10 +03:00

107 lines
4.1 KiB
Groovy

/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import org.jetbrains.kotlin.CompileToBitcode
import org.jetbrains.kotlin.CompilationDatabaseKt
import org.jetbrains.kotlin.UtilsKt
// TODO: consider using some Gradle plugins to build and test
void includeRuntime(CompileToBitcode task) {
task.compilerArgs.add('-I' + project.file('../common/src/hash/headers'))
task.compilerArgs.add('-I' + project.file('src/main/cpp'))
}
targetList.each { targetName ->
tasks.create("${targetName}Runtime", CompileToBitcode, file('src/main'), "runtime", targetName).configure {
dependsOn ":common:${targetName}Hash"
dependsOn "${targetName}StdAlloc"
dependsOn "${targetName}OptAlloc"
dependsOn "${targetName}Mimalloc"
dependsOn "${targetName}Launcher"
dependsOn "${targetName}Debug"
dependsOn "${targetName}Release"
dependsOn "${targetName}Strict"
dependsOn "${targetName}Relaxed"
dependsOn "${targetName}ProfileRuntime"
dependsOn "${targetName}ObjC"
dependsOn "${targetName}ExceptionsSupport"
includeRuntime(delegate)
linkerArgs.add(project.file("../common/build/$targetName/hash.bc").path)
}
tasks.create("${targetName}Mimalloc", CompileToBitcode, file('src/mimalloc'), "mimalloc", targetName).configure {
language = CompileToBitcode.Language.C
excludeFiles.addAll(["**/alloc-override*.c", "**/page-queue.c", "**/static.c"])
if (!UtilsKt.targetSupportsMimallocAllocator(targetName))
excludedTargets.add(targetName)
srcDir = new File(srcRoot, "c")
compilerArgs.add("-DKONAN_MI_MALLOC=1")
headersDir = new File(srcDir, "include")
}
tasks.create("${targetName}Launcher", CompileToBitcode, file('src/launcher'), "launcher", targetName).configure {
includeRuntime(delegate)
}
tasks.create("${targetName}Debug", CompileToBitcode, file('src/debug'), "debug", targetName).configure {
includeRuntime(delegate)
}
tasks.create("${targetName}StdAlloc", CompileToBitcode, file('src/std_alloc'), "std_alloc", targetName)
tasks.create("${targetName}OptAlloc", CompileToBitcode, file('src/opt_alloc'), "opt_alloc", targetName)
tasks.create("${targetName}ExceptionsSupport", CompileToBitcode, file('src/exceptions_support'),
"exceptionsSupport", targetName).configure {
includeRuntime(delegate)
}
tasks.create("${targetName}Release", CompileToBitcode, file('src/release'), "release", targetName).configure {
includeRuntime(delegate)
}
tasks.create("${targetName}Strict", CompileToBitcode, file('src/strict'), "strict", targetName).configure {
includeRuntime(delegate)
}
tasks.create("${targetName}Relaxed", CompileToBitcode, file('src/relaxed'), "relaxed", targetName).configure {
includeRuntime(delegate)
}
tasks.create("${targetName}ProfileRuntime", CompileToBitcode, file('src/profile_runtime'),
"profileRuntime", targetName)
tasks.create("${targetName}ObjC", CompileToBitcode, file('src/objc'), "objc", targetName).configure {
includeRuntime(delegate)
}
}
CompilationDatabaseKt.createCompilationDatabasesFromCompileToBitcodeTasks(project, "CompilationDatabase")
task hostRuntime(dependsOn: "${hostName}Runtime")
task clean {
doLast {
delete buildDir
}
}
task generateJsMath {
dependsOn ':distCompiler'
doLast {
def jsinteropScript = isWindows() ? "jsinterop.bat" : "jsinterop"
def jsinterop = "$distDir/bin/$jsinteropScript"
def targetDir = "$buildDir/generated"
"$jsinterop -pkg kotlinx.interop.wasm.math -o $targetDir/math -target wasm32".execute().waitFor()
def generated = file("$targetDir/math-build/natives/js_stubs.js")
def mathJs = file('src/main/js/math.js')
mathJs.write("// NOTE: THIS FILE IS AUTO-GENERATED!\n" +
"// Run ':runtime:generateJsMath' to re-generate it.\n\n")
generated.withReader {
mathJs.append(it)
}
}
}