Move everything under kotlin-native folder

I was forced to manually do update the following files, because otherwise
they would be ignored according .gitignore settings. Probably they
should be deleted from repo.

Interop/.idea/compiler.xml
Interop/.idea/gradle.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml
Interop/.idea/modules.xml
Interop/.idea/modules/Indexer/Indexer.iml
Interop/.idea/modules/Runtime/Runtime.iml
Interop/.idea/modules/StubGenerator/StubGenerator.iml
backend.native/backend.native.iml
backend.native/bc.frontend/bc.frontend.iml
backend.native/cli.bc/cli.bc.iml
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt
backend.native/tests/link/lib/foo.kt
backend.native/tests/link/lib/foo2.kt
backend.native/tests/teamcity-test.property
This commit is contained in:
Stanislav Erokhin
2020-10-27 21:00:28 +03:00
parent 91e4162dad
commit f624800b84
2830 changed files with 0 additions and 0 deletions
@@ -0,0 +1,15 @@
# HTML5 Canvas
This sample shows how to use Kotlin/Native to build a WebAssembly application and how to call JavaScript functions
from a Kotlin/Native code.
> __Note__: If you build this sample not from the Kotlin/Native repository, you need to specify a path to a
Kotlin/Native distribution. Add the following snippet in `gradle.properties`:
>```
>kotlin.native.home=<path-to-distribution>
>```
> The default distribution path is `$HOME/.konan/kotlin-native-<macos|linux|windows>-<version>`.
To build use `../gradlew assemble`.
To run use `../gradlew runProgram`.
@@ -0,0 +1,97 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinNativeCompile
plugins {
kotlin("multiplatform")
}
repositories {
jcenter()
maven("https://dl.bintray.com/kotlin/ktor")
}
val hostOs = System.getProperty("os.name")
val isWindows = hostOs.startsWith("Windows")
val packageName = "kotlinx.interop.wasm.dom"
val jsinteropKlibFile = buildDir.resolve("klib").resolve("$packageName-jsinterop.klib")
kotlin {
wasm32("html5Canvas") {
binaries {
executable {
entryPoint = "sample.html5canvas.main"
}
}
}
jvm("httpServer")
sourceSets {
val html5CanvasMain by getting {
dependencies {
implementation(files(jsinteropKlibFile))
}
}
val httpServerMain by getting {
dependencies {
implementation("io.ktor:ktor-server-netty:1.2.1")
}
}
}
}
val jsinterop by tasks.creating(Exec::class) {
workingDir = projectDir
val ext = if (isWindows) ".bat" else ""
val distributionPath = project.properties["kotlin.native.home"] as String?
if (distributionPath != null) {
val jsinteropCommand = file(distributionPath).resolve("bin").resolve("jsinterop$ext")
inputs.property("jsinteropCommand", jsinteropCommand)
inputs.property("jsinteropPackageName", packageName)
outputs.file(jsinteropKlibFile)
commandLine(
jsinteropCommand,
"-pkg", packageName,
"-o", jsinteropKlibFile,
"-target", "wasm32"
)
} else {
doFirst {
// Abort build execution if the distribution path isn't specified.
throw GradleException(
"""
|
|Kotlin/Native distribution path must be specified to build the JavaScript interop.
|Use 'kotlin.native.home' project property to specify it.
""".trimMargin()
)
}
}
}
tasks.withType(AbstractKotlinNativeCompile::class).all {
dependsOn(jsinterop)
}
val assemble by tasks.getting
// This is to run embedded HTTP server with Ktor:
val runProgram by tasks.creating(JavaExec::class) {
dependsOn(assemble)
val httpServer: KotlinJvmTarget by kotlin.targets
val httpServerMainCompilation = httpServer.compilations["main"]
main = "sample.html5canvas.httpserver.HttpServer"
classpath = files(httpServerMainCompilation.output) + httpServerMainCompilation.runtimeDependencyFiles
args = listOf(projectDir.toString())
}
tasks.withType(KotlinJvmCompile::class).all {
runProgram.dependsOn(this)
kotlinOptions.jvmTarget = "1.8"
}
@@ -0,0 +1,2 @@
kotlin.code.style=official
kotlin.import.noCommonSourceSets=true
@@ -0,0 +1,14 @@
<html>
<head>
<meta charset="utf-8">
<script src="build/bin/html5Canvas/releaseExecutable/html5Canvas.wasm.js" wasm="build/bin/html5Canvas/releaseExecutable/html5Canvas.wasm"> </script>
</head>
<body>
<canvas id="myCanvas" width="640" height="480" style="border:1px solid #000000;">
</canvas>
<p>Draw something using the mouse!</p>
</body>
</html>
@@ -0,0 +1,53 @@
/*
* 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/LICENSE.txt file.
*/
package sample.html5canvas
import kotlinx.interop.wasm.dom.*
import kotlinx.wasm.jsinterop.*
fun main() {
val canvas = document.getElementById("myCanvas").asCanvas
val ctx = canvas.getContext("2d")
val rect = canvas.getBoundingClientRect()
val rectLeft = rect.left
val rectTop = rect.top
var mouseX: Int = 0
var mouseY: Int = 0
var draw: Boolean = false
document.setter("onmousemove") { arguments: ArrayList<JsValue> ->
val event = MouseEvent(arguments[0])
mouseX = event.getInt("clientX") - rectLeft
mouseY = event.getInt("clientY") - rectTop
if (mouseX < 0) mouseX = 0
if (mouseX > 639) mouseX = 639
if (mouseY < 0) mouseY = 0
if (mouseY > 479) mouseY = 479
}
document.setter("onmousedown") {
draw = true
}
document.setter("onmouseup") {
draw = false
}
setInterval(10) {
if (draw) {
ctx.strokeStyle = "#222222"
ctx.lineTo(mouseX, mouseY)
ctx.stroke()
} else {
ctx.moveTo(mouseX, mouseY)
ctx.stroke()
}
}
}
@@ -0,0 +1,59 @@
/*
* 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/LICENSE.txt file.
*/
@file:JvmName("HttpServer")
package sample.html5canvas.httpserver
import io.ktor.application.call
import io.ktor.http.ContentType
import io.ktor.http.content.LocalFileContent
import io.ktor.http.content.default
import io.ktor.http.content.files
import io.ktor.http.content.static
import io.ktor.response.respond
import io.ktor.routing.get
import io.ktor.routing.routing
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import java.io.File
fun main(args: Array<String>) {
check(args.size == 1) { "Invalid number of arguments: $args.\nExpected one argument with content root." }
val contentRoot = File(args[0])
check(contentRoot.isDirectory) { "Invalid content root: $contentRoot." }
println(
"""
IMPORTANT: Please open http://localhost:8080/ in your browser!
To stop embedded HTTP server use Ctrl+C (Cmd+C for Mac OS X).
""".trimIndent()
)
val server = embeddedServer(Netty, 8080) {
routing {
val wasm = "build/bin/html5Canvas/releaseExecutable/html5Canvas.wasm"
get(wasm) {
// TODO: ktor as of now doesn't know about 'application/wasm'.
// The newer browsers (firefox and chrome at least) don't allow
// 'application/octet-stream' for wasm anymore.
// We provide the proper content type here and,
// at the same time, put it into the ktor database.
// Remove this whole get() clause when ktor fix is available.
call.respond(LocalFileContent(File(wasm), ContentType("application", "wasm")))
}
static("/") {
files(contentRoot)
default("index.html")
}
}
}
server.start(wait = true)
}