Files
kotlin-fork/runtime/build.gradle
T
2018-03-01 17:02:37 +03:00

80 lines
2.6 KiB
Groovy

/*
* 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.
*/
import org.jetbrains.kotlin.CompileCppToBitcode
// TODO: consider using some Gradle plugins to build and test
targetList.each { targetName ->
task("${targetName}Runtime", type: CompileCppToBitcode) {
name "runtime"
srcRoot file('src/main')
dependsOn ":common:${targetName}Hash"
dependsOn "${targetName}Launcher"
target targetName
if (!isWindows())
compilerArgs '-fPIC'
compilerArgs '-I' + project.file('../common/src/hash/headers')
if (rootProject.hasProperty("${targetName}LibffiDir"))
compilerArgs '-I' + project.file(rootProject.ext.get("${targetName}LibffiDir") + "/include")
linkerArgs project.file("../common/build/$targetName/hash.bc").path
}
}
targetList.each { targetName ->
task("${targetName}Launcher", type: CompileCppToBitcode) {
name "launcher"
srcRoot file('src/launcher')
target targetName
compilerArgs '-I' + project.file('../common/src/hash/headers')
compilerArgs '-I' + project.file('src/main/cpp')
}
}
task hostRuntime(dependsOn: "${hostName}Runtime")
task clean {
doLast {
delete buildDir
}
}
task generateJsMath {
dependsOn ':dist'
doLast {
def jsinteropScript = isWindows() ? "jsinterop.bat" : "jsinterop"
def jsinterop = "$distDir/bin/$jsinteropScript"
def targetDir = "$buildDir/generated"
def firstLine = true
"$jsinterop -pkg kotlinx.interop.wasm.math -o $targetDir/math -target wasm32".execute().waitFor()
copy {
from("$targetDir/math-build/natives/js_stubs.js")
into('src/main/js')
rename { "math.js" }
filter { line ->
if (firstLine) {
firstLine = false
return "// NOTE: THIS FILE IS AUTO-GENERATED!\n" +
"// Run ':runtime:generateJsMath' to re-generate it.\n\n" +
"$line"
} else {
return line
}
}
}
}
}