From 16acb72521f7f9c3c41f6e854c9ff4e48475f99f Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Tue, 2 May 2023 11:40:40 +0200 Subject: [PATCH] Native: don't pack endorsed libraries (namely kotlinx.cli) into dist The overall concept of "endorsed" libraries is currently unmaintained and non-reviewed. kotlinx-cli is in its alpha, and is available from Maven. See also KT-54098. --- kotlin-native/build.gradle | 71 +------------- .../endorsedLibraries/build.gradle.kts | 97 ------------------- .../kotlinx.cli/build.gradle.kts | 96 ------------------ settings.gradle | 1 - 4 files changed, 5 insertions(+), 260 deletions(-) delete mode 100644 kotlin-native/endorsedLibraries/build.gradle.kts diff --git a/kotlin-native/build.gradle b/kotlin-native/build.gradle index 8c021545e62..655e7fa2889 100644 --- a/kotlin-native/build.gradle +++ b/kotlin-native/build.gradle @@ -210,14 +210,9 @@ task distNativeSources(type: Zip) { } } -task distEndorsedSources { - dependsOn(':kotlin-native:endorsedLibraries:endorsedLibsSources') -} - task distSources { dependsOn(distCommonSources) dependsOn(distNativeSources) - dependsOn(distEndorsedSources) } task shadowJar(type: ShadowJar) { @@ -346,35 +341,19 @@ task distRuntime(type: Copy) { dependsOn "${hostName}CrossDistRuntime" } -task distEndorsedLibraries { - dependsOn "${hostName}CrossDistEndorsedLibraries" -} - task distStdlibCache { if (hostName in cacheableTargetNames) { dependsOn("${hostName}StdlibCache") } } -task distEndorsedCache { - if (hostName in cacheableTargetNames) { - dependsOn("${hostName}EndorsedCache") - } -} - def stdlib = 'klib/common/stdlib' def stdlibDefaultComponent = "$stdlib/default" -def endorsedLibs = 'klib/common/endorsedLibraries' -def endorsedLibsBase = 'klib/common' task crossDistRuntime { dependsOn.addAll(targetList.collect { "${it}CrossDistRuntime" }) } -task crossDistEndorsedLibraries { - dependsOn.addAll(targetList.collect { "${it}CrossDistEndorsedLibraries" }) -} - task crossDistPlatformLibs { dependsOn.addAll(targetList.collect { "${it}PlatformLibs" }) } @@ -387,19 +366,6 @@ task crossDistStdlibCache { dependsOn.addAll(targetList.findAll { it in cacheableTargetNames }.collect { "${it}StdlibCache" }) } -task crossDistEndorsedCache { - dependsOn.addAll(targetList.findAll { it in cacheableTargetNames }.collect { "${it}EndorsedCache" }) -} - -def endorsedLibsCopyTask = task("crossDistEndorsedLibrariesCopy", type: Copy) { - destinationDir project.file("$distDir/$endorsedLibsBase") - - from(project(':kotlin-native:endorsedLibraries').file("build")) { - include('**') - exclude('cache') - } -} - targetList.each { target -> task("${target}CrossDistStdlib", type: Copy) { dependsOn ":kotlin-native:runtime:${target}Stdlib" @@ -419,7 +385,7 @@ targetList.each { target -> include('**') } else { // We don't want to rewrite stdlib parts as they are the same and may be already used - // by the other build phases like caching or endorsed libraries. + // by the other build phases like caching. include('*/targets/**') include('*/manifest') } @@ -486,36 +452,14 @@ targetList.each { target -> include('**') } } - - task ("${target}EndorsedCache", type: Copy) { - dependsOn "${target}CrossDistStdlib" - dependsOn ":kotlin-native:endorsedLibraries:${target}Cache" - - destinationDir project.file("$distDir/klib/cache") - - from("${project(':kotlin-native:endorsedLibraries').buildDir}/cache/$target") { - include('**') - } - } } task("${target}CrossDist") { dependsOn "${target}CrossDistRuntime", "distCompiler" - dependsOn "${target}CrossDistEndorsedLibraries" if (target in cacheableTargetNames) { - dependsOn "${target}StdlibCache", "${target}EndorsedCache" + dependsOn "${target}StdlibCache" } } - - task("${target}CrossDistEndorsedLibraries") { - def endorsedLibsBuildTask = ":kotlin-native:endorsedLibraries:${target}EndorsedLibraries" - dependsOn endorsedLibsBuildTask - dependsOn endorsedLibsCopyTask - // There is only one copy task for endorsed libs, because they are already copied into a single dir, - // while having target-tasks will make Gradle issue warnings on incorrect inputs and outputs usage. - // So this copy task should run after the all build tasks. - endorsedLibsCopyTask.mustRunAfter(endorsedLibsBuildTask) - } } task distPlatformLibs { @@ -526,20 +470,16 @@ task distPlatformLibs { task dist { dependsOn "distCompiler", "distRuntime", - "distEndorsedLibraries", "distDef", - "distStdlibCache", - "distEndorsedCache" + "distStdlibCache" } task crossDist { dependsOn "distCompiler", "crossDistRuntime", - "crossDistEndorsedLibraries", "distDef", "crossDistStdlib", - "crossDistStdlibCache", - "crossDistEndorsedCache" + "crossDistStdlibCache" } task bundle { @@ -556,7 +496,7 @@ task bundleRegular(type: (isWindows()) ? Zip : Tar) { exclude 'klib/testLibrary' // Don't include platform libraries into the bundle (generate them at the user side instead). exclude 'klib/platform' - // Exclude platform libraries caches too. Keep caches for stdlib and endorsed libs. + // Exclude platform libraries caches too. Keep caches for stdlib. exclude 'klib/cache/*/org.jetbrains.kotlin.native.platform.*/**' into "${archiveBaseName.get()}-${archiveVersion.get()}" } @@ -598,7 +538,6 @@ configurePackingLicensesToBundle(bundlePrebuilt, /* containsPlatformLibraries = configure([bundleRegular, bundlePrebuilt]) { dependsOn("crossDist") dependsOn("crossDistStdlibCache") - dependsOn("crossDistEndorsedCache") dependsOn("distSources") dependsOn("distDef") from(project.projectDir) { diff --git a/kotlin-native/endorsedLibraries/build.gradle.kts b/kotlin-native/endorsedLibraries/build.gradle.kts deleted file mode 100644 index 05d285c2858..00000000000 --- a/kotlin-native/endorsedLibraries/build.gradle.kts +++ /dev/null @@ -1,97 +0,0 @@ -import org.jetbrains.kotlin.EndorsedLibraryInfo -import org.jetbrains.kotlin.konan.target.HostManager -import org.jetbrains.kotlin.konan.target.KonanTarget -import org.jetbrains.kotlin.kotlinNativeDist -import org.jetbrains.kotlin.mergeManifestsByTargets - -if (HostManager.host == KonanTarget.MACOS_ARM64) { - project.configureJvmToolchain(JdkMajorVersion.JDK_17_0) -} - -plugins { - base -} - -val endorsedLibraries = listOf(EndorsedLibraryInfo(project("kotlinx.cli"), "org.jetbrains.kotlinx.kotlinx-cli")) - -extra["endorsedLibraries"] = endorsedLibraries.associateBy { it.project } - -tasks.register("jvmJar") { - endorsedLibraries.forEach { library -> - dependsOn("${library.projectName}:jvmJar") - } -} - -val targetList: List by project -val cacheableTargetNames: List by project - -// Build all default libraries. -targetList.forEach { target -> - tasks.create("${target}EndorsedLibraries") { - endorsedLibraries.forEach { library -> - dependsOn(tasks.register("${target}${library.name}EndorsedLibraries", Copy::class.java) { - dependsOn("${library.projectName}:${target}${library.taskName}") - destinationDir = project.file("${project.buildDir}/${library.name}") - - from(library.project.file("build/${target}${library.name}")) { - include("**") - eachFile { - if (name == "manifest") { - val existingManifest = file("$destinationDir/$path") - if (existingManifest.exists()) { - project.mergeManifestsByTargets(file, existingManifest) - exclude() - } - } - } - } - }) - } - } - - if (target in cacheableTargetNames) { - val cacheTask = tasks.register("${target}Cache", Copy::class.java) { - destinationDir = project.file("${project.buildDir}/cache/$target") - - endorsedLibraries.forEach { library -> - from(library.project.file("build/cache/$target")) { - include("**") - } - } - } - - endorsedLibraries.forEach { library -> - cacheTask.configure { - dependsOn("${library.projectName}:${target}${library.taskName}Cache") - } - } - } -} - -endorsedLibraries.forEach { library -> - tasks.register("${library.taskName}CommonSources", Zip::class.java) { - destinationDirectory.set(file("${project.kotlinNativeDist}/sources")) - archiveFileName.set("${library.name}-common-sources.zip") - - includeEmptyDirs = false - include("**/*.kt") - - from(library.project.file("src/main/kotlin")) - } - tasks.register("${library.taskName}NativeSources", Zip::class.java) { - destinationDirectory.set(file("${project.kotlinNativeDist}/sources")) - archiveFileName.set("${library.name}-native-sources.zip") - - includeEmptyDirs = false - include("**/*.kt") - - from(library.project.file("src/main/kotlin-native")) - } -} - -tasks.register("endorsedLibsSources") { - endorsedLibraries.forEach { library -> - dependsOn("${library.taskName}CommonSources") - dependsOn("${library.taskName}NativeSources") - } -} diff --git a/kotlin-native/endorsedLibraries/kotlinx.cli/build.gradle.kts b/kotlin-native/endorsedLibraries/kotlinx.cli/build.gradle.kts index d1cf6861ae0..7460341d7c6 100644 --- a/kotlin-native/endorsedLibraries/kotlinx.cli/build.gradle.kts +++ b/kotlin-native/endorsedLibraries/kotlinx.cli/build.gradle.kts @@ -1,18 +1,7 @@ import org.jetbrains.kotlin.* -import org.jetbrains.kotlin.gradle.plugin.konan.tasks.KonanCacheTask -import org.jetbrains.kotlin.konan.properties.loadProperties -import org.jetbrains.kotlin.konan.properties.saveProperties -import org.jetbrains.kotlin.library.KLIB_PROPERTY_NATIVE_TARGETS -import org.jetbrains.kotlin.konan.file.File as KFile - -val distDir: File by project -val konanHome: String by extra(distDir.absolutePath) -extra["org.jetbrains.kotlin.native.home"] = konanHome plugins { kotlin("multiplatform") - id("kotlin.native.build-tools-conventions") - id("konan") } kotlin { @@ -54,88 +43,3 @@ kotlin { } } } - -val commonSrc = project.file("src/main/kotlin") -val nativeSrc = project.file("src/main/kotlin-native") - -val targetList: List by project -val endorsedLibraries: Map by project(":kotlin-native:endorsedLibraries").ext - -val library = endorsedLibraries[project] ?: throw IllegalStateException("Library for $project is not set") - -konanArtifacts { - library(library.name) { - baseDir(project.buildDir.resolve(library.name)) - - noPack(true) - noDefaultLibs(true) - noEndorsedLibs(true) - enableMultiplatform(true) - - // See :endorsedLibraries.ext for full endorsedLibraries list. - val moduleName = endorsedLibraries[project]?.name.toString() - - extraOpts(project.globalBuildArgs) - extraOpts( - "-Werror", - "-module-name", moduleName, - "-opt-in=kotlin.RequiresOptIn", - "-opt-in=kotlin.ExperimentalMultiplatform", - "-opt-in=kotlinx.cli.ExperimentalCli" - ) - - commonSrcDir(commonSrc) - srcDir(nativeSrc) - - dependsOn(":kotlin-native:distCompiler") - dependsOn(":kotlin-native:distRuntime") - } -} - -val hostName: String by project -val cacheableTargetNames: List by project - -targetList.forEach { targetName -> - val copyTask = tasks.register("${targetName}${library.taskName}", Copy::class.java) { - dependsOn(project.findKonanBuildTask(library.name, project.platformManager.hostPlatform.target)) - - destinationDir = buildDir.resolve("$targetName${library.name}") - - // We build a single klib file for host platform and then copy it to other platforms - // creating target dirs and adding targets to manifest file - val libFile = buildDir.resolve("${library.name}/${hostName}/${library.name}") - from(libFile) { - exclude("default/targets/$hostName") - } - from(libFile.resolve("default/targets/$hostName")) { - into("default/targets/$targetName") - } - - if (targetName != hostName) { - doLast { - // Change target in manifest file - with(KFile(destinationDir.resolve("default/manifest").absolutePath)) { - val props = loadProperties() - props[KLIB_PROPERTY_NATIVE_TARGETS] = targetName - saveProperties(props) - } - } - } - } - - if (targetName in cacheableTargetNames) { - tasks.register("${targetName}${library.taskName}Cache", KonanCacheTask::class.java) { - target = targetName - originalKlib = project.buildDir.resolve("$targetName${library.name}") - klibUniqName = library.name - cacheRoot = project.buildDir.resolve("cache/$targetName").absolutePath - - cachedLibraries = mapOf(distDir.resolve("klib/common/stdlib") to - distDir.resolve("klib/cache/${target}-g$cacheKind/stdlib-cache")) - - dependsOn(copyTask) - dependsOn(":kotlin-native:${targetName}CrossDistStdlib") - dependsOn(":kotlin-native:${targetName}StdlibCache") - } - } -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 7a372b85544..6c3a22b363a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -811,7 +811,6 @@ if (buildProperties.isKotlinNativeEnabled) { } include ':kotlin-native:dependencies' include ':kotlin-native:endorsedLibraries:kotlinx.cli' - include ':kotlin-native:endorsedLibraries' include ':kotlin-native:Interop:StubGenerator' include ':kotlin-native:backend.native' include ':kotlin-native:Interop:Runtime'