ef9413108b
This is refactoring in preparation for KT-59764. Names and layout of forward declarations related classes was copy-pasted many times over compiler code. Implementing KT-59764 would require copy-pasting it two more times. So instead of doing this it was put in single place. No behaviour changes intended in this commit.
257 lines
8.1 KiB
Groovy
257 lines
8.1 KiB
Groovy
/*
|
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
* that can be found in the LICENSE file.
|
|
*/
|
|
|
|
import org.jetbrains.kotlin.cpp.CppConsumerPlugin
|
|
import org.jetbrains.kotlin.cpp.CppUsage
|
|
import org.jetbrains.kotlin.cpp.DependencyHandlerExKt
|
|
import org.jetbrains.kotlin.tools.NativePluginKt
|
|
|
|
|
|
buildscript {
|
|
apply from: "../../kotlin-native/gradle/kotlinGradlePlugin.gradle"
|
|
apply plugin: 'project-report'
|
|
}
|
|
|
|
apply plugin: 'java'
|
|
apply plugin: 'kotlin'
|
|
apply plugin: "native-interop-plugin"
|
|
apply plugin: "maven-publish"
|
|
apply plugin: CppConsumerPlugin
|
|
|
|
sourceSets {
|
|
compiler {
|
|
kotlin {
|
|
srcDir 'compiler/ir/backend.native/src/'
|
|
}
|
|
resources.srcDir 'compiler/ir/backend.native/resources/'
|
|
}
|
|
cli_bc {
|
|
kotlin.srcDir 'cli.bc/src'
|
|
}
|
|
}
|
|
|
|
compileCompilerKotlin {
|
|
kotlinOptions.jvmTarget = "1.8"
|
|
kotlinOptions.freeCompilerArgs += [
|
|
'-opt-in=kotlin.RequiresOptIn',
|
|
"-opt-in=kotlinx.cinterop.BetaInteropApi",
|
|
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
|
|
'-Xskip-prerelease-check']
|
|
}
|
|
|
|
compileCli_bcKotlin {
|
|
kotlinOptions.freeCompilerArgs += ['-Xskip-prerelease-check']
|
|
}
|
|
|
|
configurations {
|
|
commonFilesBitcode {
|
|
canBeConsumed = false
|
|
canBeResolved = true
|
|
attributes {
|
|
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, CppUsage.LLVM_BITCODE))
|
|
}
|
|
}
|
|
commonEnvBitcode {
|
|
canBeConsumed = false
|
|
canBeResolved = true
|
|
attributes {
|
|
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, CppUsage.LLVM_BITCODE))
|
|
}
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
use(DependencyHandlerExKt) {
|
|
commonFilesBitcode module(project(":kotlin-native:common"), "files")
|
|
commonEnvBitcode module(project(":kotlin-native:common"), "env")
|
|
}
|
|
}
|
|
|
|
kotlinNativeInterop {
|
|
llvm {
|
|
|
|
dependsOn ":kotlin-native:llvmDebugInfoC:${NativePluginKt.lib("debugInfo")}"
|
|
dependsOn ":kotlin-native:libllvmext:${NativePluginKt.lib("llvmext")}"
|
|
defFile 'llvm.def'
|
|
compilerOpts "-I$llvmDir/include", "-I${rootProject.project(':kotlin-native:llvmDebugInfoC').projectDir}/src/main/include", "-I${rootProject.project(':kotlin-native:libllvmext').projectDir}/src/main/include"
|
|
if (isMac()) {
|
|
// $llvmDir/lib contains libc++.1.dylib too, and it seems to be preferred by the linker
|
|
// over the sysroot-provided one.
|
|
// As a result, libllvmstubs.dylib gets linked with $llvmDir/lib/libc++.1.dylib.
|
|
// It has install_name = @rpath/libc++.1.dylib, which won't work for us, because
|
|
// dynamic loader won't be able to find libc++ when loading libllvmstubs.
|
|
// For some reason, this worked fine before macOS 12.3.
|
|
//
|
|
// To enforce linking with proper libc++, pass the default path explicitly:
|
|
linkerOpts "-L${platformManager.hostPlatform.absoluteTargetSysRoot}/usr/lib"
|
|
}
|
|
linkerOpts "-L$llvmDir/lib", "-L${rootProject.project(':kotlin-native:llvmDebugInfoC').buildDir}", "-L${rootProject.project(':kotlin-native:libllvmext').buildDir}"
|
|
}
|
|
|
|
files {
|
|
linker 'clang++'
|
|
link configurations.commonFilesBitcode
|
|
|
|
// TODO: These should come from some sort of commonFilesApi configuration
|
|
headers fileTree('../common/src/files/headers') {
|
|
include '**/*.h'
|
|
include '**/*.hpp'
|
|
}
|
|
|
|
pkg 'org.jetbrains.kotlin.backend.konan.files'
|
|
}
|
|
|
|
|
|
env {
|
|
linker 'clang++'
|
|
link configurations.commonEnvBitcode
|
|
|
|
// TODO: These should come from some sort of commonEnvApi configuration
|
|
headers fileTree('../common/src/env/headers') {
|
|
include '**/*.h'
|
|
include '**/*.hpp'
|
|
}
|
|
|
|
pkg 'org.jetbrains.kotlin.backend.konan.env'
|
|
}
|
|
}
|
|
|
|
|
|
configurations {
|
|
compilerApi {
|
|
extendsFrom kotlinNativeInterop['llvm'].configuration
|
|
extendsFrom kotlinNativeInterop['files'].configuration
|
|
extendsFrom kotlinNativeInterop['env'].configuration
|
|
}
|
|
kotlin_compiler_jar
|
|
kotlin_stdlib_jar
|
|
kotlin_reflect_jar
|
|
kotlin_script_runtime_jar
|
|
trove4j_jar
|
|
|
|
cli_bcApiElements {
|
|
extendsFrom cli_bcApi
|
|
}
|
|
|
|
cli_bcApi.extendsFrom compilerApi
|
|
}
|
|
|
|
dependencies {
|
|
kotlin_compiler_jar kotlinCompilerModule
|
|
kotlin_stdlib_jar kotlinStdLibModule
|
|
use(RepoDependencies) {
|
|
trove4j_jar commonDependency("org.jetbrains.intellij.deps:trove4j")
|
|
kotlin_reflect_jar commonDependency("org.jetbrains.kotlin:kotlin-reflect")
|
|
compilerApi(commonDependency("org.jetbrains.intellij.deps.fastutil:intellij-deps-fastutil")) { setTransitive(false) }
|
|
compilerApi(commonDependency("org.jetbrains.intellij.deps:log4j")) { setTransitive(false) }
|
|
compilerApi(commonDependency("org.jetbrains.intellij.deps:jdom"))
|
|
compilerApi(commonDependency("com.fasterxml:aalto-xml")) { setTransitive(false) }
|
|
compilerApi(commonDependency("org.codehaus.woodstox:stax2-api")) { setTransitive(false) }
|
|
}
|
|
kotlin_script_runtime_jar project(":kotlin-script-runtime")
|
|
|
|
compilerApi project(":kotlin-native:utilities:basic-utils")
|
|
|
|
compilerImplementation project(":kotlin-compiler")
|
|
compilerApi project(":native:kotlin-native-utils")
|
|
compilerApi project(":core:descriptors")
|
|
compilerApi project(":core:compiler.common.native")
|
|
compilerApi project(":compiler:ir.tree")
|
|
compilerApi project(":compiler:ir.backend.common")
|
|
compilerApi project(":compiler:util")
|
|
compilerApi project(":native:frontend.native")
|
|
compilerApi project(":compiler:cli-common")
|
|
compilerApi project(":compiler:cli-base")
|
|
compilerApi project(":compiler:cli")
|
|
compilerApi project(":kotlin-util-klib")
|
|
compilerApi project(":kotlin-util-klib-metadata")
|
|
compilerApi project(":compiler:ir.serialization.common")
|
|
compilerApi project(":compiler:fir:fir-serialization")
|
|
compilerApi project(":compiler:ir.psi2ir")
|
|
compilerApi project(":kotlin-native-shared")
|
|
use(IntellijDependenciesKt) {
|
|
compilerApi(intellijCore())
|
|
compileOnly(jpsModel())
|
|
}
|
|
|
|
cli_bcApi sourceSets.compiler.output
|
|
|
|
cli_bcApiElements sourceSets.cli_bc.output
|
|
}
|
|
|
|
|
|
classes.dependsOn 'compilerClasses', 'cli_bcClasses'
|
|
|
|
tasks.named("jar") {
|
|
from sourceSets.cli_bc.output,
|
|
sourceSets.compiler.output,
|
|
sourceSets.filesInteropStubs.output,
|
|
sourceSets.envInteropStubs.output,
|
|
sourceSets.llvmInteropStubs.output
|
|
|
|
dependsOn 'external_jars'
|
|
}
|
|
|
|
def externalJars = ['compiler', 'stdlib', 'reflect', 'script_runtime']
|
|
|
|
tasks.register("trove4jCopy", Copy) {
|
|
from configurations.named("trove4j_jar") {
|
|
include "trove4j*.jar"
|
|
rename "trove4j(.*).jar", "trove4j.jar"
|
|
|
|
into 'build/external_jars'
|
|
}
|
|
}
|
|
|
|
externalJars.each { arg ->
|
|
def jar = arg.replace('_', '-') // :(
|
|
tasks.register("${arg}Copy", Copy) {
|
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
from configurations.named("kotlin_${arg}_jar") {
|
|
include "kotlin-${jar}*.jar"
|
|
rename "kotlin-${jar}(.*).jar", "kotlin-${jar}.jar"
|
|
|
|
into 'build/external_jars'
|
|
}
|
|
}
|
|
}
|
|
|
|
tasks.register("external_jars", Copy) {
|
|
dependsOn externalJars.collect { "${it}Copy" }
|
|
dependsOn trove4jCopy
|
|
}
|
|
|
|
tasks.register("debugCompiler", JavaExec) {
|
|
dependsOn ':dist'
|
|
mainClass = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
|
classpath = project.fileTree("${distDir.canonicalPath}/konan/lib/") {
|
|
include '*.jar'
|
|
}
|
|
jvmArgs "-Dorg.jetbrains.kotlin.native.home=${distDir.canonicalPath}"
|
|
enableAssertions = true
|
|
args = findProperty("konan.debug.args").toString().tokenize() ?: []
|
|
}
|
|
|
|
publishing {
|
|
repositories {
|
|
maven { url = "$buildDir/repo" }
|
|
}
|
|
|
|
publications {
|
|
maven(MavenPublication) {
|
|
groupId = 'org.jetbrains.kotlin'
|
|
artifactId = 'backend.native'
|
|
version = kotlinVersion
|
|
|
|
from components.java
|
|
}
|
|
}
|
|
}
|
|
|
|
RepoArtifacts.sourcesJar(project) {
|
|
it.from(sourceSets["cli_bc"].allSource)
|
|
it.from(sourceSets["compiler"].allSource)
|
|
}
|