kstatemachine icon indicating copy to clipboard operation
kstatemachine copied to clipboard

Add multiplatform support

Open nsk90 opened this issue 4 years ago • 11 comments

nsk90 avatar Jul 22 '21 20:07 nsk90

There is no synchronization support and CopyOnWriteArraySet should be replaced with another Set implementation. Also tests should not depend on JUnit.

nsk90 avatar Oct 28 '21 21:10 nsk90

which platforms to support?

nsk90 avatar Feb 22 '22 20:02 nsk90

Tests switched to kotest which has jvm and js support.

nsk90 avatar Feb 22 '22 21:02 nsk90

Did you found this discussion about replacing synchronization support? https://discuss.kotlinlang.org/t/replacement-for-synchronized/11240

MasterEmit avatar May 05 '22 14:05 MasterEmit

Yes I know it is not a problem to implement synchronization analog. I can even simply drop all synchronization away, as kstatemachine classes are not intended to be thread-safe. I used synchronization in some cases just to prevent from common possible mistakes..

I am not sure about what platforms it might be useful to support. I don't have a project where is might be necessary in practice. Tell me if you have one?)

nsk90 avatar May 05 '22 15:05 nsk90

We would like to use multiplatform for Android and iOS, but I can't see really a usecase for synchronization beside the one you mentioned: prevent from common mistakes ;-). So maybe dropping synchronization may could be a way, which is perfectly fine for this library.

MasterEmit avatar May 17 '22 06:05 MasterEmit

Removed JVM synchronisation primitives in 0.10.0. It seems that now KStateMachine should be compatible to Kotlin multi-platform. I am going to check it...

nsk90 avatar Jul 22 '22 21:07 nsk90

Current status: library itself successfully builds for jvm, js and possibly other targets. Kotest used as testing framework supports running tests on jvm and js. Mockk used for mocks supports only jvm. So the tests are limited to jvm.

I think I will add mutiplatform plugin to gradle files, so users will be able to build library for targets they need theirselves.

nsk90 avatar Aug 13 '22 10:08 nsk90

Here are some mocking libraries with multiplatfrom support. https://github.com/kosi-libs/MocKMP https://github.com/mockative/mockative

nsk90 avatar Aug 13 '22 11:08 nsk90

I think I will add mutiplatform plugin to gradle files, so users will be able to build library for targets they need theirselves.

I've switched few of my libraries to KMP and it was painful. A lot of issues with various gradle configs, plugins (especially maven-publish). Having reference projects where it was already done helps a lot.

I would also suggest adding targets for ios*Arm64 and macos*Arm64, this is M1 stuff. I have recently created a PR for this for kotlin-result, which I also used as a sample while porting my libs to KMP, perhaps you would find it useful too (also all useful kmp-targets can be found there):

https://github.com/michaelbull/kotlin-result

dimsuz avatar Sep 24 '22 22:09 dimsuz

@dimsuz cool, thank you!

nsk90 avatar Sep 26 '22 06:09 nsk90

This is done finally! https://github.com/nsk90/kstatemachine/releases/tag/v0.22.0 KStateMachine has moved to Kotlin Multiplatform

I will add more platforms soon..

nsk90 avatar Mar 30 '23 17:03 nsk90