Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplatform support #7

Open
bendgk opened this issue Feb 21, 2023 · 14 comments
Open

Multiplatform support #7

bendgk opened this issue Feb 21, 2023 · 14 comments
Assignees
Labels
enhancement New feature or request

Comments

@bendgk
Copy link
Owner

bendgk commented Feb 21, 2023

Kotlin supports cross-compilation to multiple platforms: native/js/jvm.

It would be cool if EffeKt was able to be targeted to be compiled as a Multiplatform project.

@bendgk bendgk added the enhancement New feature or request label Feb 21, 2023
@bendgk bendgk self-assigned this Feb 21, 2023
@bendgk bendgk moved this to Todo in EffeKt Feb 21, 2023
@bendgk bendgk added this to EffeKt Feb 21, 2023
@sdeleuze
Copy link

sdeleuze commented Feb 22, 2023

I am interested in contributing Kotlin/Wasm (still in preview) support once you have made the library multiplatform and added Kotlin/JS support.

@sdeleuze
Copy link

Maybe you could just make the lib fully multiplatform by using https://github.com/Kotlin/kotlinx-atomicfu.

@bendgk
Copy link
Owner Author

bendgk commented Feb 22, 2023

Yeah sorry, this was on a backlog as I had real-life things to take care of, I'm gonna start working on porting over to Kotlin Multi-Platform today.

I'll take a look at atomicfu, and I believe you posted a blog post on Kotlin Multi-Platform somewhere, so I'll give that a read to 👍

@sdeleuze
Copy link

No problem, and thanks for taking care of that, feel free to share a branch or a PR if you want feedback. The blog post I published recently here is really focused on Kotlin/Wasm but yeah I would like to use effekt for frontend development with Kotlin/Wasm as a lightweight alternative to Compose.

@notKamui
Copy link

Maybe you could just make the lib fully multiplatform by using https://github.com/Kotlin/kotlinx-atomicfu.

There is no need for that. Benjamin should use Mutex instead of ReantrantLock, and move to coroutines for concurrency

@sdeleuze
Copy link

Mutex implementation is leveraging atomicfu, and I would like to avoid a mandatory dependency on Coroutines when not needed since on frontend footprint is super important, especially given the lighweight positioning of this library.

So I think I would advise:

  • To limit usages of kotlinx.coroutines.* classes to concurrency/Concurrency.kt
  • Use directly atomicfu in the library core (reactivity/Reactivity.kt)

@bendgk
Copy link
Owner Author

bendgk commented Feb 22, 2023

Yeah, I possibly agree with this approach too. I originally really liked the lightweight approach and 0 dependencies that reactivity/Reactivity.kt had originally.

I think ill keep concurrency/Concurrent.kt though because Coroutine usage with EffeKt seems like a common valid use case.

Also, I'm not too sure how the decoupling of packages works in kotlin/gradle, would it be possible to include only either concurrency or reactivity and not both in a project? I think something like that would be ideal.

@sdeleuze
Copy link

sdeleuze commented Feb 22, 2023

Could potentially be achieved by using compileOnly for the Coroutines dependency, but I have not tried it on multiplatform projects.

Both Kotlin/JS and Kotlin/Wasm are using dead code elimination so this is potentially not strictly for the footprint goal, but it would be much cleaner to not pollute the classpath when Coroutines are not used by the user project, and avoiding the mandatory dependency also makes sense on JVM side.

Feature variants are another way to tackle that kind of need, but not sure we need this level of complexity, so if compileOnly works on multiplatform project, I would stick to that.

@sdeleuze
Copy link

Hum, I am AFK so have not tried but compileOnly looks like JVM specific so, if confirmed, maybe for now keep the dependencies as they are, I will do footprint tests with Kotlin/JS and Kotlin/Wasm with your multiplatform implementation to check Coroutines classes are removed by the dead code elimination processing.

The key point as mentioned above is to not reference Coroutines classes or Concurrency.kt from Reactivity.kt.

@notKamui
Copy link

You can make the dependency to kotlinx.coroutines not transitive.

dependencies {
    implementation("anylib") {
        transitive = false
    }
}

@bendgk
Copy link
Owner Author

bendgk commented Feb 23, 2023

Hey guys, just created the dev/multiplatform branch, come check it out!

I'm still working on adopting all the other discussions and recommendations that were passed around. Right now in dev/multiplatform the concurrency package has been removed. I will work on bringing it back in with a new effektScope API

Honestly, I love working on this project, but I may need to allocate my coding time for this project to the weekends for now (as real-life duty calls)

@sdeleuze
Copy link

sdeleuze commented Feb 24, 2023

I did some test and it seems to work as expected on frontend with pretty low footprint, I did various refinements in https://github.com/sdeleuze/effekt/tree/dev/multiplatform feel free to integrate my additional commit.

Wasm support will require Kotlin/kotlinx-atomicfu#278.

Worth to try the transitive = false when you bring back the Coroutine support.

@sdeleuze
Copy link

Since that's too early to provide Kotlin/Wasm support there, I have added support on KoWasm side via this commit and will leverage upstream effeKt when it will provide Wasm support (I guess Kotlin 1.8.20 final + Kotlin/Wasm support in atomicfu will be needed). I have added a DOM based sample if you want to have a look.

@bendgk
Copy link
Owner Author

bendgk commented Feb 26, 2023

Thanks for the fork, Ill take a look at it in a bit.

Gonna work on the concurrency package later today and hopefully Tag an actual release with Multiplatform support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

3 participants