Files
kotlin-fork/samples/html5Canvas/build.gradle
T
2018-12-07 17:40:18 +07:00

76 lines
2.3 KiB
Groovy

import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
import java.nio.file.Paths
plugins {
id 'kotlin-multiplatform'
}
repositories {
jcenter()
maven { url 'https://dl.bintray.com/kotlin/ktor' }
}
String packageName = 'kotlinx.interop.wasm.dom'
String jsinteropKlibFileName = Paths.get(buildDir.toString(), 'klib', "$packageName-jsinterop.klib").toString()
kotlin {
targets {
fromPreset(presets.wasm32, 'html5Canvas') {
compilations.main.outputKinds 'EXECUTABLE'
compilations.main.entryPoint 'sample.html5canvas.main'
}
fromPreset(presets.jvm, 'httpServer')
}
sourceSets {
html5CanvasMain {
dependencies {
implementation files(jsinteropKlibFileName)
}
}
httpServerMain {
dependencies {
implementation 'io.ktor:ktor-server-netty:1.0.0'
}
}
}
}
task jsinterop(type: Exec) {
workingDir projectDir
def ext = MPPTools.isWindows() ? '.bat' : ''
def distributionPath = project.properties['org.jetbrains.kotlin.native.home'] as String
if (distributionPath != null) {
commandLine Paths.get(file(distributionPath).path, 'bin', "jsinterop$ext").toString(),
'-pkg', packageName,
'-o', jsinteropKlibFileName,
'-target', 'wasm32'
} else {
doFirst {
// Abort build execution if the distribution path isn't specified.
throw new GradleException("""\
|Kotlin/Native distribution path must be specified to build the JavaScript interop.
|Use 'org.jetbrains.kotlin.native.home' project property to specify it.
""".stripMargin())
}
}
}
tasks.withType(KotlinNativeCompile).all {
dependsOn jsinterop
}
// This is to run embedded HTTP server with Ktor:
task runProgram(type: JavaExec) {
dependsOn assemble
main = 'sample.html5canvas.httpserver.HttpServer'
classpath = files(kotlin.targets.httpServer.compilations.main.output) + kotlin.targets.httpServer.compilations.main.runtimeDependencyFiles
args projectDir
}
tasks.withType(KotlinJvmCompile).all {
runProgram.dependsOn it
kotlinOptions.jvmTarget = '1.8'
}