df02804be1
Moved to util-io and util-klib for klib code commonization Moved the common writer to Kotlin workspace
293 lines
9.1 KiB
Groovy
293 lines
9.1 KiB
Groovy
import org.jetbrains.kotlin.CopyCommonSources
|
|
import org.jetbrains.kotlin.konan.target.HostManager
|
|
|
|
/*
|
|
* Copyright 2010-2018 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.
|
|
*/
|
|
buildscript {
|
|
apply from: "$rootDir/gradle/kotlinGradlePlugin.gradle"
|
|
apply plugin: 'project-report'
|
|
|
|
dependencies {
|
|
classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.8"
|
|
}
|
|
}
|
|
|
|
String protobufVersion = '2.6.1'
|
|
apply plugin: "com.google.protobuf"
|
|
apply plugin: 'java'
|
|
apply plugin: 'kotlin'
|
|
apply plugin: org.jetbrains.kotlin.NativeInteropPlugin
|
|
|
|
// (gets applied to this project and all its subprojects)
|
|
allprojects {
|
|
repositories {
|
|
maven { url buildKotlinCompilerRepo }
|
|
}
|
|
}
|
|
|
|
sourceSets {
|
|
compiler {
|
|
proto.srcDir 'compiler/ir/backend.native/src/'
|
|
java {
|
|
srcDir 'compiler/ir/backend.native/src/'
|
|
srcDir 'build/renamed/source/proto/compiler/java'
|
|
}
|
|
kotlin {
|
|
srcDir 'compiler/ir/backend.native/src/'
|
|
}
|
|
resources.srcDir 'compiler/ir/backend.native/resources/'
|
|
}
|
|
cli_bc {
|
|
java.srcDir 'cli.bc/src'
|
|
kotlin.srcDir 'cli.bc/src'
|
|
}
|
|
bc_frontend {
|
|
java.srcDir 'bc.frontend/src'
|
|
kotlin.srcDir 'bc.frontend/src'
|
|
}
|
|
}
|
|
|
|
compileCompilerKotlin {
|
|
dependsOn('renamePackage')
|
|
// The protobuf plugin specifies this dependency for java by itself,
|
|
// but not for Kotlin.
|
|
dependsOn('generateCompilerProto')
|
|
kotlinOptions.jvmTarget = "1.8"
|
|
}
|
|
|
|
compileCompilerJava {
|
|
dependsOn('renamePackage')
|
|
}
|
|
|
|
task copyGenerated(type: Copy) {
|
|
dependsOn('generateCompilerProto')
|
|
from 'build/generated/source/proto/compiler/java'
|
|
into 'build/renamed/source/proto/compiler/java'
|
|
filter { line -> line.replaceAll("com.google.protobuf", "org.jetbrains.kotlin.protobuf") }
|
|
outputs.dir('build/renamed')
|
|
}
|
|
|
|
task deleteGenerated(type: Delete) {
|
|
dependsOn('copyGenerated')
|
|
delete 'build/generated'
|
|
}
|
|
|
|
task renamePackage {
|
|
dependsOn('copyGenerated', 'deleteGenerated')
|
|
}
|
|
|
|
kotlinNativeInterop {
|
|
llvm {
|
|
dependsOn ":llvmDebugInfoC:debugInfoStaticLibrary"
|
|
dependsOn ":llvmCoverageMappingC:coverageMappingStaticLibrary"
|
|
defFile 'llvm.def'
|
|
if (!project.parent.convention.plugins.platformInfo.isWindows())
|
|
compilerOpts "-fPIC"
|
|
compilerOpts "-I$llvmDir/include", "-I${project(':llvmDebugInfoC').projectDir}/src/main/include", "-I${project(':llvmCoverageMappingC').projectDir}/src/main/include"
|
|
linkerOpts "-L$llvmDir/lib", "-L${project(':llvmDebugInfoC').buildDir}/libs/debugInfo/static", "-L${project(':llvmCoverageMappingC').buildDir}/libs/coverageMapping/static"
|
|
}
|
|
|
|
hash { // TODO: copy-pasted from ':common:compileHash'
|
|
if (!project.parent.convention.plugins.platformInfo.isWindows()) {
|
|
compilerOpts '-fPIC'
|
|
linkerOpts '-fPIC'
|
|
}
|
|
linker 'clang++'
|
|
linkOutputs ":common:${hostName}Hash"
|
|
|
|
headers fileTree('../common/src/hash/headers') {
|
|
include '**/*.h'
|
|
include '**/*.hpp'
|
|
}
|
|
|
|
pkg 'org.jetbrains.kotlin.backend.konan.hash'
|
|
}
|
|
}
|
|
|
|
|
|
configurations {
|
|
kotlin_compiler_jar
|
|
kotlin_stdlib_jar
|
|
kotlin_reflect_jar
|
|
kotlin_script_runtime_jar
|
|
kotlin_native_utils_jar
|
|
kotlin_util_io_jar
|
|
kotlin_util_klib_jar
|
|
trove4j_jar
|
|
kotlinCommonSources
|
|
|
|
cli_bcRuntime {
|
|
extendsFrom compilerRuntime
|
|
extendsFrom kotlin_script_runtime_jar
|
|
}
|
|
|
|
cli_bc {
|
|
extendsFrom cli_bcRuntime
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
trove4j_jar "org.jetbrains.intellij.deps:trove4j:1.0.20181211@jar"
|
|
kotlin_compiler_jar "$kotlinCompilerModule@jar"
|
|
kotlin_stdlib_jar "$kotlinStdLibModule@jar"
|
|
kotlin_reflect_jar "$kotlinReflectModule@jar"
|
|
kotlin_script_runtime_jar "$kotlinScriptRuntimeModule@jar"
|
|
kotlin_native_utils_jar "$kotlinNativeUtilsModule@jar"
|
|
kotlin_util_io_jar "$kotlinUtilIoModule@jar"
|
|
kotlin_util_klib_jar "$kotlinUtilKlibModule@jar"
|
|
|
|
[kotlinCommonStdlibModule, kotlinTestCommonModule, kotlinTestAnnotationsCommonModule].each {
|
|
kotlinCommonSources(it) { transitive = false }
|
|
}
|
|
|
|
compilerCompile "com.google.protobuf:protobuf-java:${protobufVersion}"
|
|
|
|
compilerCompile kotlinCompilerModule
|
|
compilerCompile kotlinNativeInterop['llvm'].configuration
|
|
compilerCompile kotlinNativeInterop['hash'].configuration
|
|
compilerCompile "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
|
|
compilerCompile "org.jetbrains.kotlin:konan.serializer:$konanVersion"
|
|
|
|
cli_bcCompile kotlinCompilerModule
|
|
cli_bcCompile "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
|
|
cli_bcCompile sourceSets.compiler.output
|
|
cli_bcCompile "org.jetbrains.kotlin:konan.serializer:$konanVersion"
|
|
|
|
bc_frontendCompile kotlinCompilerModule
|
|
|
|
cli_bc sourceSets.cli_bc.output
|
|
}
|
|
|
|
|
|
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.files
|
|
}
|
|
|
|
final List<File> stdLibSrc = [
|
|
project(':Interop:Runtime').file('src/main/kotlin'),
|
|
project(':Interop:Runtime').file('src/native/kotlin'),
|
|
project(':Interop:JsRuntime').file('src/main/kotlin'),
|
|
project(':runtime').file('src/main/kotlin'),
|
|
project(':runtime').file('src/launcher/kotlin')
|
|
]
|
|
|
|
// These files are built before the 'dist' is complete,
|
|
// so we provide custom values for
|
|
// konan.home, --runtime, -Djava.library.path etc
|
|
|
|
targetList.each { target ->
|
|
def konanJvmArgs = [*HostManager.regularJvmArgs,
|
|
"-Dkonan.home=${rootProject.projectDir}/dist",
|
|
"-Djava.library.path=${project.buildDir}/nativelibs/$hostName",
|
|
]
|
|
|
|
def defaultArgs = ['-nopack', '-nostdlib', '-nodefaultlibs']
|
|
if (target != "wasm32") defaultArgs += '-g'
|
|
def konanArgs = [*defaultArgs,
|
|
'-target', target,
|
|
"-Xruntime=${project(':runtime').file('build/' + target + '/runtime.bc')}",
|
|
*project.globalBuildArgs]
|
|
|
|
task("${target}Stdlib", type: JavaExec) {
|
|
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
|
classpath = project.configurations.cli_bc
|
|
jvmArgs = konanJvmArgs
|
|
args = [*konanArgs,
|
|
'-output', project(':runtime').file("build/${target}Stdlib"),
|
|
'-produce', 'library', '-module-name', 'stdlib', '-XXLanguage:+AllowContractsForCustomFunctions',
|
|
'-Xmulti-platform', '-Xuse-experimental=kotlin.Experimental', '-XXLanguage:+InlineClasses',
|
|
'-Xuse-experimental=kotlin.contracts.ExperimentalContracts',
|
|
'-Xuse-experimental=kotlin.ExperimentalMultiplatform',
|
|
'-Xallow-result-return-type',
|
|
commonSrc.absolutePath,
|
|
"-Xcommon-sources=${commonSrc.absolutePath}",
|
|
*stdLibSrc]
|
|
stdLibSrc.forEach { inputs.dir(it) }
|
|
inputs.dir(commonSrc)
|
|
outputs.dir(project(':runtime').file("build/${target}Stdlib"))
|
|
|
|
dependsOn 'unzipStdlibSources'
|
|
dependsOn ":runtime:${target}Runtime"
|
|
dependsOn ":distCompiler"
|
|
}
|
|
}
|
|
|
|
task run {
|
|
doLast {
|
|
logger.quiet("Run the outer project 'demo' target to compile the test source.")
|
|
}
|
|
}
|
|
|
|
jar {
|
|
from sourceSets.cli_bc.output,
|
|
sourceSets.compiler.output,
|
|
sourceSets.hashInteropStubs.output,
|
|
sourceSets.llvmInteropStubs.output
|
|
|
|
dependsOn ':runtime:hostRuntime', 'external_jars'
|
|
}
|
|
|
|
def externalJars = ['compiler', 'stdlib', 'reflect', 'script_runtime', 'native_utils', 'util_io', 'util_klib']
|
|
|
|
task trove4jCopy(type: Copy) {
|
|
from configurations.getByName("trove4j_jar") {
|
|
include "trove4j*.jar"
|
|
rename "trove4j(.*).jar", "trove4j.jar"
|
|
|
|
into 'build/external_jars'
|
|
}
|
|
}
|
|
|
|
externalJars.each { arg ->
|
|
def jar = arg.replace('_', '-') // :(
|
|
task("${arg}Copy", type: Copy) {
|
|
from configurations.getByName("kotlin_${arg}_jar") {
|
|
include "kotlin-${jar}*.jar"
|
|
rename "kotlin-${jar}(.*).jar", "kotlin-${jar}.jar"
|
|
|
|
into 'build/external_jars'
|
|
}
|
|
}
|
|
}
|
|
|
|
task external_jars(type: Copy) {
|
|
dependsOn externalJars.collect { "${it}Copy" }
|
|
dependsOn trove4jCopy
|
|
|
|
from configurations.compilerCompile {
|
|
|
|
include "protobuf-java-${protobufVersion}.jar"
|
|
|
|
into 'build/external_jars'
|
|
}
|
|
}
|
|
|
|
protobuf {
|
|
protoc {
|
|
artifact = "com.google.protobuf:protoc:${protobufVersion}"
|
|
}
|
|
}
|
|
|
|
task debugCompiler(type: JavaExec) {
|
|
dependsOn ':dist'
|
|
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
|
classpath = project.fileTree("${distDir.canonicalPath}/konan/lib/") {
|
|
include '*.jar'
|
|
}
|
|
jvmArgs "-Dorg.jetbrains.kotlin.native.home=${distDir.canonicalPath}",
|
|
"-Djava.library.path=${distDir.canonicalPath}/konan/nativelib"
|
|
enableAssertions = true
|
|
args = findProperty("konan.debug.args").toString().tokenize() ?: []
|
|
}
|