forked from JetBrains/kotlin-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
265 lines (218 loc) · 8.23 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
* 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"
apply plugin: 'project-report'
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(kotlinStdLibModule)
substitute module('org.jetbrains.kotlin:kotlin-reflect') with module(kotlinReflectModule)
}
// 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'
if (!project.parent.convention.plugins.platformInfo.isWindows())
compilerOpts "-fPIC"
compilerOpts "-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'
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
cli_bcRuntime.extendsFrom compilerRuntime
cli_bc {
extendsFrom cli_bcRuntime
}
}
dependencies {
kotlin_compiler_jar "$kotlinCompilerModule@jar"
kotlin_stdlib_jar "$kotlinStdLibModule@jar"
kotlin_reflect_jar "$kotlinReflectModule@jar"
kotlin_script_runtime_jar "$kotlinScriptRuntimeModule@jar"
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:$buildKotlinVersion"
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=$distDir",
"-Djava.library.path=${project.buildDir}/nativelibs/$hostName",
"-Dfile.encoding=UTF-8"]
def defaultArgs = ['-nopack', '-nostdlib', '-nodefaultlibs', '-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', '-module_name', 'stdlib',
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 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']
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"}
from configurations.compilerCompile {
include "protobuf-java-${protobufVersion}.jar"
into 'build/external_jars'
}
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${protobufVersion}"
}
}