forked from JetBrains/kotlin-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
106 lines (88 loc) · 4.1 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
/*
* Copyright 2010-2019 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.
*/
import org.jetbrains.kotlin.CompileToBitcode
import org.jetbrains.kotlin.CompilationDatabaseKt
import org.jetbrains.kotlin.UtilsKt
// TODO: consider using some Gradle plugins to build and test
void includeRuntime(CompileToBitcode task) {
task.compilerArgs.add('-I' + project.file('../common/src/hash/headers'))
task.compilerArgs.add('-I' + project.file('src/main/cpp'))
}
targetList.each { targetName ->
tasks.create("${targetName}Runtime", CompileToBitcode, file('src/main'), "runtime", targetName).configure {
dependsOn ":common:${targetName}Hash"
dependsOn "${targetName}StdAlloc"
dependsOn "${targetName}OptAlloc"
dependsOn "${targetName}Mimalloc"
dependsOn "${targetName}Launcher"
dependsOn "${targetName}Debug"
dependsOn "${targetName}Release"
dependsOn "${targetName}Strict"
dependsOn "${targetName}Relaxed"
dependsOn "${targetName}ProfileRuntime"
dependsOn "${targetName}ObjC"
dependsOn "${targetName}ExceptionsSupport"
includeRuntime(delegate)
linkerArgs.add(project.file("../common/build/$targetName/hash.bc").path)
}
tasks.create("${targetName}Mimalloc", CompileToBitcode, file('src/mimalloc'), "mimalloc", targetName).configure {
language = CompileToBitcode.Language.C
excludeFiles.addAll(["**/alloc-override*.c", "**/page-queue.c", "**/static.c"])
if (!UtilsKt.targetSupportsMimallocAllocator(targetName))
excludedTargets.add(targetName)
srcDir = new File(srcRoot, "c")
compilerArgs.add("-DKONAN_MI_MALLOC=1")
headersDir = new File(srcDir, "include")
}
tasks.create("${targetName}Launcher", CompileToBitcode, file('src/launcher'), "launcher", targetName).configure {
includeRuntime(delegate)
}
tasks.create("${targetName}Debug", CompileToBitcode, file('src/debug'), "debug", targetName).configure {
includeRuntime(delegate)
}
tasks.create("${targetName}StdAlloc", CompileToBitcode, file('src/std_alloc'), "std_alloc", targetName)
tasks.create("${targetName}OptAlloc", CompileToBitcode, file('src/opt_alloc'), "opt_alloc", targetName)
tasks.create("${targetName}ExceptionsSupport", CompileToBitcode, file('src/exceptions_support'),
"exceptionsSupport", targetName).configure {
includeRuntime(delegate)
}
tasks.create("${targetName}Release", CompileToBitcode, file('src/release'), "release", targetName).configure {
includeRuntime(delegate)
}
tasks.create("${targetName}Strict", CompileToBitcode, file('src/strict'), "strict", targetName).configure {
includeRuntime(delegate)
}
tasks.create("${targetName}Relaxed", CompileToBitcode, file('src/relaxed'), "relaxed", targetName).configure {
includeRuntime(delegate)
}
tasks.create("${targetName}ProfileRuntime", CompileToBitcode, file('src/profile_runtime'),
"profileRuntime", targetName)
tasks.create("${targetName}ObjC", CompileToBitcode, file('src/objc'), "objc", targetName).configure {
includeRuntime(delegate)
}
}
CompilationDatabaseKt.createCompilationDatabasesFromCompileToBitcodeTasks(project, "CompilationDatabase")
task hostRuntime(dependsOn: "${hostName}Runtime")
task clean {
doLast {
delete buildDir
}
}
task generateJsMath {
dependsOn ':distCompiler'
doLast {
def jsinteropScript = isWindows() ? "jsinterop.bat" : "jsinterop"
def jsinterop = "$distDir/bin/$jsinteropScript"
def targetDir = "$buildDir/generated"
"$jsinterop -pkg kotlinx.interop.wasm.math -o $targetDir/math -target wasm32".execute().waitFor()
def generated = file("$targetDir/math-build/natives/js_stubs.js")
def mathJs = file('src/main/js/math.js')
mathJs.write("// NOTE: THIS FILE IS AUTO-GENERATED!\n" +
"// Run ':runtime:generateJsMath' to re-generate it.\n\n")
generated.withReader {
mathJs.append(it)
}
}
}