/* * 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. */ buildscript { apply from: "$rootDir/gradle/kotlinGradlePlugin.gradle" repositories { mavenCentral() } dependencies { 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 // (gets applied to this project and all its subprojects) allprojects { repositories { maven { url kotlinCompilerRepo } } 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/' } 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') } 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') } kotlinNativeInterop { llvm { dependsOn ":llvmDebugInfoC:debugInfoStaticLibrary" defFile 'llvm.def' compilerOpts "-fPIC", "-I$llvmDir/include", "-I${project(':llvmDebugInfoC').projectDir}/src/main/include" linkerOpts "-L$llvmDir/lib", "-L${project(':llvmDebugInfoC').buildDir}/libs/debugInfo/static" } hash { // TODO: copy-pasted from ':common:compileHash' 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 { 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 compilerCompile project(':shared') cli_bcCompile "org.jetbrains.kotlin:kotlin-runtime:$kotlin_version" cli_bcCompile project(':shared') cli_bcCompile sourceSets.compiler.output 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") task start(dependsOn: "${hostName}Start") // 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 -> def konanJvmArgs = ["-ea", "-Dkonan.home=${project.parent.file('dist')}", "-Djava.library.path=${project.buildDir}/nativelibs", "-Dfile.encoding=UTF-8"] def defaultArgs = ['-nopack', '-nostdlib','-ea' ] if (target != "wasm32") defaultArgs += '-g' def konanArgs = [*defaultArgs, '-target', target, '-runtime', project(':runtime').file("build/${target}/runtime.bc"), '-properties', rootProject.konanPropertiesFile.canonicalPath, *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', project(':Interop:Runtime').file('src/main/kotlin'), project(':Interop:Runtime').file('src/native/kotlin'), project(':runtime').file('src/main/kotlin')] 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")) dependsOn ":runtime:${target}Runtime" } task("${target}Start", type: JavaExec) { main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt' classpath = project.configurations.cli_bc jvmArgs = konanJvmArgs args = [*konanArgs, '-produce', 'bitcode', '-output', project(':runtime').file("build/${target}Start"), '-library', project(':runtime').file("build/${target}Stdlib"), project(':runtime').file('src/launcher/kotlin')] inputs.dir(project(':runtime').file('src/launcher/kotlin')) outputs.file(project(':runtime').file("build/${target}Start")) dependsOn ":runtime:${target}Runtime", "${target}Stdlib" } } task run { doLast { logger.quiet("Run the outer project 'demo' target to compile the test source." ) } } jar { from 'build/classes/cli_bc', 'build/classes/compiler', 'build/classes/hashInteropStubs', 'build/classes/llvmInteropStubs', 'build/resources/compiler' dependsOn ':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}" } }