realm / realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Apache License 2.0
956 stars 59 forks source link

Kotlin JS #1169

Open Burtan opened 1 year ago

Burtan commented 1 year ago

Hey, any chance to get Kotlin JS support? Would be nice in combination with jetbrains compose web. Thanks for considering!

cmelchior commented 1 year ago

Hi @Burtan. We are looking into JS support, but there are quite a few technical challenges associated with it, like building the core database for WebAssembly and making sure the threading model will still work. So we don't really have any sort of timeline for it yet.

gxhenderson commented 1 year ago

I'm curious if this is more feasible now with the Kotlin/WASM target. Would it be as simple as adding the following target to build.gradle.kts files?

wasm {
  browser()
}
cmelchior commented 1 year ago

@gxhenderson Once it is working, yes, that should be enough. Unfortunately, it is a bit more complicated behind the scenes, so that will not work yet.

gxhenderson commented 1 year ago

@cmelchior what do you mean by not working? As in there is something within Realm that needs to be updated or that the Kotlin/WASM target is in alpha and has some bug that affects Realm? If it's the former, I might be interested in contributing to get this working as I have decided to invest pretty heavily in Realm for my side project 😁

Burtan commented 1 year ago

The core of realm is not written in kotlin. This project just contains the bindings.

cmelchior commented 1 year ago

@gxhenderson There are two limitations:

1) WASM is a lot more restricted than "normal" native code since it is running inside the browser sandbox. That has large implications on which APIs we have available in C++ and required us to modify parts of https://github.com/realm/realm-core. We have started this work, but there is still more to do. You can see the initial PR here: https://github.com/realm/realm-core/pull/6263

2) With Realm Core compiling against WASM, it should, in theory, be possible to enable the JS target, but there is a fair amount of expect/actual implementations in Realm Kotlin that only support Native, JVM and Android, those would have to be extended with JS support. After that we might run into architectural issues. The current codebase is heavily designed as multi-threaded and I suspect some of these designs would have to be re-worked for JS support.

While we appreciate the offer to help, I'm not sure the current state of this project is suitable for external collaboration, but I'll let you know when that changes.

gxhenderson commented 1 year ago

Thanks for this extra context and all the work the team is putting into supporting this! Excited to see how this goes.

ismai117 commented 1 year ago

im using realm for andoird/iOS and desktop but not web. I'm trying to run web without realm but I keep on receiving errors because realm doesn't work with js(IR) { browser() } but im not using realm for web. also I can't remove js(IR) { browser() } because web needs it

ismai117 commented 1 year ago

val jsMain by getting { dependsOn(commonMain) dependencies { implementation(compose.html.core) implementation("io.realm.kotlin:library-base:$realmVersion") { exclude(group = "io.realm.kotlin", module = "library-base") } implementation("io.realm.kotlin:library-sync:$realmVersion") { exclude(group = "io.realm.kotlin", module = "library-sync") } } } this won't work