83 lines
2.5 KiB
Groovy
83 lines
2.5 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 {
|
|
targetFromPreset(presets.wasm32, 'html5Canvas') {
|
|
binaries {
|
|
executable() {
|
|
entryPoint = 'sample.html5canvas.main'
|
|
}
|
|
}
|
|
}
|
|
jvm('httpServer')
|
|
sourceSets {
|
|
html5CanvasMain {
|
|
dependencies {
|
|
implementation files(jsinteropKlibFileName)
|
|
}
|
|
}
|
|
httpServerMain {
|
|
dependencies {
|
|
implementation 'io.ktor:ktor-server-netty:1.2.1'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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) {
|
|
def jsinteropCommand = Paths.get(file(distributionPath).path, 'bin', "jsinterop$ext").toString()
|
|
|
|
inputs.property('jsinteropCommand', jsinteropCommand)
|
|
inputs.property('jsinteropPackageName', packageName)
|
|
outputs.file(jsinteropKlibFileName)
|
|
|
|
commandLine jsinteropCommand,
|
|
'-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'
|
|
}
|