[Build] Refactor compiling native code to bitcode

Also switch to kts in the corresponding buildscripts.
This commit is contained in:
Ilya Matveev
2020-10-06 13:03:42 +07:00
committed by Ilya Matveev
parent 9663e724aa
commit cb146e06ab
10 changed files with 275 additions and 177 deletions
+119
View File
@@ -0,0 +1,119 @@
/*
* Copyright 2010-2020 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.*
import org.jetbrains.kotlin.bitcode.CompileToBitcode
plugins {
id("compile-to-bitcode")
}
fun CompileToBitcode.includeRuntime() {
headersDirs += files("../common/src/hash/headers", "src/main/cpp")
}
val hostName: String by project
val targetList: List<String> by project
bitcode {
create("runtime", file("src/main")) {
dependsOn(
":common:${target}Hash",
"${target}StdAlloc",
"${target}OptAlloc",
"${target}Mimalloc",
"${target}Launcher",
"${target}Debug",
"${target}Release",
"${target}Strict",
"${target}Relaxed",
"${target}ProfileRuntime",
"${target}Objc",
"${target}ExceptionsSupport"
)
includeRuntime()
linkerArgs.add(project.file("../common/build/$target/hash.bc").path)
}
create("mimalloc") {
language = CompileToBitcode.Language.C
includeFiles = listOf("**/*.c")
excludeFiles += listOf("**/alloc-override*.c", "**/page-queue.c", "**/static.c")
srcDirs = files("$srcRoot/c")
compilerArgs.add("-DKONAN_MI_MALLOC=1")
headersDirs = files("$srcRoot/c/include")
onlyIf { targetSupportsMimallocAllocator(target) }
}
create("launcher") {
includeRuntime()
}
create("debug") {
includeRuntime()
}
create("std_alloc")
create("opt_alloc")
create("exceptionsSupport", file("src/exceptions_support")) {
includeRuntime()
}
create("release") {
includeRuntime()
}
create("strict") {
includeRuntime()
}
create("relaxed") {
includeRuntime()
}
create("profileRuntime", file("src/profile_runtime"))
create("objc") {
includeRuntime()
}
}
val hostRuntime by tasks.registering {
dependsOn("${hostName}Runtime")
}
val clean by tasks.registering {
doLast {
delete(buildDir)
}
}
val generateJsMath by tasks.registering {
dependsOn(":distCompiler")
doLast {
val distDir: File by project
val jsinteropScript = if (PlatformInfo.isWindows()) "jsinterop.bat" else "jsinterop"
val jsinterop = "$distDir/bin/$jsinteropScript"
val targetDir = "$buildDir/generated"
project.exec {
commandLine(
jsinterop,
"-pkg", "kotlinx.interop.wasm.math",
"-o", "$targetDir/math",
"-target", "wasm32"
)
}
val generated = file("$targetDir/math-build/natives/js_stubs.js")
val mathJs = file("src/main/js/math.js")
mathJs.writeText(
"// NOTE: THIS FILE IS AUTO-GENERATED!\n" +
"// Run ':runtime:generateJsMath' to re-generate it.\n\n"
)
mathJs.appendText(generated.readText())
}
}