diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 16fbad4e0c3..0092b2effc5 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -106,6 +106,10 @@ sourceSets["main"].withConvention(org.jetbrains.kotlin.gradle.plugin.KotlinSourc kotlin.srcDir("../kotlin-native/build-tools/src/main/kotlin") kotlin.srcDir("../kotlin-native/build-tools/src/tmp/kotlin") kotlin.srcDir("../kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin") + kotlin.srcDir("../compiler/util-klib/src") + kotlin.srcDir(project.kotlinNativeVersionSrc()) + kotlin.srcDir("../native/utils/src") + kotlin.exclude("**/benchmark/SwiftBenchmarkingPlugin.kt") } tasks.validatePlugins.configure { @@ -148,8 +152,6 @@ dependencies { implementation("io.ktor:ktor-client-core:$ktorVersion") implementation("io.ktor:ktor-client-cio:$ktorVersion") - api("org.jetbrains.kotlin:kotlin-native-utils:$kotlinVersion") - implementation("org.jetbrains.kotlinx:kotlinx-metadata-klib:$metadataVersion") } @@ -167,7 +169,10 @@ java { tasks.withType().configureEach { kotlinOptions.freeCompilerArgs += listOf( - "-Xopt-in=kotlin.RequiresOptIn", "-Xskip-runtime-version-check", "-Xsuppress-version-warnings" + "-Xopt-in=kotlin.RequiresOptIn", + "-Xskip-runtime-version-check", + "-Xsuppress-version-warnings", + "-Xopt-in=kotlin.ExperimentalStdlibApi" ) } diff --git a/kotlin-native/Interop/StubGenerator/build.gradle b/kotlin-native/Interop/StubGenerator/build.gradle index d78a03699b2..bfd6e538572 100644 --- a/kotlin-native/Interop/StubGenerator/build.gradle +++ b/kotlin-native/Interop/StubGenerator/build.gradle @@ -31,8 +31,11 @@ dependencies { api project(path: ":kotlin-native:endorsedLibraries:kotlinx.cli", configuration: "jvmRuntimeElements") api project(":kotlin-stdlib") - api project(":kotlin-compiler") + api project(kotlinCompilerModule) api project(":kotlinx-metadata-klib") + api project(":native:kotlin-native-utils") + implementation(project(":compiler:util")) + implementation(project(":compiler:ir.serialization.common")) testImplementation "junit:junit:4.12" testImplementation project(":kotlin-test:kotlin-test-junit") @@ -44,3 +47,13 @@ compileKotlin { allWarningsAsErrors=true } } + +sourceSets{ + main { + kotlin { + srcDir("../../shared/src/library/kotlin") + srcDir("../../shared/src/main/kotlin") + srcDir("../../../buildSrc/src/generated/kotlin") + } + } +} \ No newline at end of file diff --git a/kotlin-native/backend.native/build.gradle b/kotlin-native/backend.native/build.gradle index 74a28f09efb..8572833006e 100644 --- a/kotlin-native/backend.native/build.gradle +++ b/kotlin-native/backend.native/build.gradle @@ -21,13 +21,6 @@ apply plugin: 'kotlin' apply plugin: org.jetbrains.kotlin.NativeInteropPlugin apply plugin: "maven-publish" -// (gets applied to this project and all its subprojects) -allprojects { - repositories { - maven { url project.bootstrapKotlinRepo } - } -} - sourceSets { compiler { proto.srcDir 'compiler/ir/backend.native/src/' @@ -37,6 +30,9 @@ sourceSets { } kotlin { srcDir 'compiler/ir/backend.native/src/' + srcDir '../shared/src/main/kotlin' + srcDir '../shared/src/library/kotlin' + srcDir '../../buildSrc/src/generated/kotlin' } resources.srcDir 'compiler/ir/backend.native/resources/' } @@ -114,7 +110,7 @@ kotlinNativeInterop { } files { - if (!project.parent.convention.plugins.platformInfo.isWindows()) { + if (!project.project(":kotlin-native").convention.plugins.platformInfo.isWindows()) { compilerOpts '-fPIC' linkerOpts '-fPIC' } @@ -147,13 +143,14 @@ configurations { cli_bc { extendsFrom cli_bcRuntime } + cli_bcCompile.extendsFrom compilerCompile } dependencies { trove4j_jar "org.jetbrains.intellij.deps:trove4j:1.0.20181211@jar" - kotlin_compiler_jar project(":kotlin-compiler") - kotlin_stdlib_jar project(":kotlin-stdlib") - kotlin_reflect_jar project(":kotlin-reflect") + kotlin_compiler_jar project(kotlinCompilerModule) + kotlin_stdlib_jar kotlinStdLibModule + kotlin_reflect_jar kotlinReflectModule kotlin_script_runtime_jar project(":kotlin-script-runtime") [kotlinCommonStdlibModule, kotlinTestCommonModule, kotlinTestAnnotationsCommonModule].each { @@ -164,15 +161,44 @@ dependencies { compilerCompile "com.google.protobuf:protobuf-java:${protobufVersion}" - compilerCompile project(":kotlin-compiler") + compilerCompile project(kotlinCompilerModule) + compilerCompile project(":native:kotlin-native-utils") + compilerCompile project(":core:descriptors") + compilerCompile project(":compiler:ir.tree") + compilerCompile project(":compiler:ir.tree.impl") + compilerCompile project(":compiler:ir.backend.common") + compilerCompile project(":compiler:util") + compilerCompile project(":native:frontend.native") + compilerCompile project(":compiler:cli-common") + compilerCompile project(":compiler:cli") + compilerCompile project(":kotlin-util-klib") + compilerCompile project(":kotlin-util-klib-metadata") + compilerCompile project(":compiler:ir.serialization.common") + use(LocalDependenciesKt) { + compilerCompile(intellijCoreDep()){ + artifact { + name = "intellij-core" + type = "jar" + } + } + compilerCompile(intellijDep()){ + artifact { + name = "util" + type = "jar" + //extention = "jar" + } + } + compileOnly(jpsStandalone()) + } + compilerCompile kotlinNativeInterop['llvm'].configuration compilerCompile kotlinNativeInterop['hash'].configuration compilerCompile kotlinNativeInterop['files'].configuration - cli_bcCompile project(":kotlin-compiler") + cli_bcCompile sourceSets.compiler.output - bc_frontendCompile kotlinCompilerModule + bc_frontendCompile project(kotlinCompilerModule) cli_bc sourceSets.cli_bc.output } @@ -184,12 +210,7 @@ classes.dependsOn 'compilerClasses', 'cli_bcClasses', 'bc_frontendClasses' // These are just a couple of aliases task stdlib(dependsOn: "${hostName}Stdlib") -def commonSrc = file('build/stdlib') - -task unzipStdlibSources(type: CopyCommonSources) { - outputDir commonSrc - sourcePaths configurations.kotlinCommonSources -} +def commonSrc = project(":kotlin-stdlib-common").files("src/kotlin", "src/generated", "../unsigned/src", "../src").files final List stdLibSrc = [ project(':kotlin-native:Interop:Runtime').file('src/main/kotlin'), @@ -220,6 +241,8 @@ targetList.each { target -> include "*.jar" } 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', '-XXLanguage:+AllowContractsForCustomFunctions', @@ -227,14 +250,19 @@ targetList.each { target -> '-Xopt-in=kotlin.contracts.ExperimentalContracts', '-Xopt-in=kotlin.ExperimentalMultiplatform', '-Xallow-result-return-type', - commonSrc.absolutePath, - "-Xcommon-sources=${commonSrc.absolutePath}", + *commonSrc.toList(), + *testAnnotationCommon.toList(), + *testCommon.toList(), + "-Xcommon-sources=${commonSrc.join(',')}", + "-Xcommon-sources=${testAnnotationCommon.join(',')}", + "-Xcommon-sources=${testCommon.join(',')}", *stdLibSrc] stdLibSrc.forEach { inputs.dir(it) } - inputs.dir(commonSrc) + commonSrc.forEach{ + inputs.dir(it) + } outputs.dir(project(':kotlin-native:runtime').file("build/${target}Stdlib")) - dependsOn 'unzipStdlibSources' dependsOn ":kotlin-native:runtime:${target}Runtime" dependsOn ":kotlin-native:distCompiler" } @@ -253,7 +281,7 @@ jar { sourceSets.filesInteropStubs.output, sourceSets.llvmInteropStubs.output - dependsOn ':runtime:hostRuntime', 'external_jars' + dependsOn ':kotlin-native:runtime:hostRuntime', 'external_jars' } def externalJars = ['compiler', 'stdlib', 'reflect', 'script_runtime'] diff --git a/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy b/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy index 698cfe94143..e0d638e3d4d 100644 --- a/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy +++ b/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy @@ -207,7 +207,7 @@ class NamedNativeInteropConfig implements Named { ).asPath // Set the konan.home property because we run the cinterop tool not from a distribution jar // so it will not be able to determine this path by itself. - systemProperties "konan.home": project.rootProject.projectDir + systemProperties "konan.home": project.project(":kotlin-native").projectDir environment "LIBCLANG_DISABLE_CRASH_RECOVERY": "1" outputs.dir generatedSrcDir diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt index 5f792005c42..0dc4e0a6d4f 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/KotlinNativeTest.kt @@ -466,7 +466,7 @@ open class KonanDynamicTest : KonanStandaloneTest() { val execResult = plugin.execKonanClang(project.testTarget, Action { workingDir = File(outputDirectory) - executable = clangTool + this@Action.executable = clangTool args = listOf(processCSource(), "-c", "-o", "${this@KonanDynamicTest.executable}.o", diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/PlatformInfo.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/PlatformInfo.kt index cbd63cc1a8a..de753ffbc39 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/PlatformInfo.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/PlatformInfo.kt @@ -32,7 +32,7 @@ object PlatformInfo { @JvmStatic fun getTarget(project: Project): KonanTarget { - val platformManager = project.rootProject.platformManager + val platformManager = project.project(":kotlin-native").platformManager val targetName = project.project.testTarget.name return platformManager.targetManager(targetName).target } diff --git a/kotlin-native/build.gradle b/kotlin-native/build.gradle index ef250f3fe1e..1cb8a7fa183 100644 --- a/kotlin-native/build.gradle +++ b/kotlin-native/build.gradle @@ -65,7 +65,7 @@ if (isMac()) { } ext { - distDir = file('dist') + distDir = rootProject.file('dist') dependenciesDir = DependencyProcessor.defaultDependenciesRoot experimentalEnabled = project.hasProperty("org.jetbrains.kotlin.native.experimentalTargets") platformManager = new PlatformManager(DistributionKt.buildDistribution(projectDir.absolutePath), @@ -82,7 +82,7 @@ ext { KonanTarget.LINUX_MIPSEL32.INSTANCE ] - kotlinCompilerModule= project(":kotlin-compiler") + kotlinCompilerModule= [path: ":kotlin-compiler", configuration: "runtimeElements"] kotlinStdLibModule= project(":kotlin-stdlib") kotlinCommonStdlibModule= project(":kotlin-stdlib-common") kotlinTestCommonModule= project(":kotlin-test:kotlin-test-common") @@ -220,7 +220,7 @@ dependencies { distPack project(':kotlin-native:Interop:Runtime') distPack project(':kotlin-native:Interop:Indexer') distPack project(':kotlin-native:Interop:StubGenerator') - //distPack project(':kotlin-native:backend.native') + distPack project(':kotlin-native:backend.native') distPack project(':kotlin-native:utilities:cli-runner') distPack project(':kotlin-native:utilities:basic-utils') distPack project(':kotlin-native:klib') @@ -341,7 +341,7 @@ task detectJarCollision(type: CollisionDetector) { } task shadowJar(type: ShadowJar) { - dependsOn ':detectJarCollision' + //dependsOn ':kotlin-native:detectJarCollision' mergeServiceFiles() destinationDirectory.set(file("$distDir/konan/lib")) archiveBaseName.set("kotlin-native") @@ -356,7 +356,7 @@ task shadowJar(type: ShadowJar) { } task distCompiler(type: Copy) { - dependsOn ':shadowJar' + dependsOn ':kotlin-native:shadowJar' destinationDir distDir diff --git a/kotlin-native/endorsedLibraries/build.gradle b/kotlin-native/endorsedLibraries/build.gradle index a42ca5e5cf6..d335ede8626 100644 --- a/kotlin-native/endorsedLibraries/build.gradle +++ b/kotlin-native/endorsedLibraries/build.gradle @@ -67,8 +67,8 @@ targetList.each { target -> compilerDistributionPath.set(distDir) dependsOn "${target}EndorsedLibraries" - dependsOn ":${target}CrossDistRuntime" - dependsOn ":${target}StdlibCache" + dependsOn ":kotlin-native:${target}CrossDistRuntime" + dependsOn ":kotlin-native:${target}StdlibCache" cacheTask.dependsOn it } diff --git a/kotlin-native/gradle/kotlinGradlePlugin.gradle b/kotlin-native/gradle/kotlinGradlePlugin.gradle index 6db6f292710..faa11cb6681 100644 --- a/kotlin-native/gradle/kotlinGradlePlugin.gradle +++ b/kotlin-native/gradle/kotlinGradlePlugin.gradle @@ -16,5 +16,5 @@ configurations { } project.dependencies { - kotlinCompilerClasspath(project(":kotlin-compiler-embeddable")) + kotlinCompilerClasspath(project(path: ":kotlin-compiler-embeddable", configuration: "runtimeJar")) } diff --git a/kotlin-native/platformLibs/build.gradle b/kotlin-native/platformLibs/build.gradle index 423ea10711a..f62bdd47eef 100644 --- a/kotlin-native/platformLibs/build.gradle +++ b/kotlin-native/platformLibs/build.gradle @@ -59,7 +59,7 @@ rootProject.project("kotlin-native").ext.platformManager.enabled.each { target - it.originalKlib = file("$konanHome/klib/common/stdlib") it.cacheRoot = file("$konanHome/klib/cache") - it.dependsOn ":${targetName}CrossDistRuntime" + it.dependsOn ":kotlin-native:${targetName}CrossDistRuntime" } } @@ -86,7 +86,7 @@ rootProject.project("kotlin-native").ext.platformManager.enabled.each { target - def libTask = konanArtifacts."$libName"."$targetName" libTask.configure { it.dependsOn df.config.depends.collect { defFileToLibName(targetName, it) } - it.dependsOn ":${targetName}CrossDist" + it.dependsOn ":kotlin-native:${targetName}CrossDist" it.enableParallel = true } @@ -104,7 +104,7 @@ rootProject.project("kotlin-native").ext.platformManager.enabled.each { target - it.originalKlib = tasks[libName].installDir.get() it.cacheRoot = file("$konanHome/klib/cache") - it.dependsOn ":${targetName}StdlibCache" + it.dependsOn ":kotlin-native:${targetName}StdlibCache" it.dependsOn tasks[libName] it.dependsOn df.config.depends.collect { def depName = defFileToLibName(targetName, it) diff --git a/kotlin-native/runtime/build.gradle.kts b/kotlin-native/runtime/build.gradle.kts index bfdedff0eb5..2f3f3106ef4 100644 --- a/kotlin-native/runtime/build.gradle.kts +++ b/kotlin-native/runtime/build.gradle.kts @@ -28,7 +28,7 @@ val targetList: List by project bitcode { create("runtime", file("src/main")) { dependsOn( - ":common:${target}Hash", + ":kotlin-native:common:${target}Hash", "${target}StdAlloc", "${target}OptAlloc", "${target}Mimalloc", diff --git a/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/KonanToolRunner.kt b/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/KonanToolRunner.kt index 118f9736933..65e3e24a931 100644 --- a/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/KonanToolRunner.kt +++ b/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/KonanToolRunner.kt @@ -19,6 +19,8 @@ package org.jetbrains.kotlin.gradle.plugin.konan import org.gradle.api.Named import org.gradle.api.Project import org.gradle.api.file.FileCollection +import org.gradle.api.Action +import org.gradle.process.JavaExecSpec import org.jetbrains.kotlin.gradle.plugin.konan.KonanPlugin.ProjectProperty.KONAN_HOME import org.jetbrains.kotlin.konan.target.Family import org.jetbrains.kotlin.konan.target.HostManager @@ -91,21 +93,23 @@ internal abstract class KonanCliRunner( "Please change it to the compiler root directory and rerun the build.") } - project.javaexec { - main = this@KonanCliRunner.mainClass - classpath = classpath - jvmArgs(jvmArgs) - systemProperties( - System.getProperties().asSequence() - .map { (k, v) -> k.toString() to v.toString() } - .filter { (k, _) -> k !in blacklistProperties } - .escapeQuotesForWindows() - .toMap() - ) - args(listOf(toolName) + transformArgs(args)) - blacklistEnvironment.forEach { environment.remove(it) } - environment(environment) - } + project.javaexec(object :Action { + override fun execute(exec: JavaExecSpec) { + exec.main = mainClass + exec.classpath = classpath + exec.jvmArgs(jvmArgs) + exec.systemProperties( + System.getProperties().asSequence() + .map { (k, v) -> k.toString() to v.toString() } + .filter { (k, _) -> k !in this@KonanCliRunner.blacklistProperties } + .escapeQuotesForWindows() + .toMap() + ) + exec.args(listOf(toolName) + transformArgs(args)) + this@KonanCliRunner.blacklistEnvironment.forEach { environment.remove(it) } + exec.environment(environment) + } + }) } } diff --git a/kotlin-native/utilities/basic-utils/build.gradle.kts b/kotlin-native/utilities/basic-utils/build.gradle.kts index 4f8eb3c33b1..f6842c9ae28 100644 --- a/kotlin-native/utilities/basic-utils/build.gradle.kts +++ b/kotlin-native/utilities/basic-utils/build.gradle.kts @@ -21,5 +21,6 @@ tasks.named("compileKotlin") { dependencies { api(project(":kotlin-stdlib")) - implementation(project(":kotlin-compiler")) + implementation(project(project.project(":kotlin-native").extra["kotlinCompilerModule"] as Map)) + implementation(project(":compiler:util")) } diff --git a/native/utils/src/org/jetbrains/kotlin/konan/target/HostManager.kt b/native/utils/src/org/jetbrains/kotlin/konan/target/HostManager.kt index 9dce6872ac3..46b7a99ed99 100644 --- a/native/utils/src/org/jetbrains/kotlin/konan/target/HostManager.kt +++ b/native/utils/src/org/jetbrains/kotlin/konan/target/HostManager.kt @@ -16,7 +16,7 @@ open class HostManager( constructor( distribution: Distribution, - experimental: Boolean = false, + experimental: Boolean = false ) : this(distribution.subTargetProvider, experimental || distribution.experimentalEnabled) fun targetManager(userRequest: String? = null): TargetManager = TargetManagerImpl(userRequest, this)