| /* | |
| * Copyright 2010-2017 JetBrains s.r.o. | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| import org.jetbrains.kotlin.DeletingSync | |
| import org.jetbrains.kotlin.NativeFullCrossDistKt | |
| import org.jetbrains.kotlin.konan.target.* | |
| import org.jetbrains.kotlin.CopySamples | |
| import org.jetbrains.kotlin.PlatformInfo | |
| import org.jetbrains.kotlin.cpp.CompilationDatabasePlugin | |
| import org.jetbrains.kotlin.cpp.CppUsage | |
| import org.jetbrains.kotlin.cpp.GitClangFormatPlugin | |
| import org.jetbrains.kotlin.CompareDistributionSignatures | |
| import org.jetbrains.kotlin.nativeDistribution.InvalidateStaleCaches | |
| import org.jetbrains.kotlin.nativeDistribution.LLVMDistributionKind | |
| import org.jetbrains.kotlin.nativeDistribution.LLVMDistributionSourceKt | |
| import org.jetbrains.kotlin.nativeDistribution.NativeDistributionKt | |
| import org.jetbrains.kotlin.nativeDistribution.NativeDistribution | |
| import org.jetbrains.kotlin.nativeDistribution.NativeProtoDistributionKt | |
| import org.jetbrains.kotlin.nativeDistribution.PrepareDistributionFingerprint | |
| import org.jetbrains.kotlin.nativeDistribution.PrepareKonanProperties | |
| import org.jetbrains.kotlin.xcode.XcodeOverridePlugin | |
| import org.jetbrains.kotlin.UtilsKt | |
| import plugins.KotlinBuildPublishingPluginKt | |
| import java.security.MessageDigest | |
| plugins { | |
| id("common-configuration") | |
| id("com.autonomousapps.dependency-analysis") | |
| } | |
| defaultTasks 'clean', 'dist' | |
| apply plugin: XcodeOverridePlugin | |
| if (PlatformInfo.isMac()) { | |
| PlatformInfo.checkXcodeVersion(project) | |
| } | |
| apply plugin: "kotlin.native.build-tools-conventions" | |
| apply plugin: "platform-manager" | |
| apply plugin: "java" | |
| def kotlinBuildProperties = BuildPropertiesKt.getKotlinBuildProperties(project) | |
| def platformManager = project.extensions.platformManager | |
| def hostName = PlatformInfo.hostName | |
| def targetList = EnabledTargetsKt.enabledTargets(platformManager).collect { it.visibleName } as List | |
| def cacheableTargetNames = platformManager.hostPlatform.cacheableTargets | |
| def nativeDistribution = NativeDistributionKt.getNativeDistribution(project) | |
| configurations { | |
| register("commonSources") | |
| runtimeBitcode { | |
| canBeConsumed = false | |
| canBeResolved = true | |
| attributes { | |
| attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, CppUsage.LLVM_BITCODE)) | |
| } | |
| } | |
| objcExportApi { | |
| canBeConsumed = false | |
| canBeResolved = true | |
| attributes { | |
| attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, CppUsage.API)) | |
| } | |
| } | |
| embeddableJar { | |
| canBeConsumed = false | |
| canBeResolved = true | |
| } | |
| nativeLibs { | |
| canBeConsumed = false | |
| canBeResolved = true | |
| attributes { | |
| attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, CppUsage.LIBRARY_RUNTIME)) | |
| } | |
| } | |
| } | |
| apply plugin: CompilationDatabasePlugin | |
| dependencies { | |
| commonSources project(path: ':kotlin-stdlib', configuration: 'metadataSourcesElements') | |
| commonSources project(path: ':kotlin-test', configuration: 'metadataSourcesElements') | |
| compilationDatabase project(":kotlin-native:Interop:Runtime") | |
| compilationDatabase project(":kotlin-native:libclangext") | |
| compilationDatabase project(":kotlin-native:libllvmext") | |
| compilationDatabase project(":kotlin-native:llvmDebugInfoC") | |
| compilationDatabase project(":kotlin-native:runtime") | |
| compilationDatabase project(":kotlin-native:tools:minidump-analyzer") | |
| runtimeBitcode project(":kotlin-native:runtime") | |
| objcExportApi project(":kotlin-native:runtime") | |
| embeddableJar project(path: ':kotlin-native:prepare:kotlin-native-compiler-embeddable', configuration: 'runtimeElements') | |
| nativeLibs project(':kotlin-native:common:env') | |
| nativeLibs project(':kotlin-native:common:files') | |
| nativeLibs project(':kotlin-native:llvmInterop') | |
| nativeLibs project(':kotlin-native:libclangInterop') | |
| nativeLibs project(':kotlin-native:Interop:Runtime') | |
| // declared to be included in verification-metadata.xml | |
| implicitDependencies("org.jetbrains.kotlin:kotlin-native-prebuilt:$bootstrapKotlinVersion:macos-aarch64@tar.gz") | |
| implicitDependencies("org.jetbrains.kotlin:kotlin-native-prebuilt:$bootstrapKotlinVersion:linux-x86_64@tar.gz") | |
| implicitDependencies("org.jetbrains.kotlin:kotlin-native-prebuilt:$bootstrapKotlinVersion:windows-x86_64@zip") | |
| } | |
| apply plugin: GitClangFormatPlugin | |
| apply plugin: 'maven-publish' | |
| apply plugin: BasePlugin | |
| tasks.register("dist_compiler") { | |
| dependsOn("distCompiler") | |
| } | |
| tasks.register("dist_runtime") { | |
| dependsOn("distRuntime") | |
| } | |
| tasks.register("cross_dist") { | |
| dependsOn("crossDist") | |
| } | |
| tasks.register("list_dist") { | |
| dependsOn("listDist") | |
| } | |
| tasks.named("build") { | |
| dependsOn 'dist', 'distPlatformLibs' | |
| } | |
| tasks.register("distNativeSources", Zip) { | |
| dependsOn(configurations.commonSources) | |
| duplicatesStrategy = DuplicatesStrategy.FAIL | |
| destinationDirectory = nativeDistribution.map { it.sources } | |
| archiveFileName = nativeDistribution.map { it.stdlibSources.asFile.name } | |
| includeEmptyDirs = false | |
| include('**/*.kt') | |
| from { | |
| configurations.commonSources | |
| .collect { zipTree(it) } | |
| .inject { t1, t2 -> t1 + t2 } | |
| } | |
| into('nativeWasmMain') { | |
| from(project.project(":kotlin-stdlib").isolated.projectDirectory.dir('native-wasm/src/')) | |
| } | |
| into('nativeWasmWasiMain') { | |
| from(project.project(":kotlin-stdlib").isolated.projectDirectory.dir('native-wasm/wasi/')) | |
| } | |
| into('nativeMain') { | |
| from(project.project(':kotlin-native:runtime').isolated.projectDirectory.dir('src/main/kotlin')) | |
| from(project.project(':kotlin-native:Interop:Runtime').isolated.projectDirectory.dir('src/main/kotlin')) | |
| from(project.project(':kotlin-native:Interop:Runtime').isolated.projectDirectory.dir('src/native/kotlin')) | |
| } | |
| } | |
| tasks.register("distSources") { | |
| dependsOn(distNativeSources) | |
| } | |
| tasks.register("distCompiler") { | |
| // Workaround: make distCompiler no-op if we are using custom dist: | |
| // the dist is already in place and has the compiler, so we don't have to | |
| // build and copy the compiler to dist. | |
| // Moreover, if we do copy it, it might overwrite the compiler files already loaded | |
| // by this Gradle process (including the jar loaded to the custom classloader), | |
| // causing hard-to-debug errors. | |
| if (!UtilsKt.isDefaultNativeHome(project)) { | |
| enabled = false | |
| } else { | |
| dependsOn 'distNativeLibs' | |
| dependsOn 'distCompilerJars' | |
| dependsOn 'distTools' | |
| dependsOn 'distBin' | |
| dependsOn 'distSwiftExport' | |
| dependsOn 'distKonanPlatforms' | |
| dependsOn 'distKonanProperties' | |
| dependsOn 'distCompilerFingerprint' | |
| } | |
| } | |
| tasks.register("distDef", Sync) { | |
| into(nativeDistribution.map { it.platformLibsDefinitions }) | |
| dependsOn ":kotlin-native:platformLibs:updateDefFileDependencies" | |
| platformManager.targetValues.each { target -> | |
| from(it.project.project(":kotlin-native:platformLibs").isolated.projectDirectory.dir("src/platform/${target.family.name().toLowerCase()}")) { | |
| into target.visibleName | |
| include '**/*.def' | |
| } | |
| } | |
| } | |
| tasks.register("listDist", Exec) { | |
| commandLine 'find', nativeDistribution.get().root | |
| } | |
| tasks.register("distRuntime") { | |
| dependsOn "${hostName}CrossDistRuntime" | |
| } | |
| tasks.register("distStdlibCache") { | |
| if (hostName in cacheableTargetNames) { | |
| dependsOn("${hostName}StdlibCache") | |
| dependsOn("${hostName}StdlibCacheOpt") | |
| } | |
| // Make sure any tasks depending on this one see cleaned-up distribution. | |
| mustRunAfter("distInvalidateStaleCaches") | |
| } | |
| tasks.register("distStdlib", Sync) { | |
| FileCollection nativeStdlibConf = configurations.detachedConfiguration(dependencies.project(path: ":kotlin-native:runtime", configuration: "nativeStdlib")) | |
| from(nativeStdlibConf) | |
| into(nativeDistribution.map { it.stdlib }) | |
| } | |
| tasks.register("distNativeLibs", DeletingSync) { | |
| from(configurations.nativeLibs) | |
| into(nativeDistribution.map { it.nativeLibs }) | |
| } | |
| tasks.register("distCompilerJars", Sync) { | |
| from(configurations.embeddableJar) { | |
| rename { | |
| "kotlin-native-compiler-embeddable.jar" | |
| } | |
| filePermissions { | |
| unix("0644") | |
| } | |
| } | |
| into(nativeDistribution.map { it.compilerJars }) | |
| } | |
| tasks.register("distCompilerFingerprint", PrepareDistributionFingerprint) { | |
| input.from(tasks.named("distNativeLibs")) | |
| input.from(tasks.named("distCompilerJars")) | |
| input.from(tasks.named("distKonanProperties")) | |
| output = nativeDistribution.map { it.compilerFingerprint } | |
| finalizedBy("distInvalidateStaleCaches") // if the fingerprint has updated, some caches may need to be invalidated | |
| } | |
| tasks.register("distTools", Sync) { | |
| from(it.project.project(':kotlin-native:llvmDebugInfoC').isolated.projectDirectory.file('src/scripts/konan_lldb.py')) | |
| from(it.project.project(':kotlin-native:utilities').isolated.projectDirectory.file('env_blacklist')) | |
| into(nativeDistribution.map { it.tools }) | |
| } | |
| tasks.register("distBin", Sync) { | |
| from(file('cmd')) { | |
| filePermissions { | |
| unix("0755") | |
| } | |
| if (!PlatformInfo.isWindows()) { | |
| exclude('**/*.bat') | |
| } | |
| } | |
| into(nativeDistribution.map { it.bin }) | |
| } | |
| tasks.register("distSwiftExport", Sync) { | |
| from(configurations.objcExportApi) { | |
| into('kotlin_runtime') | |
| filePermissions { | |
| unix("0644") | |
| } | |
| } | |
| into(nativeDistribution.map { it.swiftExport }) | |
| } | |
| tasks.register("distKonanPlatforms", Sync) { | |
| from(NativeProtoDistributionKt.getNativeProtoDistribution(project).konanPlatforms) | |
| into(nativeDistribution.map { it.konanPlatforms }) | |
| } | |
| tasks.register("distKonanProperties", PrepareKonanProperties) { | |
| input = NativeProtoDistributionKt.getNativeProtoDistribution(project).konanProperties | |
| output = nativeDistribution.map { it.konanProperties } | |
| compilerVersion = kotlinBuildProperties.kotlinVersion.get() | |
| llvmVariants.put(HostManager.host, LLVMDistributionKind.ESSENTIALS) | |
| llvmProperties.set(LLVMDistributionSourceKt.getAsProperties(LLVMDistributionSourceKt.getLlvmDistributionSource(project))) | |
| } | |
| tasks.register("crossDistRuntime") { | |
| dependsOn.addAll(targetList.collect { "${it}CrossDistRuntime" }) | |
| } | |
| tasks.register("crossDistPlatformLibs") { | |
| dependsOn.addAll(targetList.collect { "${it}PlatformLibs" }) | |
| } | |
| tasks.register("crossDistStdlibCache") { | |
| dependsOn.addAll(targetList.findAll { it in cacheableTargetNames }.collect { "${it}StdlibCache" }) | |
| dependsOn.addAll(targetList.findAll { it in cacheableTargetNames }.collect { "${it}StdlibCacheOpt" }) | |
| // Make sure any tasks depending on this one see cleaned-up distribution. | |
| mustRunAfter("distInvalidateStaleCaches") | |
| } | |
| targetList.each { target -> | |
| tasks.register("${target}CrossDistBitcodeCopy", Sync) { | |
| def bitcodeFiles = configurations.runtimeBitcode.incoming.artifactView { | |
| attributes { | |
| attribute(TargetWithSanitizer.TARGET_ATTRIBUTE, new TargetWithSanitizer(platformManager.targetByName(target), null)) | |
| } | |
| }.files | |
| into(nativeDistribution.map { it.runtime(target) }) | |
| from(bitcodeFiles) { | |
| include("*.bc") | |
| } | |
| } | |
| tasks.register("${target}CrossDistRuntimeFingerprint", PrepareDistributionFingerprint) { | |
| input.from(tasks.named("${target}CrossDistBitcodeCopy")) | |
| output = nativeDistribution.map { it.runtimeFingerprint(target) } | |
| finalizedBy("distInvalidateStaleCaches") // if the fingerprint has updated, some caches may need to be invalidated | |
| } | |
| tasks.register("${target}CrossDistRuntime") { | |
| dependsOn ":kotlin-native:distStdlib" | |
| dependsOn "${target}CrossDistBitcodeCopy" | |
| dependsOn "${target}CrossDistRuntimeFingerprint" | |
| } | |
| tasks.register("${target}PlatformLibs") { | |
| dependsOn ":kotlin-native:platformLibs:${target}Install" | |
| if (target in cacheableTargetNames) { | |
| dependsOn(":kotlin-native:platformLibs:${target}Cache") | |
| } | |
| // Make sure any tasks depending on this one see cleaned-up distribution. | |
| mustRunAfter("distInvalidateStaleCaches") | |
| } | |
| if (target in cacheableTargetNames) { | |
| [false, true].each { optimizationsEnabled -> | |
| def optSuffix = optimizationsEnabled ? "Opt" : "" | |
| tasks.register("${target}StdlibCache${optSuffix}", Sync) { | |
| dependsOn "distStdlib" | |
| dependsOn ":kotlin-native:runtime:${target}StdlibCache${optSuffix}" | |
| // Make sure the cache clean-up has happened, so this task can safely write into the shared cache folder | |
| mustRunAfter("distInvalidateStaleCaches") | |
| into(nativeDistribution.map { it.stdlibCache(target, optimizationsEnabled) }) | |
| def cacheFlavor = UtilsKt.cacheFlavor(target, optimizationsEnabled) | |
| def cacheName = NativeDistribution.cacheDirectoryName("stdlib", !optimizationsEnabled) | |
| from(it.project.project(":kotlin-native:runtime").isolated | |
| .projectDirectory | |
| .dir("build/cache/$target/$cacheFlavor/$cacheName")) { | |
| include('**') | |
| } | |
| } | |
| } | |
| } | |
| tasks.register("${target}CrossDist") { | |
| dependsOn "${target}CrossDistRuntime", "distCompiler" | |
| if (target in cacheableTargetNames) { | |
| dependsOn "${target}StdlibCache" | |
| dependsOn "${target}StdlibCacheOpt" | |
| } | |
| // Make sure any tasks depending on this one see cleaned-up distribution. | |
| mustRunAfter("distInvalidateStaleCaches") | |
| } | |
| } | |
| tasks.register("distPlatformLibs") { | |
| dependsOn("${hostName}PlatformLibs") | |
| } | |
| tasks.register("dist") { | |
| dependsOn "distCompiler", | |
| "distRuntime", | |
| "distDef", | |
| "distStdlib", | |
| "distStdlibCache" | |
| } | |
| tasks.register("crossDist") { | |
| dependsOn "distCompiler", | |
| "crossDistRuntime", | |
| "distDef", | |
| "distStdlib", | |
| "crossDistStdlibCache" | |
| } | |
| tasks.register("distInvalidateStaleCaches", InvalidateStaleCaches) { | |
| distributionRoot.set(nativeDistribution.map { it.root }) | |
| // If the build graph includes any of the fingerprint updates, this task must run after them. | |
| // However, it shouldn't force any of the fingerprints to be computed (e.g. when building :kotlin-native:dist | |
| // this task should run after compiler and host runtime fingerprint updates, but shouldn't force fingerprint from an iOS simulator | |
| // to be computed) | |
| mustRunAfter("distCompilerFingerprint") | |
| targetList.each { target -> | |
| mustRunAfter("${target}CrossDistRuntimeFingerprint") | |
| } | |
| } | |
| tasks.register("bundle") { | |
| dependsOn 'bundleRegular', 'bundlePrebuilt' | |
| } | |
| def sbomBundleRegular = SbomKt.configureSbom(project, "BundleRegular", "Kotlin/Native bundle", [].toSet(), null) | |
| def sbomBundleRegularForPublish = tasks.register("sbomBundleRegularForPublish", Copy) { | |
| dependsOn(sbomBundleRegular) | |
| destinationDir = file("$buildDir/spdx/regular") | |
| from(sbomBundleRegular) { | |
| rename(".*", "kotlin-native-${HostManager.platformName()}-${kotlinBuildProperties.kotlinVersion.get()}.spdx.json") | |
| } | |
| } | |
| tasks.register("bundleRegular", (PlatformInfo.isWindows()) ? Zip : Tar) { | |
| dependsOn(sbomBundleRegularForPublish) | |
| def simpleOsName = HostManager.platformName() | |
| archiveBaseName.set("kotlin-native-$simpleOsName") | |
| archiveVersion.set(kotlinBuildProperties.kotlinVersion) | |
| from(nativeDistribution.map { it.root }) { | |
| include '**' | |
| exclude 'dependencies' | |
| 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. | |
| exclude 'klib/cache/*/org.jetbrains.kotlin.native.platform.*/**' | |
| into "${archiveBaseName.get()}-${archiveVersion.get()}" | |
| } | |
| } | |
| def sbomBundlePrebuilt = SbomKt.configureSbom(project, | |
| "BundlePrebuilt", "Kotlin/Native bundle (prebuilt platform libs)", [].toSet(), null) | |
| def sbomBundlePrebuiltForPublish = tasks.register("sbomBundlePrebuiltForPublish", Copy) { | |
| dependsOn(sbomBundlePrebuilt) | |
| destinationDir = file("$buildDir/spdx/prebuilt") | |
| from(sbomBundlePrebuilt) { | |
| rename(".*", "kotlin-native-prebuilt-${HostManager.platformName()}-${kotlinBuildProperties.kotlinVersion.get()}.spdx.json") | |
| } | |
| } | |
| def mergeCrossBundleTask = NativeFullCrossDistKt.setupMergeCrossBundleTask(project) | |
| tasks.register("bundlePrebuilt", (PlatformInfo.isWindows()) ? Zip : Tar) { | |
| dependsOn(sbomBundlePrebuiltForPublish) | |
| if (mergeCrossBundleTask == null) | |
| dependsOn("crossDistPlatformLibs") | |
| else | |
| dependsOn(mergeCrossBundleTask) | |
| def simpleOsName = HostManager.platformName() | |
| archiveBaseName.set("kotlin-native-prebuilt-$simpleOsName") | |
| archiveVersion.set(kotlinBuildProperties.kotlinVersion) | |
| from(nativeDistribution.map { it.root }) { | |
| include '**' | |
| exclude 'dependencies' | |
| exclude 'klib/testLibrary' | |
| into "${archiveBaseName.get()}-${archiveVersion.get()}" | |
| } | |
| } | |
| void configurePackingLicensesToBundle(AbstractArchiveTask task, boolean containsPlatformLibraries, boolean crossBundleEnabled) { | |
| task.from(project.projectDir) { | |
| include 'licenses/**' | |
| def hasXcodeLibraries = PlatformInfo.isMac() || crossBundleEnabled | |
| if (!containsPlatformLibraries || !hasXcodeLibraries) { | |
| exclude '**/xcode_license.pdf' | |
| } | |
| if (!containsPlatformLibraries) { | |
| exclude '**/mingw-w64-headers_LICENSE.txt' | |
| } | |
| into "${task.archiveBaseName.get()}-${task.archiveVersion.get()}" | |
| } | |
| task.from(new File(project.rootDir, "license")) { | |
| into "${task.archiveBaseName.get()}-${task.archiveVersion.get()}/licenses" | |
| } | |
| } | |
| tasks.named("bundleRegular").configure { | |
| configurePackingLicensesToBundle( | |
| it, | |
| /* containsPlatformLibraries = */ false, | |
| /* crossBundleEnabled = */ mergeCrossBundleTask != null | |
| ) | |
| } | |
| tasks.named("bundlePrebuilt").configure { | |
| configurePackingLicensesToBundle( | |
| it, | |
| /* containsPlatformLibraries = */ true, | |
| /* crossBundleEnabled = */ mergeCrossBundleTask != null | |
| ) | |
| } | |
| configure([bundleRegular, bundlePrebuilt]) { | |
| if (mergeCrossBundleTask == null) { | |
| dependsOn("crossDist") | |
| dependsOn("crossDistStdlibCache") | |
| dependsOn("distSources") | |
| dependsOn("distDef") | |
| } else { | |
| dependsOn(mergeCrossBundleTask) | |
| } | |
| // Bundle tasks read the entire contents of the Native distribution. Make sure this happens after invalid stale caches are removed | |
| mustRunAfter("distInvalidateStaleCaches") | |
| destinationDirectory.set(file('.')) | |
| if (PlatformInfo.isWindows()) { | |
| zip64 true | |
| } else { | |
| archiveExtension.set('tar.gz') | |
| compression = Compression.GZIP | |
| } | |
| // Calculating SHA-256 checksums for bundle artifacts | |
| def archiveExtension = PlatformInfo.isWindows() ? 'zip' : 'tar.gz' | |
| def checksumFile = archiveBaseName.zip(archiveVersion) { name, version -> file("${buildDir}/${name}-${version}.${archiveExtension}.sha256") } | |
| outputs.file(checksumFile).withPropertyName("checksumFile") | |
| // If `bundleRegular`/`bundlePrebuilt` tasks are executed with CC enabled, you will get a | |
| // "Couldn't find method 'calculateChecksum' ... " error. This most likely happens due to bug/issue on Gradle side, somewhere around | |
| // capturing mechanisms in doLast-lambda and CC's serialization/deserialization mechanism. | |
| // | |
| // Issue can be workarounded by converting this file to build.gradle.kts, but it's quite an invasive change, and there's no strict | |
| // need for it. Indeed, normally you can't use `bundleRegular/`bundlePrebuilt` tasks with CC because they depend transitively on | |
| // `KonanCompileLibraryTask` / `KonanCacheTask` (transitively via `crossDist`), which are inherently not compatible with CC | |
| // | |
| // Q: If `bundle*`-tasks depend on CC-incompatible tasks anyways, why we need this explicit call? | |
| // A: When we're building a cross-dist on CI, we don't depend on 'crossDist' and other tasks, but just reuse the dist built in this | |
| // build chain, via `mergeCrossBundleTask`. In such case, there won't be any CC-incompatible tasks in execution plan, and by default, | |
| // Gradle will try using CC, leading to aforementioned "Couldn't find method"-issue. To avoid that, we additionally mark `bundle*` | |
| // tasks as notCompatibleWithConfigurationCache. | |
| notCompatibleWithConfigurationCache("Groovy script evaluation issue workaround") | |
| doLast { | |
| File bundleFile = archiveFile.get().asFile | |
| if (bundleFile.exists()) { | |
| String checksum = calculateChecksum(bundleFile, "SHA-256") | |
| checksumFile.get().write(checksum) | |
| } | |
| } | |
| } | |
| def calculateChecksum(File file, String algorithm) { | |
| MessageDigest digest = MessageDigest.getInstance(algorithm) | |
| FileInputStream fis = new FileInputStream(file) | |
| byte[] byteArray = new byte[1024] | |
| int bytesCount | |
| while ((bytesCount = fis.read(byteArray)) != -1) { | |
| digest.update(byteArray, 0, bytesCount) | |
| } | |
| fis.close() | |
| byte[] bytes = digest.digest() | |
| StringBuilder sb = new StringBuilder() | |
| for (byte aByte : bytes) { | |
| sb.append(Integer.toString((aByte & 0xff) + 0x100, 16).substring(1)) | |
| } | |
| return sb.toString() | |
| } | |
| tasks.register("tc-dist", (PlatformInfo.isWindows()) ? Zip : Tar) { | |
| dependsOn('dist') | |
| dependsOn('distSources') | |
| def simpleOsName = HostManager.platformName() | |
| archiveBaseName.set("kotlin-native-dist-$simpleOsName") | |
| archiveVersion.set(kotlinBuildProperties.kotlinVersion) | |
| from(nativeDistribution) { | |
| include '**' | |
| exclude 'dependencies' | |
| into "${archiveBaseName.get()}-${archiveVersion.get()}" | |
| } | |
| destinationDirectory.set(file('.')) | |
| if (PlatformInfo.isWindows()) { | |
| zip64 true | |
| } else { | |
| archiveExtension.set('tar.gz') | |
| compression = Compression.GZIP | |
| } | |
| } | |
| tasks.register("samples") { | |
| dependsOn 'samplesZip', 'samplesTar' | |
| } | |
| tasks.register("samplesZip", Zip) | |
| tasks.register("samplesTar", Tar) { | |
| archiveExtension = 'tar.gz' | |
| compression = Compression.GZIP | |
| } | |
| configure([samplesZip, samplesTar]) { | |
| archiveBaseName = "kotlin-native-samples-${kotlinBuildProperties.kotlinVersion.get()}" | |
| destinationDirectory = projectDir | |
| into(archiveBaseName) | |
| from(file('samples')) { | |
| // Process properties files separately. | |
| exclude '**/gradle.properties' | |
| } | |
| from(project.projectDir) { | |
| include 'licenses/**' | |
| } | |
| from(file('samples')) { | |
| include '**/gradle.properties' | |
| filter { | |
| it.startsWith('org.jetbrains.kotlin.native.home=') || it.startsWith('# Use custom Kotlin/Native home:') ? null : it | |
| } | |
| filter(org.apache.tools.ant.filters.FixCrLfFilter, "eol": org.apache.tools.ant.filters.FixCrLfFilter.CrLf.newInstance("lf")) | |
| } | |
| // Exclude build artifacts. | |
| exclude '**/build' | |
| exclude '**/.gradle' | |
| exclude '**/.idea' | |
| exclude '**/*.kt.bc-build/' | |
| } | |
| tasks.register("copy_samples") { | |
| dependsOn 'copySamples' | |
| } | |
| tasks.register("copySamples", CopySamples) { | |
| destinationDir = file('build/samples-under-test') | |
| } | |
| compilationDatabase { | |
| allTargets {} | |
| } | |
| // TODO: Replace with a more convenient user-facing task that can build for a specific target. | |
| // like compilationDatabase with optional argument --target. | |
| tasks.register("compdb", Copy) { | |
| from compilationDatabase.hostTarget.task | |
| into layout.projectDirectory | |
| group = compilationDatabase.TASK_GROUP | |
| description = "Copy host compilation database to kotlin-native/" | |
| } | |
| targetList.each { targetName -> | |
| CompareDistributionSignatures.registerForPlatform(project, targetName) | |
| } | |
| CompareDistributionSignatures.registerForStdlib(project) | |
| // FIXME: should be a part of Host/TargetManager | |
| String platformName(KonanTarget target) { | |
| def result | |
| switch (target) { | |
| case KonanTarget.LINUX_X64: | |
| result ="linux-x86_64" | |
| break | |
| case KonanTarget.MACOS_X64: | |
| result = "macos-x86_64" | |
| break | |
| case KonanTarget.MACOS_ARM64: | |
| result = "macos-aarch64" | |
| break | |
| case KonanTarget.MINGW_X64: | |
| result = "windows-x86_64" | |
| break | |
| default: | |
| throw TargetSupportException("Unknown host target") | |
| } | |
| return result | |
| } | |
| Map<KonanTarget, File> createConfigurations(List<File> bundles) { | |
| def hostTargets = platformManager.enabledByHost.keySet().findAll { | |
| it.name != 'macos_x64' | |
| } as Set | |
| def result = hostTargets.collectEntries { target -> | |
| [ (target): bundles.find { it.name.contains(platformName(target)) }] | |
| } | |
| result.retainAll { it.value != null } | |
| def missingBundles = hostTargets - result.keySet() | |
| if (!missingBundles.isEmpty()) { | |
| println("Some of the archive bundles are missing for targets $missingBundles:") | |
| println(result) | |
| throw new IllegalArgumentException("Bundle archives are missing for $missingBundles") | |
| } | |
| result.each { target, file -> | |
| if (!file.name.contains(BuildPropertiesKt.getKotlinBuildProperties(project).kotlinVersion.get())) { | |
| throw new IllegalArgumentException("Incorrect version specified for the publish: ${file.name}") | |
| } | |
| } | |
| return result | |
| } | |
| def bundlesLocationFiles = UtilsKt.getNativeBundlesLocation(project) | |
| .listFiles() | |
| .toList() | |
| KotlinBuildPublishingPluginKt.configureDefaultPublishing( | |
| /* receiver = */ project, | |
| /* signingRequired = */ KotlinBuildPublishingPluginKt.getSignLibraryPublication(project) | |
| ) | |
| tasks.named("clean", Delete) { | |
| it.delete(nativeDistribution.map { it.root }) | |
| it.delete(layout.buildDirectory) | |
| it.delete(bundle.outputs.files) | |
| it.delete("${projectDir}/compile_commands.json") | |
| it.delete("${rootDir}/test.output") // Clean up after legacy test infrastructure | |
| } | |
| publishing { | |
| publications { | |
| def publishBundlesFromLocation = UtilsKt.getNativeBundlesLocation(project) != project.projectDir | |
| register("Bundle", MavenPublication) { mvn -> | |
| mvn.groupId = project.group.toString() | |
| mvn.artifactId = project.name | |
| mvn.version = kotlinBuildProperties.kotlinVersion.get() | |
| if (publishBundlesFromLocation) { | |
| def bundleArchives = bundlesLocationFiles | |
| .findAll { | |
| it.name.startsWith("kotlin-native") | |
| && !it.name.contains("prebuilt") | |
| && (it.name.endsWith("zip") || it.name.endsWith("tar.gz")) | |
| } | |
| def bundleConfigs = createConfigurations(bundleArchives) | |
| bundleConfigs.forEach { target, file -> | |
| def archiveExtension = (target.family == Family.MINGW) ? 'zip' : 'tar.gz' | |
| mvn.artifact(file) { | |
| classifier = platformName(target) | |
| extension = archiveExtension | |
| } | |
| mvn.artifact("${UtilsKt.getNativeBundlesLocation(project)}/kotlin-native-${platformName(target)}-${kotlinBuildProperties.kotlinVersion.get()}.spdx.json") { | |
| classifier = platformName(target) | |
| extension = "spdx.json" | |
| } | |
| } | |
| } else { | |
| mvn.artifact(bundleRegular) { | |
| classifier = HostManager.platformName() | |
| extension = (PlatformInfo.isWindows()) ? 'zip' : 'tar.gz' | |
| } | |
| mvn.artifact(sbomBundleRegular) { | |
| classifier = HostManager.platformName() | |
| extension = "spdx.json" | |
| } | |
| } | |
| KotlinBuildPublishingPluginKt.configureKotlinPomAttributes( | |
| /* receiver = */ mvn, | |
| /* project = */ project, | |
| /* explicitDescription = */ "Kotlin/Native bundle", | |
| /* packaging = */ "pom", | |
| /* explicitName = */ null | |
| ) | |
| } | |
| register("BundlePrebuilt", MavenPublication) { mvn -> | |
| mvn.groupId = project.group.toString() | |
| mvn.artifactId = project.name + "-prebuilt" | |
| mvn.version = kotlinBuildProperties.kotlinVersion.get() | |
| if (publishBundlesFromLocation) { | |
| def prebuiltBundleArchives = bundlesLocationFiles | |
| .findAll { | |
| it.name.startsWith("kotlin-native-prebuilt") | |
| && (it.name.endsWith("zip") || it.name.endsWith("tar.gz")) | |
| } | |
| def bundlePrebuiltConfigs = createConfigurations(prebuiltBundleArchives) | |
| bundlePrebuiltConfigs.forEach { target, file -> | |
| def archiveExtension = (target.family == Family.MINGW) ? 'zip' : 'tar.gz' | |
| mvn.artifact(file) { | |
| classifier = platformName(target) | |
| extension = archiveExtension | |
| } | |
| mvn.artifact("${UtilsKt.getNativeBundlesLocation(project)}/kotlin-native-prebuilt-${platformName(target)}-${kotlinBuildProperties.kotlinVersion.get()}.spdx.json") { | |
| classifier = platformName(target) | |
| extension = "spdx.json" | |
| } | |
| } | |
| } else { | |
| mvn.artifact(bundlePrebuilt) { | |
| classifier = HostManager.platformName() | |
| extension = (PlatformInfo.isWindows()) ? 'zip' : 'tar.gz' | |
| } | |
| mvn.artifact(sbomBundlePrebuilt) { | |
| classifier = HostManager.platformName() | |
| extension = "spdx.json" | |
| } | |
| } | |
| KotlinBuildPublishingPluginKt.configureKotlinPomAttributes( | |
| /* receiver = */ mvn, | |
| /* project = */ project, | |
| /* explicitDescription = */ "Kotlin/Native bundle (prebuilt platform libs)", | |
| /* packaging = */ "pom", | |
| /* explicitName = */ null | |
| ) | |
| } | |
| } | |
| } |