Files
kotlin-fork/kotlin-native/build.gradle
T
Pavel Punegov 2d2714c8de [K/N] Move runtime bitcode files out of stdlib
Native bitcode files were moved out of the stdlib to the default
location of bitcode files in the dist.
Now it is possible to build stdlib separately and once as a klib
without bitcode files inside.
2023-12-14 11:33:20 +00:00

825 lines
28 KiB
Groovy

/*
* 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.konan.target.*
import org.jetbrains.kotlin.konan.util.*
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 com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.apache.tools.ant.filters.ReplaceTokens
import org.jetbrains.kotlin.UtilsKt
import java.util.concurrent.ConcurrentHashMap
import plugins.KotlinBuildPublishingPluginKt
buildscript {
apply from: "gradle/kotlinGradlePlugin.gradle"
repositories {
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath 'com.github.johnrengelman:shadow:8.1.1'
}
}
defaultTasks 'clean', 'dist'
if (PlatformInfo.isMac()) {
PlatformInfo.checkXcodeVersion(project)
}
apply plugin: "kotlin.native.build-tools-conventions"
ext {
distDir = UtilsKt.getKotlinNativeDist(project)
def konanDataDir = project.hasProperty('konan.data.dir') ? project.property('konan.data.dir').toString() : null
dependenciesDir = DependencyDirectories.INSTANCE.getDependenciesRoot(konanDataDir)
experimentalEnabled = project.hasProperty("org.jetbrains.kotlin.native.experimentalTargets")
platformManager = new PlatformManager(DistributionKt.buildDistribution(projectDir.absolutePath, konanDataDir),
ext.experimentalEnabled)
cacheableTargetNames = platformManager.hostPlatform.cacheableTargets
cacheableTargets = cacheableTargetNames.collect { platformManager.targetByName(it) }
// Some targets miss zlib in their sysroots.
// We skip these targets when generate a corresponding platform library.
// See also: the :distDef task, targetDefFiles in the :platformLibs project.
targetsWithoutZlib = [
KonanTarget.LINUX_MIPS32.INSTANCE,
KonanTarget.LINUX_MIPSEL32.INSTANCE
]
kotlinCompilerModule = project(":kotlin-compiler")
kotlinStdLibModule= project(":kotlin-stdlib")
// A separate map for each build for automatic cleaning the daemon after the build have finished.
toolClassLoadersMap = new ConcurrentHashMap<Object, URLClassLoader>()
}
allprojects {
repositories {
mavenCentral()
maven {
url project.bootstrapKotlinRepo
}
}
setupHostAndTarget()
loadCommandLineProperties()
loadLocalProperties()
setupClang(project)
}
void setupHostAndTarget() {
ext.hostName = platformManager.hostName
ext.targetList = EnabledTargetsKt.enabledTargets(platformManager).collect { it.visibleName } as List
ext.konanTargetList = EnabledTargetsKt.enabledTargets(platformManager) as List
}
void setupClang(Project project) {
project.extensions.platformManager = project.project(":kotlin-native").ext.platformManager
project.extensions.execClang = org.jetbrains.kotlin.ExecClang.create(project)
}
void loadLocalProperties() {
if (new File("$project.rootDir/local.properties").exists()) {
Properties props = new Properties()
props.load(new FileInputStream("$project.rootDir/local.properties"))
props.each { prop -> project.ext.set(prop.key, prop.value) }
}
}
void loadCommandLineProperties() {
if (project.hasProperty("konanc_flags")) {
throw new Error("Specify either -Ptest_flags or -Pbuild_flags.")
}
ext.globalBuildArgs = new ArrayList<String>()
if (project.hasProperty("build_flags")) {
for (String flag : ext.build_flags.toString().split("\\s")) {
flag = flag.trim()
if (!flag.isEmpty()) ext.globalBuildArgs.add(flag)
}
}
ext.globalTestArgs = new ArrayList<String>()
ext.globalTestArgs.add("-Xpartial-linkage=enable")
ext.globalTestArgs.add("-Xpartial-linkage-loglevel=error")
if (project.hasProperty("test_flags")) {
for (String flag : ext.test_flags.toString().split("\\s")) {
flag = flag.trim()
if (!flag.isEmpty()) ext.globalTestArgs.add(flag)
}
}
ext.testTarget = project.hasProperty("test_target") ? ext.test_target : ext.hostName
}
configurations {
ftpAntTask
distPack
commonSources
runtimeBitcode {
canBeConsumed = false
canBeResolved = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, CppUsage.LLVM_BITCODE))
}
}
embeddableJar {
canBeConsumed = false
canBeResolved = true
}
}
apply plugin: CompilationDatabasePlugin
dependencies {
ftpAntTask 'org.apache.ant:ant-commons-net:1.9.9'
distPack project(':kotlin-native:Interop:Runtime')
distPack project(':kotlin-native:Interop:Indexer')
distPack project(':kotlin-native:Interop:StubGenerator')
distPack project(':kotlin-native:Interop:Skia')
distPack project(':kotlin-native:backend.native')
distPack project(':native:objcexport-header-generator')
distPack project(':native:base')
distPack project(':kotlin-native:utilities:cli-runner')
distPack project(':kotlin-native:utilities:basic-utils')
distPack project(':kotlin-native:klib')
distPack project(path: ':kotlin-native:endorsedLibraries:kotlinx.cli', configuration: "jvmRuntimeElements")
commonSources project(path: ':kotlin-stdlib', configuration: 'metadataSourcesElements')
commonSources project(path: ':kotlin-test', configuration: 'metadataSourcesElements')
compilationDatabase project(":kotlin-native:common")
compilationDatabase project(":kotlin-native:runtime")
runtimeBitcode project(":kotlin-native:runtime")
embeddableJar project(path: ':kotlin-native:prepare:kotlin-native-compiler-embeddable', configuration: 'runtimeElements')
}
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 = file("$distDir/sources")
archiveFileName = "kotlin-stdlib-native-sources.zip"
includeEmptyDirs = false
include('**/*.kt')
from {
configurations.commonSources
.collect { zipTree(it) }
.inject { t1, t2 -> t1 + t2 }
}
into('nativeWasmMain') {
from(project(":kotlin-stdlib").file('native-wasm/src/'))
}
into('nativeMain') {
from(project(':kotlin-native:runtime').file('src/main/kotlin'))
from(project(':kotlin-native:Interop:Runtime').file('src/main/kotlin'))
from(project(':kotlin-native:Interop:Runtime').file('src/native/kotlin'))
from(project(':kotlin-native:Interop:JsRuntime').file('src/main/kotlin')) {
into('kotlinx/wasm/jsinterop')
}
}
}
tasks.register("distSources") {
dependsOn(distNativeSources)
}
tasks.register("shadowJar", ShadowJar) {
mergeServiceFiles()
destinationDirectory.set(file("$distDir/konan/lib"))
archiveBaseName.set("kotlin-native")
archiveVersion.set("")
archiveClassifier.set("")
// Exclude trove4j because of license agreement.
exclude "*trove4j*"
exclude("META-INF/versions/9/module-info.class")
configurations = [project.configurations.distPack]
outputs.upToDateWhen {
archiveFile.getOrNull()?.asFile?.exists() ?: false
}
}
tasks.register("distCompiler", Copy) {
// 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 ':kotlin-native:shadowJar'
dependsOn configurations.embeddableJar
}
destinationDir distDir
from(project(':kotlin-native:backend.native').file("build/nativelibs/$hostName")) {
into('konan/nativelib')
}
from(project(':kotlin-native:backend.native').file('build/external_jars/trove4j.jar')) {
into('konan/lib')
}
from(configurations.embeddableJar) {
rename {
"kotlin-native-compiler-embeddable.jar"
}
into("konan/lib")
}
from(project(':kotlin-native:Interop').file('Indexer/build/nativelibs')) {
into('konan/nativelib')
}
from(project(':kotlin-native:Interop').file('Runtime/build/nativelibs')) {
into('konan/nativelib')
}
from(project(':kotlin-native:libllvmext').file('build/libs/llvmext/shared')) {
into('konan/nativelib')
}
from(project(':kotlin-native:llvmDebugInfoC').file('build/libs/debugInfo/shared')) {
into('konan/nativelib')
}
from(project(':kotlin-native:llvmDebugInfoC').file('src/scripts/konan_lldb.py')) {
into('tools')
}
from(project(':kotlin-native:utilities').file('env_blacklist')) {
into('tools')
}
from(file('cmd')) {
fileMode(0755)
into('bin')
if (!PlatformInfo.isWindows()) {
exclude('**/*.bat')
}
}
from(project.file('konan')) {
into('konan')
exclude('**/*.properties')
}
from(project.file('konan')) {
into('konan')
include('**/*.properties')
filter(ReplaceTokens, tokens: [compilerVersion: kotlinVersion])
// Set LLVM variant that will be used by default in the distribution.
// `user` - smaller, includes only necessary components.
// `dev` - bigger, includes (almost) every possible component. Use this one,
// if your feature requires component that is not a part of user distribution (yet).
// Note: by default konan.properties use `dev` variant because it is needed for building our LLVM dynamic library.
String llvmVariant = 'user'
filter(ReplaceTokens,
beginToken: '$',
endToken: '',
tokens: [("llvm.${hostName}.dev".toString()): "\$llvm.${hostName}.${llvmVariant}".toString()]
)
}
if (experimentalEnabled) {
file('konan/experimentalTargetsEnabled').text = ""
} else {
delete('konan/experimentalTargetsEnabled')
}
}
tasks.register("distDef", Copy) {
destinationDir project.file("$distDir/konan/platformDef/")
platformManager.targetValues.each { target ->
from(project(":kotlin-native:platformLibs").file("src/platform/${target.family.name().toLowerCase()}")) {
into target.visibleName
include '**/*.def'
if (target in targetsWithoutZlib) {
exclude '**/zlib.def'
}
}
}
}
tasks.register("listDist", Exec) {
commandLine 'find', distDir
}
tasks.register("distRuntime", Copy) {
dependsOn "${hostName}CrossDistRuntime"
}
tasks.register("distStdlibCache") {
if (hostName in cacheableTargetNames) {
dependsOn("${hostName}StdlibCache")
}
}
def stdlib = 'klib/common/stdlib'
def stdlibDefaultComponent = "$stdlib/default"
tasks.register("crossDistRuntime") {
dependsOn.addAll(targetList.collect { "${it}CrossDistRuntime" })
}
tasks.register("crossDistPlatformLibs") {
dependsOn.addAll(targetList.collect { "${it}PlatformLibs" })
}
tasks.register("crossDistStdlib") {
dependsOn.addAll(targetList.collect { "${it}CrossDistStdlib" })
}
tasks.register("crossDistStdlibCache") {
dependsOn.addAll(targetList.findAll { it in cacheableTargetNames }.collect { "${it}StdlibCache" })
}
targetList.each { target ->
tasks.register("${target}CrossDistStdlib", Copy) {
dependsOn ":kotlin-native:runtime:${target}Stdlib"
// TODO: add explicit dependency on host task with IR klib stdlib parts
// As for now it is possibly to build up distribution from the tc-dist to crossdist
// by request of tests that need cross-targets or platform libs. It may create undesired
// issues with overwriting the file being used by the concurrent build/test.
// This building (by request) should be turned off when this to-do is fixed.
// if (target != hostName) {
// dependsOn ":kotlin-native:${hostName}CrossDistStdlib"
// }
destinationDir project.file("$distDir/$stdlib")
from(project(':kotlin-native:runtime').file("build/${target}Stdlib")) {
if (target == hostName) {
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.
include('*/targets/**')
include('*/manifest')
}
eachFile {
if (name == 'manifest') {
def existingManifest = file("$destinationDir/$path")
if (existingManifest.exists()) {
UtilsKt.mergeManifestsByTargets(project, file, existingManifest)
exclude()
}
}
}
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.register("${target}CrossDistBitcodeCopy", Copy) {
def bitcodeFiles = configurations.runtimeBitcode.incoming.artifactView {
attributes {
attribute(TargetWithSanitizer.TARGET_ATTRIBUTE, new TargetWithSanitizer(platformManager.targetByName(target), null))
}
}.files
destinationDir project.file("$distDir/konan/targets/")
from(bitcodeFiles) {
include("*.bc")
into("$target/native")
}
}
tasks.register("${target}CrossDistRuntime", Copy) {
dependsOn ":kotlin-native:${target}CrossDistStdlib"
dependsOn "${target}CrossDistBitcodeCopy"
destinationDir project.file("$distDir/$stdlibDefaultComponent")
}
tasks.register("${target}PlatformLibs") {
dependsOn ":kotlin-native:platformLibs:${target}Install"
if (target in cacheableTargetNames) {
dependsOn(":kotlin-native:platformLibs:${target}Cache")
}
}
if (target in cacheableTargetNames) {
tasks.register("${target}StdlibCache", Copy) {
dependsOn "${target}CrossDistStdlib"
dependsOn ":kotlin-native:runtime:${target}StdlibCache"
destinationDir project.file("$distDir/klib/cache/")
from(project(":kotlin-native:runtime").layout.buildDirectory.dir("cache/$target")) {
include('**')
}
}
}
tasks.register("${target}CrossDist") {
dependsOn "${target}CrossDistRuntime", "distCompiler"
if (target in cacheableTargetNames) {
dependsOn "${target}StdlibCache"
}
}
}
tasks.register("distPlatformLibs") {
dependsOn ':kotlin-native:platformLibs:hostInstall'
dependsOn ':kotlin-native:platformLibs:hostCache'
}
tasks.register("dist") {
dependsOn "distCompiler",
"distRuntime",
"distDef",
"distStdlibCache"
}
tasks.register("crossDist") {
dependsOn "distCompiler",
"crossDistRuntime",
"distDef",
"crossDistStdlib",
"crossDistStdlibCache"
}
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.map { it.outputDirectory.file("BundleRegular.spdx.json") }) {
rename(".*", "kotlin-native-${HostManager.platformName()}-${kotlinVersion}.spdx.json")
}
}
tasks.register("bundleRegular", (PlatformInfo.isWindows()) ? Zip : Tar) {
dependsOn(sbomBundleRegularForPublish)
def simpleOsName = HostManager.platformName()
archiveBaseName.set("kotlin-native-$simpleOsName")
archiveVersion.set(kotlinVersion)
from(UtilsKt.getKotlinNativeDist(project)) {
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.map { it.outputDirectory.file("BundlePrebuilt.spdx.json") }) {
rename(".*", "kotlin-native-prebuilt-${HostManager.platformName()}-${kotlinVersion}.spdx.json")
}
}
tasks.register("bundlePrebuilt", (PlatformInfo.isWindows()) ? Zip : Tar) {
dependsOn(sbomBundlePrebuiltForPublish)
dependsOn("crossDistPlatformLibs")
def simpleOsName = HostManager.platformName()
archiveBaseName.set("kotlin-native-prebuilt-$simpleOsName")
archiveVersion.set(kotlinVersion)
from(UtilsKt.getKotlinNativeDist(project)) {
include '**'
exclude 'dependencies'
exclude 'klib/testLibrary'
into "${archiveBaseName.get()}-${archiveVersion.get()}"
}
}
void configurePackingLicensesToBundle(AbstractArchiveTask task, boolean containsPlatformLibraries) {
task.from(project.projectDir) {
include 'licenses/**'
if (!containsPlatformLibraries || !PlatformInfo.isMac()) {
exclude '**/xcode_license.pdf'
}
if (!containsPlatformLibraries) {
exclude '**/mingw-w64-headers_LICENSE.txt'
}
into "${task.archiveBaseName.get()}-${task.archiveVersion.get()}"
}
task.from(project.rootProject.file("license")) {
into "${task.archiveBaseName.get()}-${task.archiveVersion.get()}/licenses"
}
}
tasks.named("bundleRegular").configure {
configurePackingLicensesToBundle(it, /* containsPlatformLibraries = */ false)
}
tasks.named("bundlePrebuilt").configure {
configurePackingLicensesToBundle(it, /* containsPlatformLibraries = */ true)
}
configure([bundleRegular, bundlePrebuilt]) {
dependsOn("crossDist")
dependsOn("crossDistStdlibCache")
dependsOn("distSources")
dependsOn("distDef")
from(project.projectDir) {
include 'RELEASE_NOTES.md'
into "${archiveBaseName.get()}-${archiveVersion.get()}"
}
destinationDirectory.set(file('.'))
if (PlatformInfo.isWindows()) {
zip64 true
} else {
archiveExtension.set('tar.gz')
compression = Compression.GZIP
}
}
tasks.register("tc-dist", (PlatformInfo.isWindows()) ? Zip : Tar) {
dependsOn('dist')
dependsOn('distSources')
def simpleOsName = HostManager.platformName()
archiveBaseName.set("kotlin-native-dist-$simpleOsName")
archiveVersion.set(kotlinVersion)
from(UtilsKt.getKotlinNativeDist(project)) {
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-$kotlinVersion"
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 ->
tasks.register("${targetName}CheckPlatformAbiCompatibility", CompareDistributionSignatures) {
dependsOn "${targetName}PlatformLibs"
libraries = new CompareDistributionSignatures.Libraries.Platform(targetName)
if (project.hasProperty("anotherDistro")) {
oldDistribution = project.findProperty("anotherDistro")
}
onMismatchMode = CompareDistributionSignatures.OnMismatchMode.FAIL
}
}
tasks.register("checkStdlibAbiCompatibility", CompareDistributionSignatures) {
dependsOn "distRuntime"
libraries = CompareDistributionSignatures.Libraries.Standard.INSTANCE
if (project.hasProperty("anotherDistro")) {
oldDistribution = project.findProperty("anotherDistro")
}
onMismatchMode = CompareDistributionSignatures.OnMismatchMode.FAIL
}
// 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()
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(kotlinVersion)) {
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) {
dependsOn subprojects.collect { it.tasks.matching { it.name == "clean" } }
doFirst {
delete distDir
delete layout.buildDirectory
delete bundle.outputs.files
delete "${projectDir}/compile_commands.json"
}
}
publishing {
publications {
def publishBundlesFromLocation = UtilsKt.getNativeBundlesLocation(project) != project.projectDir
register("Bundle", MavenPublication) { mvn ->
mvn.groupId = project.group.toString()
mvn.artifactId = project.name
mvn.version = kotlinVersion
if (publishBundlesFromLocation) {
def bundleArchives = bundlesLocationFiles
.findAll { it.name.startsWith("kotlin-native") && !it.name.contains("prebuilt") && !it.name.endsWith("spdx.json") }
def bundleConfigs = createConfigurations(bundleArchives)
bundleConfigs.forEach { target, file ->
mvn.artifact(file) {
classifier = platformName(target)
extension = (target.family == Family.MINGW) ? 'zip' : 'tar.gz'
}
mvn.artifact("${UtilsKt.getNativeBundlesLocation(project)}/kotlin-native-${platformName(target)}-${kotlinVersion}.spdx.json") {
classifier = platformName(target)
extension = "spdx.json"
}
}
} else {
mvn.artifact(bundleRegular) {
classifier = HostManager.platformName()
extension = (PlatformInfo.isWindows()) ? 'zip' : 'tar.gz'
}
}
KotlinBuildPublishingPluginKt.configureKotlinPomAttributes(
/* receiver = */ mvn,
/* project = */ project,
/* explicitDescription = */ "Kotlin/Native bundle",
/* packaging = */ "pom"
)
}
register("BundlePrebuilt", MavenPublication) { mvn ->
mvn.groupId = project.group.toString()
mvn.artifactId = project.name + "-prebuilt"
mvn.version = kotlinVersion
if (publishBundlesFromLocation) {
def prebuiltBundleArchives = bundlesLocationFiles
.findAll { it.name.startsWith("kotlin-native-prebuilt") && !it.name.endsWith("spdx.json") }
def bundlePrebuiltConfigs = createConfigurations(prebuiltBundleArchives)
bundlePrebuiltConfigs.forEach { target, file ->
mvn.artifact(file) {
classifier = platformName(target)
extension = (target.family == Family.MINGW) ? 'zip' : 'tar.gz'
}
mvn.artifact("${UtilsKt.getNativeBundlesLocation(project)}/kotlin-native-prebuilt-${platformName(target)}-${kotlinVersion}.spdx.json") {
classifier = platformName(target)
extension = "spdx.json"
}
}
} else {
mvn.artifact(bundlePrebuilt) {
classifier = HostManager.platformName()
extension = (PlatformInfo.isWindows()) ? 'zip' : 'tar.gz'
}
}
KotlinBuildPublishingPluginKt.configureKotlinPomAttributes(
/* receiver = */ mvn,
/* project = */ project,
/* explicitDescription = */ "Kotlin/Native bundle (prebuilt platform libs)",
/* packaging = */ "pom"
)
}
}
}