https://kotlinlang.org logo
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
benchmarks
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
confetti
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
lincheck
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by
Title
m

Marc

01/15/2023, 11:15 PM
I am currently trying to create an executable WebAssembly project for Node and set up a project that uses Multiplatform version
1.8.20-dev-5802
. I managed to get it working in that I get an .mjs file and a .wasm file, but when I try to execute the .mjs file with Node 19.4.0 with a completely empty main function, the execution fails with the following message:
CompileError: WebAssembly.Module(): Compiling function #13:"kotlin.text.checkRadix" failed: Invalid opcode 0xe3 @+9238
When I try to open the produced file in an online WASM to WAT converter, it also fails. How can there be an invalid opcode? Am I missing any flags that I have to enable in Node? I am currently using
--experimental-wasm-eh
,
--experimental-wasm-typed-funcref
and
--experimental-wasm-gc
. From what I have seen after a quick Google search, the opcode 0xe3 doesn't seem to be valid currently anyways, not even when considering all active proposals.
s

sdeleuze

01/16/2023, 6:33 AM
This is expected due to WebAssembly GC evolution, with Kotlin/Wasm 1.8.20 you need Node 20 (canary). You can install it with:
NVM_NODEJS_ORG_MIRROR=<https://nodejs.org/download/v8-canary> nvm install v20.0.0-v8-canary202212266b2b946a63
nvm use v20.0.0-v8-canary202212266b2b946a63
And/or configure your build like https://github.com/skuzmich/kotlin-wasi-bindings-experiments/blob/main/build.gradle.kts
m

Marc

01/16/2023, 12:13 PM
That seems to work, thanks. The repository you linked also seems very interesting, it seems to expose WASI calls to Kotlin? I was thinking if it would be possible to do it the other way around. Instead of designing your Kotlin programs to use these WASI calls, would be maybe be possible to compile a WASM program normally and replace the JS glue code with WASI calls from within the WASM executable, preferrably also written in Kotlin? That would require the names of those imported JS functions to be stable of course, which they don't really look like they are...
s

sdeleuze

01/16/2023, 12:40 PM
Glad it works. About WASI I am doing upcoming development on https://github.com/sdeleuze/kowasm. I am not sure what is your use case for what you describe for WASI, could you ellaborate?
s

Svyatoslav Kuzmich [JB]

01/16/2023, 12:44 PM
Instead of designing your Kotlin programs to use these WASI calls, would be maybe be possible to compile a WASM program normally and replace the JS glue code with WASI calls from within the WASM executable, preferrably also written in Kotlin? That would require the names of those imported JS functions to be stable of course, which they don’t really look like they are...
At some point, would would likely have a version of stdlib without JS, with WASI imports only.
s

sdeleuze

01/16/2023, 12:57 PM
Ah ok, that was about that, so yeah this would be the best outcome.
Distinct API is just a intermediate step to move forward.
m

Marc

01/16/2023, 2:16 PM
I am not sure what is your use case for what you describe for WASI, could you ellaborate?
I am trying to compile a standalone WASM binary that I can run externally without any JS glue, which seems like is not really currently possible... But that's why I am asking if there are any ugly hacks to do it anyways 😄
A version of the standard library without JS would be a dream, but is that something that is being planned right now?
s

Svyatoslav Kuzmich [JB]

01/16/2023, 2:49 PM
It is planned. Also, having a non-JS Wasm runtime with GC support (or progress in this direction) would deficiently bump the priority of non-JS stdlib on our side.
s

sdeleuze

01/16/2023, 2:51 PM
Yep I discussed that with Wasmtime team at some point but https://github.com/bytecodealliance/wasmtime/issues/5032 require significant effort so no short term plans. Another way to move forward would be https://github.com/WebAssembly/binaryen/issues/4590.
m

Marc

01/16/2023, 3:22 PM
I assume that it is implemented in Node because it reuses V8's GC? It's a shame that the current non-JS runtimes don't at least have stub implementations available as far as I can tell. Even if it used a bump allocator or something that never frees the memory, one could at least run and test simple programs on there. I assume that Kotlin/Native has to ship a GC though, would it be possible to reuse that one by compiling it to WASM as well?
s

sdeleuze

01/16/2023, 3:23 PM
Yep that's the reason. Kotlin/Native Wasm support with GC is a dead end and will be removed, Kotlin/Wasm with GC is the way to move forward for a lot of reasons.
Short term this is a pain but a great bet on the future.
Once GC will be enabled by default on all browser and once Wasmtime or another non JS WASI runtime ship support for GC, that will be amazing.
m

Marc

01/16/2023, 3:28 PM
I have never tried using the WASM target for Kotlin/Native so I wasn't aware that the idea of shipping a GC has been tried before... It sounded very complicated anyways but I thought that the Kotlin devs aren't above shipping complicated software to work around host limitations as that's kind of their hole thing...
But as long as it's possible to execute it at all using Node, I'm happy. My idea of replacing the JS glue code calls with WASM code to get standalone binaries probably is a bad idea anyways, right?
s

sdeleuze

01/16/2023, 3:31 PM
I think that will be doable via migrating to using Kotlin/Wasm standard libraries and other multiplatform libraries once supported (or using KoWasm when mature enough in the interim).
So not a bad idea but won't be automatic IMO
m

Marc

01/16/2023, 3:38 PM
I was looking at this mapping in the JS code and technically you should be able to translate them to WASI calls, right? The only thing that I am unsure about is that these look like compiler implementation details that might change at any time.
s

Svyatoslav Kuzmich [JB]

01/16/2023, 5:19 PM
These is implementation detail, and can change, yes. Maybe someday we’ll make these names stable, but it is not a priority. It is better to use this JS file as-is for now (all Wasm GC runtimes currently support JS, so this shouldn’t be a problem), and wait for non-JS stdlib.
m

Marc

01/16/2023, 6:22 PM
Okay, thanks!
I have made some progress implementing a simple API for testing some WASM features, but I'm having some trouble opening sockets. If I understood correctly you need to pass a file descriptor handle and register it in the
preopens
configuration section somehow but what exactly are you supposed to write there? I tried putting IP addresses with and without ports in there but all I get are
UVWASI_ENOENT
errors.
s

sdeleuze

01/17/2023, 2:22 PM
m

Marc

01/17/2023, 2:38 PM
Oh, that makes a lot of sense then. I couldn't find anything about that on Google and I didn't think to check the issues. Are there any other parts of the WASI spec that are unimplemented?