292 lines
8.7 KiB
Groovy
292 lines
8.7 KiB
Groovy
buildscript {
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
|
|
dependencies {
|
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.0"
|
|
}
|
|
|
|
}
|
|
|
|
String protobufVersion = '2.6.1'
|
|
apply plugin: "com.google.protobuf"
|
|
apply plugin: 'java'
|
|
apply plugin: 'kotlin'
|
|
apply plugin: org.jetbrains.kotlin.NativeInteropPlugin
|
|
|
|
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
|
|
// (gets applied to this project and all its subprojects)
|
|
allprojects {
|
|
repositories {
|
|
maven {
|
|
url 'http://oss.sonatype.org/content/repositories/snapshots'
|
|
//url 'http://dl.bintray.com/kotlin/kotlin-dev'
|
|
}
|
|
}
|
|
|
|
configurations.all {
|
|
// kotlin-compiler module includes Kotlin runtime bundled;
|
|
// make Gradle aware of this to avoid multiple Kotlin runtimes in classpath:
|
|
resolutionStrategy.dependencySubstitution {
|
|
substitute module('org.jetbrains.kotlin:kotlin-runtime') with module(kotlinCompilerModule)
|
|
substitute module('org.jetbrains.kotlin:kotlin-stdlib') with module(kotlinCompilerModule)
|
|
substitute module('org.jetbrains.kotlin:kotlin-reflect') with module(kotlinCompilerModule)
|
|
}
|
|
// TODO: probably we should use kotlin-compiler without bundled runtime
|
|
}
|
|
}
|
|
|
|
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/'
|
|
}
|
|
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')
|
|
}
|
|
|
|
compileCompilerJava {
|
|
doFirst {
|
|
delete 'build/generated'
|
|
}
|
|
dependsOn('renamePackage')
|
|
}
|
|
|
|
task renamePackage(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.files('build/renamed')
|
|
}
|
|
|
|
List<String> llvmLinkerOpts() {
|
|
// TODO: cannot use llvm-config because it can be inaccessible during project configuration
|
|
final List<String> libs = [
|
|
'-lLLVMX86Disassembler',
|
|
'-lLLVMX86AsmParser',
|
|
'-lLLVMX86CodeGen',
|
|
'-lLLVMSelectionDAG',
|
|
'-lLLVMAsmPrinter',
|
|
'-lLLVMX86Desc',
|
|
'-lLLVMMCDisassembler',
|
|
'-lLLVMX86Info',
|
|
'-lLLVMX86AsmPrinter',
|
|
'-lLLVMX86Utils',
|
|
'-lLLVMInterpreter',
|
|
'-lLLVMCodeGen',
|
|
'-lLLVMScalarOpts',
|
|
'-lLLVMInstCombine',
|
|
'-lLLVMInstrumentation',
|
|
'-lLLVMProfileData',
|
|
'-lLLVMTransformUtils',
|
|
'-lLLVMBitWriter',
|
|
'-lLLVMExecutionEngine',
|
|
'-lLLVMTarget',
|
|
'-lLLVMAnalysis',
|
|
'-lLLVMRuntimeDyld',
|
|
'-lLLVMObject',
|
|
'-lLLVMMCParser',
|
|
'-lLLVMBitReader',
|
|
'-lLLVMMC',
|
|
'-lLLVMCore',
|
|
'-lLLVMSupport',
|
|
'-lLLVMDebugInfoCodeView',
|
|
'-lLLVMLinker',
|
|
"-ldebugInfo"
|
|
]
|
|
|
|
final List<String> res = ["-L$llvmDir/lib", "-L${project(':llvmDebugInfoC').buildDir}/libs/debugInfo/static"]
|
|
|
|
if (isLinux()) {
|
|
res.addAll(["-Wl,-Bstatic", "-Wl,--whole-archive"]
|
|
+ libs
|
|
+ ["-Wl,--no-whole-archive", "-Wl,-Bdynamic"])
|
|
} else {
|
|
res.addAll(libs)
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
|
|
kotlinNativeInterop {
|
|
llvm {
|
|
dependsOn ":llvmDebugInfoC:debugInfoStaticLibrary"
|
|
defFile 'llvm.def'
|
|
compilerOpts "-fPIC", "-I$llvmDir/include", "-I${project(':llvmDebugInfoC').projectDir}/src/main/include"
|
|
linkerOpts llvmLinkerOpts()
|
|
}
|
|
|
|
hash { // TODO: copy-pasted from ':common:compileHash'
|
|
compilerOpts '-fPIC'
|
|
linkerOpts '-fPIC'
|
|
linker 'clang++'
|
|
linkOutputs ':common:hostHash'
|
|
|
|
headers fileTree('../common/src/hash/headers') {
|
|
include '**/*.h'
|
|
include '**/*.hpp'
|
|
}
|
|
|
|
pkg 'org.jetbrains.kotlin.backend.konan.hash'
|
|
}
|
|
}
|
|
|
|
|
|
configurations {
|
|
cli_bcRuntime.extendsFrom compilerRuntime
|
|
|
|
cli_bc {
|
|
extendsFrom cli_bcRuntime
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
|
|
compilerCompile "com.google.protobuf:protobuf-java:${protobufVersion}"
|
|
|
|
compilerCompile kotlinCompilerModule
|
|
compilerCompile kotlinNativeInterop['llvm'].configuration
|
|
compilerCompile kotlinNativeInterop['hash'].configuration
|
|
|
|
cli_bcCompile "org.jetbrains.kotlin:kotlin-runtime:$kotlin_version"
|
|
cli_bcCompile sourceSets.compiler.output
|
|
|
|
bc_frontendCompile kotlinCompilerModule
|
|
|
|
cli_bc sourceSets.cli_bc.output
|
|
}
|
|
|
|
|
|
build.dependsOn 'compilerClasses','cli_bcClasses','bc_frontendClasses'
|
|
|
|
|
|
// These are just a couple of aliases
|
|
task stdlib(dependsOn: 'hostStdlib')
|
|
task start(dependsOn: 'hostStart')
|
|
|
|
// These files are built before the 'dist' is complete,
|
|
// so we provide custom values for
|
|
// -runtime, -properties, -library and -Djava.library.path
|
|
|
|
targetList.each { target ->
|
|
task("${target}Stdlib", type: JavaExec) {
|
|
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
|
classpath = project.configurations.cli_bc
|
|
jvmArgs "-ea",
|
|
"-Dkonan.home=${project.parent.file('dist')}",
|
|
"-Djava.library.path=${project.buildDir}/nativelibs"
|
|
args('-output', project(':runtime').file("build/${target}/stdlib.kt.bc"),
|
|
'-nolink', '-nostdlib', '-ea',
|
|
'-target', target,
|
|
'-runtime', project(':runtime').file("build/${target}/runtime.bc"),
|
|
'-properties', project(':backend.native').file('konan.properties'),
|
|
project(':runtime').file('src/main/kotlin'),
|
|
project(':Interop:Runtime').file('src/main/kotlin'),
|
|
project(':Interop:Runtime').file('src/native/kotlin'),
|
|
*project.globalBuildArgs)
|
|
|
|
inputs.dir(project(':runtime').file('src/main/kotlin'))
|
|
inputs.dir(project(':Interop:Runtime').file('src/main/kotlin'))
|
|
inputs.dir(project(':Interop:Runtime').file('src/native/kotlin'))
|
|
outputs.file(project(':runtime').file("build/${target}/stdlib.kt.bc"))
|
|
|
|
dependsOn ":runtime:${target}Runtime"
|
|
}
|
|
}
|
|
|
|
targetList.each { target ->
|
|
task("${target}Start", type: JavaExec) {
|
|
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
|
classpath = project.configurations.cli_bc
|
|
jvmArgs "-ea",
|
|
"-Dkonan.home=${project.parent.file('dist')}",
|
|
"-Djava.library.path=${project.buildDir}/nativelibs"
|
|
args('-output', project(':runtime').file("build/${target}/start.kt.bc"),
|
|
'-nolink', '-nostdlib', '-ea',
|
|
'-target', target,
|
|
'-library', project(':runtime').file("build/${target}/stdlib.kt.bc"),
|
|
'-runtime', project(':runtime').file("build/${target}/runtime.bc"),
|
|
'-properties', project(':backend.native').file('konan.properties'),
|
|
project(':runtime').file('src/launcher/kotlin'),
|
|
*project.globalBuildArgs)
|
|
|
|
inputs.dir(project(':runtime').file('src/launcher/kotlin'))
|
|
outputs.file(project(':runtime').file("build/${target}/start.kt.bc"))
|
|
|
|
dependsOn ":runtime:${target}Runtime", "${target}Stdlib"
|
|
}
|
|
}
|
|
|
|
task run {
|
|
doLast {
|
|
logger.quiet("Run the outer project 'demo' target to compile the test source." )
|
|
}
|
|
}
|
|
|
|
task jars(type: Jar) {
|
|
from 'build/classes/cli_bc',
|
|
'build/classes/compiler',
|
|
'build/classes/hashInteropStubs',
|
|
'build/classes/llvmInteropStubs'
|
|
|
|
dependsOn 'build', ':runtime:hostRuntime', 'external_jars'
|
|
}
|
|
|
|
task external_jars(type: Copy) {
|
|
from configurations.compilerCompile {
|
|
|
|
include "protobuf-java-${protobufVersion}.jar"
|
|
|
|
include 'kotlin-compiler*.jar'
|
|
rename 'kotlin-compiler(.*).jar', 'kotlin-compiler.jar'
|
|
|
|
into 'build/external_jars'
|
|
}
|
|
}
|
|
|
|
protobuf {
|
|
protoc {
|
|
artifact = "com.google.protobuf:protoc:${protobufVersion}"
|
|
}
|
|
}
|
|
|
|
|