[K/N][build] Move stdlib build to runtime project
Build stdlib with konan plugin in runtime project
This commit is contained in:
@@ -138,84 +138,6 @@ dependencies {
|
|||||||
|
|
||||||
classes.dependsOn 'compilerClasses', 'cli_bcClasses'
|
classes.dependsOn 'compilerClasses', 'cli_bcClasses'
|
||||||
|
|
||||||
|
|
||||||
// These are just a couple of aliases
|
|
||||||
task stdlib(dependsOn: "${hostName}Stdlib")
|
|
||||||
|
|
||||||
def commonSrc = project(":kotlin-stdlib-common").files("src/kotlin", "src/generated", "../unsigned/src", "../src").files
|
|
||||||
def commonBuiltinsSrc = project(":core:builtins").files(
|
|
||||||
["Progressions.kt", "ProgressionIterators.kt", "Range.kt", "Ranges.kt", "internal/progressionUtil.kt"]
|
|
||||||
.collect { "src/kotlin/$it" }).files
|
|
||||||
|
|
||||||
def interopRuntimeCommonSrc = project(':kotlin-native:Interop:Runtime').file('src/main/kotlin')
|
|
||||||
|
|
||||||
final List<File> stdLibSrc = [
|
|
||||||
interopRuntimeCommonSrc,
|
|
||||||
project(':kotlin-native:Interop:Runtime').file('src/native/kotlin'),
|
|
||||||
project(':kotlin-native:Interop:JsRuntime').file('src/main/kotlin'),
|
|
||||||
project(':kotlin-native:runtime').file('src/main/kotlin'),
|
|
||||||
project(":kotlin-stdlib-common").file('../native-wasm/src/')
|
|
||||||
]
|
|
||||||
|
|
||||||
// These files are built before the 'dist' is complete,
|
|
||||||
// so we provide a custom value for --runtime
|
|
||||||
|
|
||||||
targetList.each { target ->
|
|
||||||
def konanJvmArgs = [*HostManager.regularJvmArgs]
|
|
||||||
|
|
||||||
def defaultArgs = ['-nopack', '-nostdlib', '-no-default-libs', '-no-endorsed-libs',
|
|
||||||
//Uncomment this '-Werror' when common stdlib will be ready
|
|
||||||
]
|
|
||||||
if (target != "wasm32") defaultArgs += '-g'
|
|
||||||
def konanArgs = [*defaultArgs,
|
|
||||||
'-target', target,
|
|
||||||
"-Xruntime=${project(':kotlin-native:runtime').file('build/bitcode/main/' + target + '/runtime.bc')}",
|
|
||||||
*project.globalBuildArgs]
|
|
||||||
|
|
||||||
task("${target}Stdlib", type: JavaExec) {
|
|
||||||
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
|
||||||
// This task depends on distCompiler, so the compiler jar is already in the dist directory.
|
|
||||||
classpath = fileTree("${UtilsKt.getKotlinNativeDist(project)}/konan/lib") {
|
|
||||||
include "*.jar"
|
|
||||||
}
|
|
||||||
systemProperties "konan.home": UtilsKt.getKotlinNativeDist(project)
|
|
||||||
jvmArgs = konanJvmArgs
|
|
||||||
def testAnnotationCommon = project(":kotlin-test:kotlin-test-annotations-common").files("src/main/kotlin").files
|
|
||||||
def testCommon = project(":kotlin-test:kotlin-test-common").files("src/main/kotlin").files
|
|
||||||
args = [*konanArgs,
|
|
||||||
'-output', project(':kotlin-native:runtime').file("build/${target}Stdlib"),
|
|
||||||
'-produce', 'library', '-module-name', 'stdlib',
|
|
||||||
'-Xmulti-platform', '-opt-in=kotlin.RequiresOptIn',
|
|
||||||
'-opt-in=kotlin.contracts.ExperimentalContracts',
|
|
||||||
'-opt-in=kotlin.ExperimentalMultiplatform',
|
|
||||||
'-opt-in=kotlin.native.internal.InternalForKotlinNative',
|
|
||||||
'-opt-in=kotlin.native.SymbolNameIsDeprecated',
|
|
||||||
*commonSrc.toList(),
|
|
||||||
*commonBuiltinsSrc.toList(),
|
|
||||||
*testAnnotationCommon.toList(),
|
|
||||||
*testCommon.toList(),
|
|
||||||
"-Xcommon-sources=${commonSrc.join(',')}",
|
|
||||||
"-Xcommon-sources=${testAnnotationCommon.join(',')}",
|
|
||||||
"-Xcommon-sources=${testCommon.join(',')}",
|
|
||||||
"-Xcommon-sources=$interopRuntimeCommonSrc",
|
|
||||||
*stdLibSrc]
|
|
||||||
stdLibSrc.forEach { inputs.dir(it) }
|
|
||||||
commonSrc.forEach{
|
|
||||||
inputs.dir(it)
|
|
||||||
}
|
|
||||||
outputs.dir(project(':kotlin-native:runtime').file("build/${target}Stdlib"))
|
|
||||||
|
|
||||||
dependsOn ":kotlin-native:runtime:${target}Runtime"
|
|
||||||
dependsOn ":kotlin-native:distCompiler"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
task run {
|
|
||||||
doLast {
|
|
||||||
logger.quiet("Run the outer project 'demo' target to compile the test source.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
from sourceSets.cli_bc.output,
|
from sourceSets.cli_bc.output,
|
||||||
sourceSets.compiler.output,
|
sourceSets.compiler.output,
|
||||||
|
|||||||
@@ -93,10 +93,9 @@ gradlePlugin {
|
|||||||
val compileKotlin: KotlinCompile by tasks
|
val compileKotlin: KotlinCompile by tasks
|
||||||
val compileGroovy: GroovyCompile by tasks
|
val compileGroovy: GroovyCompile by tasks
|
||||||
|
|
||||||
// https://youtrack.jetbrains.com/issue/KT-37435
|
|
||||||
compileKotlin.apply {
|
compileKotlin.apply {
|
||||||
kotlinOptions.jvmTarget = "1.8"
|
kotlinOptions.jvmTarget = "1.8"
|
||||||
kotlinOptions.freeCompilerArgs += listOf("-Xno-optimized-callable-references", "-Xskip-prerelease-check")
|
kotlinOptions.freeCompilerArgs += "-Xskip-prerelease-check"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Kotlin classes to a classpath for the Groovy compiler
|
// Add Kotlin classes to a classpath for the Groovy compiler
|
||||||
|
|||||||
@@ -66,9 +66,10 @@ open class CoverageTest : DefaultTask() {
|
|||||||
override fun configure(closure: Closure<Any>): Task {
|
override fun configure(closure: Closure<Any>): Task {
|
||||||
super.configure(closure)
|
super.configure(closure)
|
||||||
dependsOnDist()
|
dependsOnDist()
|
||||||
val compileBinaryTask = project.tasks.getByName("compileKonan$binaryName")
|
val compileBinaryTask = project.tasks.named("compileKonan$binaryName").configure {
|
||||||
compileBinaryTask.konanOldPluginTaskDependenciesWalker{
|
konanOldPluginTaskDependenciesWalker {
|
||||||
dependsOnDist()
|
dependsOnDist()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dependsOn(compileBinaryTask)
|
dependsOn(compileBinaryTask)
|
||||||
return this
|
return this
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ abstract class KonanTest : DefaultTask(), KonanTestExecutable {
|
|||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
override val buildTasks: List<Task>
|
override val buildTasks: List<Task>
|
||||||
get() = listOf(project.findKonanBuildTask(name, project.testTarget))
|
get() = listOf(project.findKonanBuildTask(name, project.testTarget).get())
|
||||||
|
|
||||||
@Suppress("UnstableApiUsage")
|
@Suppress("UnstableApiUsage")
|
||||||
override fun configure(config: Closure<*>): Task {
|
override fun configure(config: Closure<*>): Task {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import org.gradle.api.NonNullApi
|
|||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.internal.file.FileResolver
|
import org.gradle.api.internal.file.FileResolver
|
||||||
import org.gradle.api.internal.plugins.PotentialPlugin
|
import org.gradle.api.internal.plugins.PotentialPlugin
|
||||||
|
import org.gradle.api.tasks.TaskProvider
|
||||||
import org.gradle.internal.operations.BuildOperationExecutor
|
import org.gradle.internal.operations.BuildOperationExecutor
|
||||||
import org.gradle.internal.os.OperatingSystem
|
import org.gradle.internal.os.OperatingSystem
|
||||||
import org.gradle.internal.reflect.Instantiator
|
import org.gradle.internal.reflect.Instantiator
|
||||||
@@ -124,11 +125,17 @@ fun Task.dependsOnPlatformLibs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val Project.globalTestArgs: List<String>
|
private fun Project.groovyPropertyArrayToList(property: String): List<String> =
|
||||||
get() = with(findProperty("globalTestArgs")) {
|
with(findProperty(property)) {
|
||||||
if (this is Array<*>) this.toList() as List<String>
|
if (this is Array<*>) this.toList() as List<String>
|
||||||
else this as List<String>
|
else this as List<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val Project.globalBuildArgs: List<String>
|
||||||
|
get() = project.groovyPropertyArrayToList("globalBuildArgs")
|
||||||
|
|
||||||
|
val Project.globalTestArgs: List<String>
|
||||||
|
get() = project.groovyPropertyArrayToList("globalTestArgs")
|
||||||
|
|
||||||
val Project.testTargetSupportsCodeCoverage: Boolean
|
val Project.testTargetSupportsCodeCoverage: Boolean
|
||||||
get() = this.testTarget.supportsCodeCoverage()
|
get() = this.testTarget.supportsCodeCoverage()
|
||||||
@@ -189,13 +196,19 @@ fun Project.getFilesToCompile(compile: List<String>, exclude: List<String>): Lis
|
|||||||
|
|
||||||
//region Task dependency.
|
//region Task dependency.
|
||||||
|
|
||||||
fun Project.findKonanBuildTask(artifact: String, target: KonanTarget): Task =
|
fun Project.findKonanBuildTask(artifact: String, target: KonanTarget): TaskProvider<Task> =
|
||||||
tasks.getByName("compileKonan${artifact.capitalize()}${target.name.capitalize()}")
|
tasks.named("compileKonan${artifact.capitalize()}${target.name.capitalize()}")
|
||||||
|
|
||||||
fun Project.dependsOnDist(taskName: String) {
|
fun Project.dependsOnDist(taskName: String) {
|
||||||
project.tasks.getByName(taskName).dependsOnDist()
|
project.tasks.getByName(taskName).dependsOnDist()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun TaskProvider<Task>.dependsOnDist() {
|
||||||
|
configure {
|
||||||
|
dependsOnDist()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun Task.dependsOnDist() {
|
fun Task.dependsOnDist() {
|
||||||
dependsOn(":kotlin-native:dist")
|
dependsOn(":kotlin-native:dist")
|
||||||
val target = project.testTarget
|
val target = project.testTarget
|
||||||
@@ -237,10 +250,12 @@ fun Task.sameDependenciesAs(task: Task) {
|
|||||||
*/
|
*/
|
||||||
fun Task.dependsOnKonanBuildingTask(artifact: String, target: KonanTarget) {
|
fun Task.dependsOnKonanBuildingTask(artifact: String, target: KonanTarget) {
|
||||||
val buildTask = project.findKonanBuildTask(artifact, target)
|
val buildTask = project.findKonanBuildTask(artifact, target)
|
||||||
buildTask.konanOldPluginTaskDependenciesWalker {
|
buildTask.configure {
|
||||||
dependsOnDist()
|
konanOldPluginTaskDependenciesWalker {
|
||||||
|
dependsOnDist()
|
||||||
|
}
|
||||||
|
sameDependenciesAs(this)
|
||||||
}
|
}
|
||||||
buildTask.sameDependenciesAs(this)
|
|
||||||
dependsOn(buildTask)
|
dependsOn(buildTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -401,7 +401,7 @@ def endorsedLibsCopyTask = task("crossDistEndorsedLibrariesCopy", type: Copy) {
|
|||||||
|
|
||||||
targetList.each { target ->
|
targetList.each { target ->
|
||||||
task("${target}CopyStdlibRuntimeBitcode", type: Copy) {
|
task("${target}CopyStdlibRuntimeBitcode", type: Copy) {
|
||||||
dependsOn ":kotlin-native:backend.native:${target}Stdlib"
|
dependsOn ":kotlin-native:runtime:${target}Stdlib"
|
||||||
|
|
||||||
destinationDir project(':kotlin-native:runtime')
|
destinationDir project(':kotlin-native:runtime')
|
||||||
.file("build/${target}Stdlib/default")
|
.file("build/${target}Stdlib/default")
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.konan.target.Architecture as TargetArchitecture
|
|||||||
plugins {
|
plugins {
|
||||||
id("compile-to-bitcode")
|
id("compile-to-bitcode")
|
||||||
id("runtime-testing")
|
id("runtime-testing")
|
||||||
|
id("konan")
|
||||||
}
|
}
|
||||||
|
|
||||||
googletest {
|
googletest {
|
||||||
@@ -319,7 +320,7 @@ val hostExperimentalMMMimallocRuntimeTests by tasks.registering {
|
|||||||
dependsOn("${hostName}ExperimentalMMMimallocRuntimeTests")
|
dependsOn("${hostName}ExperimentalMMMimallocRuntimeTests")
|
||||||
}
|
}
|
||||||
|
|
||||||
val assemble by tasks.registering {
|
val assemble by tasks.getting {
|
||||||
dependsOn(tasks.withType(CompileToBitcode::class).matching {
|
dependsOn(tasks.withType(CompileToBitcode::class).matching {
|
||||||
it.outputGroup == "main"
|
it.outputGroup == "main"
|
||||||
})
|
})
|
||||||
@@ -331,7 +332,7 @@ val hostAssemble by tasks.registering {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
val clean by tasks.registering {
|
val clean by tasks.getting {
|
||||||
doFirst {
|
doFirst {
|
||||||
delete(buildDir)
|
delete(buildDir)
|
||||||
}
|
}
|
||||||
@@ -363,3 +364,84 @@ val generateJsMath by tasks.registering {
|
|||||||
mathJs.appendText(generated.readText())
|
mathJs.appendText(generated.readText())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// region: Stdlib
|
||||||
|
|
||||||
|
val commonStdlibSrcDirs = project(":kotlin-stdlib-common")
|
||||||
|
.files(
|
||||||
|
"src/kotlin",
|
||||||
|
"src/generated",
|
||||||
|
"../unsigned/src",
|
||||||
|
"../src"
|
||||||
|
).files
|
||||||
|
val commonBuiltinsSrc = listOf(
|
||||||
|
"Progressions.kt", "ProgressionIterators.kt", "Range.kt", "Ranges.kt", "internal/progressionUtil.kt")
|
||||||
|
.map { "src/kotlin/$it" }
|
||||||
|
.let {
|
||||||
|
project(":core:builtins").files(it).files
|
||||||
|
}
|
||||||
|
|
||||||
|
val interopRuntimeCommonSrcDir = project(":kotlin-native:Interop:Runtime").file("src/main/kotlin")
|
||||||
|
val interopSrcDir = listOf(
|
||||||
|
interopRuntimeCommonSrcDir,
|
||||||
|
project(":kotlin-native:Interop:Runtime").file("src/native/kotlin"),
|
||||||
|
project(":kotlin-native:Interop:JsRuntime").file("src/main/kotlin")
|
||||||
|
)
|
||||||
|
|
||||||
|
val testAnnotationCommonSrcDir = project(":kotlin-test:kotlin-test-annotations-common").files("src/main/kotlin").files
|
||||||
|
val testCommonSrcDir = project(":kotlin-test:kotlin-test-common").files("src/main/kotlin").files
|
||||||
|
|
||||||
|
val stdLibSrcDirs = interopSrcDir + listOf(
|
||||||
|
project.file("src/main/kotlin"),
|
||||||
|
project(":kotlin-stdlib-common").file("../native-wasm/src/")
|
||||||
|
)
|
||||||
|
|
||||||
|
val args = listOf("-nopack", "-nostdlib", "-no-default-libs", "-no-endorsed-libs", /* -Werror (TODO: check) */)
|
||||||
|
|
||||||
|
lateinit var stdlibBuildTask: TaskProvider<Task>
|
||||||
|
|
||||||
|
konanArtifacts {
|
||||||
|
library("stdlib") {
|
||||||
|
baseDir(project.buildDir.resolve("stdlib"))
|
||||||
|
extraOpts(args + project.globalBuildArgs)
|
||||||
|
extraOpts(
|
||||||
|
"-module-name", "stdlib",
|
||||||
|
"-Xmulti-platform",
|
||||||
|
"-opt-in=kotlin.RequiresOptIn",
|
||||||
|
"-opt-in=kotlin.contracts.ExperimentalContracts",
|
||||||
|
"-opt-in=kotlin.ExperimentalMultiplatform",
|
||||||
|
"-opt-in=kotlin.native.internal.InternalForKotlinNative",
|
||||||
|
"-opt-in=kotlin.native.SymbolNameIsDeprecated"
|
||||||
|
)
|
||||||
|
commonStdlibSrcDirs.forEach { extraOpts(it) }
|
||||||
|
srcFiles(commonBuiltinsSrc)
|
||||||
|
testAnnotationCommonSrcDir.forEach { extraOpts(it) }
|
||||||
|
testCommonSrcDir.forEach { extraOpts(it) }
|
||||||
|
extraOpts(interopRuntimeCommonSrcDir)
|
||||||
|
extraOpts(
|
||||||
|
"-Xcommon-sources=${commonStdlibSrcDirs.joinToString(",")}",
|
||||||
|
"-Xcommon-sources=${testAnnotationCommonSrcDir.joinToString(",")}",
|
||||||
|
"-Xcommon-sources=${testCommonSrcDir.joinToString(",")}",
|
||||||
|
"-Xcommon-sources=$interopRuntimeCommonSrcDir",
|
||||||
|
)
|
||||||
|
stdLibSrcDirs.forEach { srcDir(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
stdlibBuildTask = project.findKonanBuildTask("stdlib", project.platformManager.hostPlatform.target)
|
||||||
|
stdlibBuildTask.configure {
|
||||||
|
dependsOn(":kotlin-native:distCompiler")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
targetList.forEach { target ->
|
||||||
|
tasks.register("${target}Stdlib", Copy::class.java) {
|
||||||
|
require(::stdlibBuildTask.isInitialized)
|
||||||
|
dependsOn(stdlibBuildTask)
|
||||||
|
dependsOn("${target}Runtime")
|
||||||
|
|
||||||
|
destinationDir = project.buildDir.resolve("${target}Stdlib")
|
||||||
|
from(project.buildDir.resolve("stdlib/$target/stdlib"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion
|
||||||
-1
@@ -32,7 +32,6 @@ abstract class KonanBuildingTask: KonanArtifactWithLibrariesTask(), KonanBuildin
|
|||||||
internal abstract val toolRunner: KonanToolRunner
|
internal abstract val toolRunner: KonanToolRunner
|
||||||
|
|
||||||
override fun init(config: KonanBuildingConfig<*>, destinationDir: File, artifactName: String, target: KonanTarget) {
|
override fun init(config: KonanBuildingConfig<*>, destinationDir: File, artifactName: String, target: KonanTarget) {
|
||||||
dependsOnDist()
|
|
||||||
super.init(config, destinationDir, artifactName, target)
|
super.init(config, destinationDir, artifactName, target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user