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

Support Kotlin Symbol Processing (KSP) #7310

Closed
mannodermaus opened this issue Feb 16, 2021 · 20 comments
Closed

Support Kotlin Symbol Processing (KSP) #7310

mannodermaus opened this issue Feb 16, 2021 · 20 comments

Comments

@mannodermaus
Copy link
Contributor

Describe your problem or use case

Kotlin Symbol Processing (KSP) is a joint effort by Google & JetBrains and seeks to provide an API for building compiler plugins. Compared to KAPT, annotation processors that use KSP can run up to 2x faster.

Describe the solution you'd like

Introduce a sibling artifact to the realm-annotations-processor which leverages the performance and benefits of KSP over KAPT for Kotlin-based projects.

@rorbech
Copy link
Contributor

rorbech commented Feb 22, 2021

@mannodermaus Thanks for the input. We are aware that KSP has been promoted to alpha, but have not yet evaluated/looked into replacing the current Realm annotation processor for Kotlin with it.

@kzotin
Copy link

kzotin commented Sep 8, 2021

Just FYI, KSP is now stable!👀

https://android-developers.googleblog.com/2021/09/accelerated-kotlin-build-times-with.html

@mannodermaus
Copy link
Contributor Author

FWIW I was trying to help out here and look into a potential migration to KSP as an external contribution, but frankly I was unable to get Realm compiled on my machine. 🙈 Is there a rough roadmap or guidance of Realm regarding this feature?

@mannodermaus
Copy link
Contributor Author

The Realm Kotlin SDK exists now. Is it safe to assume that KSP wouldn't be added for the older Java SDK, esp. since the new one seems to be built as a compiler plugin instead?

@rorbech
Copy link
Contributor

rorbech commented Jun 24, 2022

Yes, we do not have any immediate plans to rewrite the code generation parts of realm-java with KSP. KSP would only work for Kotlin code and doesn't support transforming existing code, so wouldn't suffice for our full use case. This is also why we use compiler plugins in realm-kotlin.

@rorbech rorbech changed the title Support Kotlin Symbol Processing Support Kotlin Symbol Processing (KSP) Sep 18, 2023
@Kardelio
Copy link

Heyoooo <3 any updates on this front? Just curious as we are moving our entire project over to ksp and the last bit is the realm of it all.
Not meant to be a pressure or pain, just curious if this work (realm to ksp instead of kapt) is going to happen at some point in the future?

Just for reference, i changed our module containing realm into ksp and got this error, after searching on the net i found that the underlying generation uses kapt, which led me here :)

An exception occurred applying plugin request [id: 'realm-android']
> Failed to apply plugin 'realm-android'.
   > Configuration with name 'kapt' not found.

For now the android docs say kapt and ksp can run in parralel together so ill add kapt plugin back to this module and keep an eye on this issue <3

Thank you all btw for your amazing work on realm, just needed to be said <3

@sailorseashell
Copy link

I'd like to add my voice to asking for updates on this. We are also trying to move our project completely over from kapt and this is the last holdout!

@brucemax
Copy link

brucemax commented Jun 8, 2024

As always, the only thing that slows down our project from innovation is the realm :(

@Deni-H
Copy link

Deni-H commented Jun 18, 2024

Any update on this?

@kzotin
Copy link

kzotin commented Jul 22, 2024

Since the release of Kotlin 2.0, the importance of migration to KSP increases due to:

w: Kapt currently doesn't support language version 2.0+. Falling back to 1.9.

@nirinchev
Copy link
Member

We don't have plans to add new features to realm-java and instead recommend that you migrate to our native kotlin SDK: https://github.com/realm/realm-kotlin.

@nirinchev nirinchev closed this as not planned Won't fix, can't repro, duplicate, stale Jul 22, 2024
@EranBoudjnah
Copy link

This is absurd. realm-kotlin is incredibly poorly documented. There's no migration guide, which is sorely needed because the two libraries are completely different. Not a day goes by that I don't regret going with Realm. 😢

@rorbech
Copy link
Contributor

rorbech commented Aug 9, 2024

@EranBoudjnah We have a migration guide that should give you an overview of the differences. It is hard to give a step-by-step guide on the actual process as it depends on your use case. Feel free to provide feedback on what items you are missing with regards of migrations and/or what you are missing from the realm-kotlin documentation.

@EranBoudjnah
Copy link

Thanks @rorbech - this helps. Let me dig into it, and I'll keep track of anything that I'm missing as I'm going through the migration.

One obvious thing is that the README on the repo https://github.com/realm/realm-kotlin disagrees with the rest of the documentation (for example, = vs == in queries). It also has code that simply doesn't work, like realm.query<Person>(...) - from what I've seen, you have to pass in the kclass to query, but that's not in the readme.

@nirinchev
Copy link
Member

= and == are both valid equality expressions and you can use either one. Can you clarify in which case you need to pass in the kclass - realm.query<TModel>(...) should work and we do have tests for it - e.g. https://github.com/realm/realm-kotlin/blob/06aacec9db7c1f9e9c702db5bd16393c4186589d/packages/test-base/src/commonTest/kotlin/io/realm/kotlin/test/common/QueryTests.kt#L350-L355.

@EranBoudjnah
Copy link

image
This is taken straight out of io.realm.kotlin:library-base-android:2.1.0 (io/realm/kotlin/Realm.kt).

It's rather confusing that you can use both, since in many languages the meaning differs. It would be good for the documentation to be consistent.

As for the migration document, it's missing things like what to do with @LinkingObjects and the fact the RealmList fields become required, changing the schema.

Overall, with some guesswork, I was able to migrate my project, but I can't say it was a smooth process. Another confusing thing is that the Readme file mentions using snapshots but doesn't have instructions for the simple case of adding a stable version...

@nirinchev
Copy link
Member

From the API docs for this method:

A reified version of this method is also available as an extension function,
realm.query<YourClass>(...). Import io.realm.query to access it.

Regarding the equality operator, the fact = and == are interchangeable is due to the fact it's impossible to do assignments inside a query expression. Most programming languages use == to express equality, which is why we wanted to be relaxed about it and not force usage of =.

Finally, the realm-kotlin readme does link to the install instructions in the installation section. The docs on mongodb.com/docs should be viewed as the authoritative source of truth and the readme is a compressed and maintainer-focused version of those docs.

@EranBoudjnah
Copy link

EranBoudjnah commented Aug 12, 2024

image
This doesn't seem to quite work. What am I missing?

I still think it would be helpful if the documentation was consistent in its use of either = or ==, even if the other is silently accepted. But that's just my opinion.

It's good to know that the link is the authoritative source of truth, although it seems somewhat outdated (it uses version 1.16.0).

In any case, thanks for the patience and help, @nirinchev!

@nirinchev
Copy link
Member

Can you try io.realm.kotlin.ext.query? Looks like the reified version of the function is defined here: https://github.com/realm/realm-kotlin/blob/06aacec9db7c1f9e9c702db5bd16393c4186589d/packages/library-base/src/commonMain/kotlin/io/realm/kotlin/ext/RealmExt.kt#L28-L31

@EranBoudjnah
Copy link

Nice! This works.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants