Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Kotlin/Native
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
stormcat24
October 19, 2017
Programming
1.1k
0
Share
Kotlin/Native
2017/10/19 CA.kt #3
stormcat24
October 19, 2017
More Decks by stormcat24
See All by stormcat24
素早く賢く失敗するDeveloper Productivityの実現を目指して
stormcat24
4
5.4k
KubernetesのマニフェストをそれなりにCIしたい
stormcat24
4
1.6k
令和時代のSaaS開発
stormcat24
1
350
History in 5 years of CircleCI and CyberAgent
stormcat24
3
910
Kubernetes Handson Osaka
stormcat24
5
640
Kubernetes Handson
stormcat24
5
4.5k
DockerとKubernetesでアプリケーション開発にコンテナをフル活用!
stormcat24
0
380
Base Image Journey 2018
stormcat24
30
140k
kotlin-fest
stormcat24
13
19k
Other Decks in Programming
See All in Programming
CSC307 Lecture 17
javiergs
PRO
0
230
Migrations : C'est une question d'hygiène !
vinceamstoutz
0
1.8k
Zod v4 Codec でスキーマに型変換を埋め込む REST API 設計 #TSKaigi2026
ryutaro_yako
0
140
Talking to terminals (and how they talk back) (KotlinConf 2026)
jakewharton
PRO
1
110
1人1案件のプロダクトエンジニア時代に、"プロセス監督"としてチャレンジしたこと
non0113
0
280
実践ハーネスエンジニアリング:ステアリングループを実例から読み解く / Practical Harness Engineering: Understanding Steering Loops Through Real-World Examples
nrslib
6
6.2k
継続的な負荷検証を目指して
pyama86
3
1.5k
~ 秘伝のタレ化した『神スプシ』と戦う ~ 関数型パラダイムで壊れない仕組みへ
h0r15h0
1
130
新規プロダクトを高速で生み出すハーネスエンジニアリング
seanchas116
3
270
Agentic AI & UI: Arcitecture, HITL, Emerging Standards
manfredsteyer
PRO
0
130
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
5
610
tsserverとは何だったのか、これからどうなるのか
nowaki28
1
360
Featured
See All Featured
Navigating Weather and Climate Data
rabernat
0
200
Documentation Writing (for coders)
carmenintech
77
5.3k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
140
4 Signs Your Business is Dying
shpigford
187
22k
Docker and Python
trallard
47
3.8k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
810
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
360
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
200
What's in a price? How to price your products and services
michaelherold
247
13k
Optimizing for Happiness
mojombo
378
71k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
280
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.4k
Transcript
Kotlin/Native CA.kt #3 @stormcat24
stormcat24 ‣ CyberAgent, Inc. ‣ FRESH! https://freshlive.tv ‣ https://blog.stormcat.io ‣
Docker Comedian
Ice Break?
Written by @ngsw_taro Congratulations!
I reviewed 2nd, 3rd parts. ‣SparkFramework with Kotlin ‣Spring Boot
with Kotlin
Kotlin/Native
What?
None
“Kotlin/Native that compiles Kotlin directly to machine.”
“without any virtual machine.” (standalone executables)
Kotlin/Native is ‣Compiles directly to native code via LLVM ‣Call
native libraries ‣Cross Platform ‣Windows/Linux/macOS/iOS/Android/Raspberry Pi ‣Version 0.3
Setup $ git clone
[email protected]
:JetBrains/kotlin-native.git $ cd kotlin-native (kotlin-native)$ git
checkout v0.3.4 Get Kotlin/Native Build (kotlin-native)$ ./gradlew dependencies:update (kotlin-native)$ ./gradlew dist (kotlin-native)$ ./gradlew cross_dist Path $ export PATH=$PATH:path-to-path/kotlin-native/dist/bin
Try Quickly fun main(args: Array<String>) { // Not System.out.println() println(“Hello!
Kotlin/Native“) } hello.kt compile $ kotlinc hello.kt -o hello KtFile: hello.kt Execute $ ./hello.kexe Hello! Kotlin/Native
build.gradle buildscript { repositories { mavenCentral() maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
} } dependencies { classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.3.3" } } apply plugin: 'konan' konanArtifacts { KonanExample { } }
Native Library
Today’s Example HTTP GET Request By using libcurl
Create *.def file ‣Library definition file ‣Link Kotlin/Native to Native
libraries ‣Generate interoperability stubs ‣Define in build.gradle
Define *.def file headers = curl/curl.h compilerOpts=-I/usr/local/include linkerOpts.osx = -L/opt/local/lib
-L/usr/local/opt/curl/lib -lcurl src/main/c_interop/libcurl.def build.gradle apply plugin: 'konan' konanInterop { Libcurl { includeDirs '/usr/local/opt/curl/include', '.' } } konanArtifacts { KonanExample { useInterop 'libcurl' } }
Implementation curl.kt import kotlinx.cinterop.* import libcurl.* fun main(args: Array<String>): Unit
{ if (args.size == 0) { return } val url = args.first() val curl = curl_easy_init() curl_easy_setopt(curl, CURLOPT_URL, url) val res = curl_easy_perform(curl) when (res) { CURLE_OK -> println("HTTP Request OK") else -> println("HTTP Request NG") } }
Call Library In C #include <curl/curl.h> CURLcode curl_easy_perform(CURL * easy_handle);
fun curl_easy_perform(curl: COpaquePointer?): CURLcode { return kniBridge40(curl.rawValue) } typealias CURLcode = kotlin.Int val CURLE_OK: CURLcode = 0 val CURLE_UNSUPPORTED_PROTOCOL: CURLcode = 1 val CURLE_FAILED_INIT: CURLcode = 2 … Stub in Kotlin/Native
Execute Build Execute $ ./gradlew build $ ls build/konan/bin Curl.kexe
Curl.kt.bc $ build/konan/bin/Curl.kexe https://blog.stormcat.io <!DOCTYPE html> <html lang="ja-jp"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> (...) HTTP Request OK
Interoperability
Interop types ‣Int => kotlin.Int ‣T* => CPointer<T> ‣void* =>
COpaquePointer? ‣
Memory Management ‣Automated memory management by Cycle Collector ‣https://github.com/JetBrains/kotlin-native/blob/master/ runtime/src/main/cpp/Memory.cpp
‣When using Native Library…?
Memory allocation Allocate memory val buffer = nativeHeap.allocArray<ByteVar>(size) ... nativeHeap.free(buffer)
memScoped val fileSize = memScoped { val statBuf = alloc<statStruct>() val error = stat("/", statBuf.ptr) statBuf.st_size }
Use IDEA
<- Uncheck Java
Code Completion
Impressions
Impressions ‣Very experimental and challenging ‣Interoperability is difficult ‣Lack of
Ecosystem, fundamental libraries ‣Not enough code completion ‣If gRPC support Kotlin/Native?
Thanks✋