This repository has been archived by the owner on Aug 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 569
/
build.gradle
338 lines (275 loc) · 10.3 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
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
apply plugin: "maven-publish"
// (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'
}
}
compileCli_bcKotlin {
kotlinOptions.freeCompilerArgs += "-Xskip-prerelease-check"
}
compileCompilerKotlin {
dependsOn('renamePackage')
// The protobuf plugin specifies this dependency for java by itself,
// but not for Kotlin.
dependsOn('generateCompilerProto')
kotlinOptions.jvmTarget = "1.8"
// Setting jvmTarget using DSL (above) doesn't seem to work.
// This is _likely_ caused by using different versions of compiler (before changing the default JVM target)
// and Gradle plugin (after chaging).
// Workaround (to be removed soon):
kotlinOptions.freeCompilerArgs += ["-jvm-target", "1.8"]
// kotlinOptions.allWarningsAsErrors=true
kotlinOptions.freeCompilerArgs += ['-Xopt-in=kotlin.RequiresOptIn', '-Xopt-in=org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI']
kotlinOptions.freeCompilerArgs += "-Xskip-prerelease-check"
}
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/source/proto/compiler/java'
}
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'
}
files {
if (!project.parent.convention.plugins.platformInfo.isWindows()) {
compilerOpts '-fPIC'
linkerOpts '-fPIC'
}
linker 'clang++'
linkOutputs ":common:${hostName}Files"
headers fileTree('../common/src/files/headers') {
include '**/*.h'
include '**/*.hpp'
}
pkg 'org.jetbrains.kotlin.backend.konan.files'
}
}
configurations {
kotlin_compiler_jar
kotlin_stdlib_jar
kotlin_reflect_jar
kotlin_script_runtime_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"
[kotlinCommonStdlibModule, kotlinTestCommonModule, kotlinTestAnnotationsCommonModule].each {
kotlinCommonSources(it) { transitive = false }
}
compilerCompile project(":utilities:basic-utils")
compilerCompile "com.google.protobuf:protobuf-java:${protobufVersion}"
compilerCompile kotlinCompilerModule
compilerCompile kotlinNativeInterop['llvm'].configuration
compilerCompile kotlinNativeInterop['hash'].configuration
compilerCompile kotlinNativeInterop['files'].configuration
compilerCompile "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
cli_bcCompile kotlinCompilerModule
cli_bcCompile "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
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")
def commonSrc = file('build/stdlib')
task unzipStdlibSources(type: CopyCommonSources) {
outputDir commonSrc
sourcePaths configurations.kotlinCommonSources
}
def interopRuntimeCommonSrc = project(':Interop:Runtime').file('src/main/kotlin')
final List<File> stdLibSrc = [
interopRuntimeCommonSrc,
project(':Interop:Runtime').file('src/native/kotlin'),
project(':Interop:JsRuntime').file('src/main/kotlin'),
project(':runtime').file('src/main/kotlin')
]
// These files are built before the 'dist' is complete,
// so we provide a custom value for --runtime
targetList.each { target ->
def konanJvmArgs = [*HostManager.regularJvmArgs]
def defaultArgs = ['-nopack', '-nostdlib', '-no-default-libs', '-no-endorsed-libs',
//Uncomment this '-Werror' when common stdlib will be ready
]
if (target != "wasm32") defaultArgs += '-g'
def konanArgs = [*defaultArgs,
'-target', target,
"-Xruntime=${project(':runtime').file('build/bitcode/main/' + target + '/runtime.bc')}",
*project.globalBuildArgs]
task("${target}Stdlib", type: JavaExec) {
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
// This task depends on distCompiler, so the compiler jar is already in the dist directory.
classpath = fileTree("${rootProject.projectDir}/dist/konan/lib") {
include "*.jar"
}
jvmArgs = konanJvmArgs
args = [*konanArgs,
'-output', project(':runtime').file("build/${target}Stdlib"),
'-produce', 'library', '-module-name', 'stdlib', '-XXLanguage:+AllowContractsForCustomFunctions',
'-Xmulti-platform', '-Xopt-in=kotlin.RequiresOptIn', '-Xinline-classes',
'-Xopt-in=kotlin.contracts.ExperimentalContracts',
'-Xopt-in=kotlin.ExperimentalMultiplatform',
'-Xallow-result-return-type',
commonSrc.absolutePath,
"-Xcommon-sources=${commonSrc.absolutePath}",
"-Xcommon-sources=$interopRuntimeCommonSrc",
*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.filesInteropStubs.output,
sourceSets.llvmInteropStubs.output
dependsOn ':runtime:hostRuntime', 'external_jars'
}
def externalJars = ['compiler', 'stdlib', 'reflect', 'script_runtime']
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}"
enableAssertions = true
args = findProperty("konan.debug.args").toString().tokenize() ?: []
}
publishing {
repositories {
maven { url = "$buildDir/repo" }
}
publications {
maven(MavenPublication) {
groupId = 'org.jetbrains.kotlin'
artifactId = 'backend.native'
version = konanVersionFull
from components.java
}
}
}