Files
kotlin-fork/backend.native/build.gradle
T
Svyatoslav Scherbina bee2a76008 build: refactor platform checks
also improve verbosity when downloading dependencies fails
2016-11-11 19:22:34 +07:00

201 lines
5.4 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"
}
}
apply plugin: "com.google.protobuf"
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: org.jetbrains.kotlin.NativeInteropPlugin
String kotlinCompilerModule = 'org.jetbrains.kotlin:kotlin-compiler:1.1-20161108.133759-248'
// (gets applied to this project and all its subprojects)
allprojects {
repositories {
mavenCentral()
maven {
url 'http://oss.sonatype.org/content/repositories/snapshots'
}
}
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.srcDirs 'compiler/ir/backend.native/src/', 'build/generated/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'
}
}
// The protobuf plugin specifies this dependency for java by itself,
// but not for Kotlin.
compileCompilerKotlin {
dependsOn('generateCompilerProto')
}
String[] linkerOpts1() {
def 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']
List<String> ldflags = new ArrayList<>()
if (isLinux())
ldflags.addAll(["-L$llvmDir/lib",
"-Wl,-Bstatic", "-Wl,--whole-archive"]
+ libs
+ ["-Wl,--no-whole-archive", "-Wl,-Bdynamic",
"-L$libffiDir/lib -lffi",
"-lrt", "-ldl","-lpthread", "-lz", "-lm"])
else
ldflags.addAll(["-L$llvmDir/lib", "-lc++"]
+ libs
+ ["-L$libffiDir/lib", "-lffi"])
ArrayList<String> strldflags = new ArrayList<>()
ldflags.forEach{strldflags.add(it.toString())}
return strldflags.toArray(new String[0])
}
kotlinNativeInterop {
llvm {
defFile 'llvm.def'
compilerOpts "-fPIC", "-I$llvmDir/include"
linkerOpts linkerOpts1()
}
hash { // TODO: copy-pasted from ':common:compileHash'
compilerOpts '-fPIC'
linkerOpts '-fPIC'
linker 'clang++'
linkOutputs ':common:compileHash'
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:3.0.0"
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'
task run(type: JavaExec) {
main 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
classpath configurations.cli_bc
args 'tests/codegen/function/sum.kt'
args '-headers', project(':runtime').file('src/main/kotlin')
args '-output', "$buildDir/out.bc"
jvmArgs '-ea', "-Djava.library.path=${project.buildDir}/nativelibs"
dependsOn ':runtime:build'
doFirst {
args '-runtime', project(':runtime').build.outputs.files.singleFile
}
environment 'LD_LIBRARY_PATH' : "${llvmDir}/lib:${project.buildDir}/nativelibs"
}
task jars {
doFirst {
project.buildscript.configurations.classpath.each {
String jarName = it.getName();
print jarName + ":"
}
}
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0'
}
}