Is there a good multiplatform meta sample anywhere...
# arrow-meta
r
Is there a good multiplatform meta sample anywhere? Having trouble understanding how to wire things together on my own based on the hello world sample.
i
It might be worth expressing that the
multiplatform
topic applies for all plugins in the whole ecosystem - wether andriod, spark, or else. After Kotlin goes 1.4.0. By default Meta enables the IR backend. May I ask to what your building for. A good start is also checking out the phases Meta exposes and their related algebras.
r
I'm primarily interested in mobile, so Android/JVM and iOS/native. When moving Android clients toward KMP, a common question that comes up is how to do annotation processing and code generation, since they're used to that in the JVM world. Obviously compiler plugins go much deeper than that, but for the moment I want to understand if we can use Meta or something like it to do the sorts of code-gen our clients are used to. As a starting point I was trying to do essentially the same thing as in this thread, but I don't understand what needs to be added for native vs jvm. https://kotlinlang.slack.com/archives/CJ699L62W/p1579559989015500
i
@raulraja might be of better help, regarding the internals. But from a practical standpoint, we already have Quotes, which work like the one in Haskell. To do compile time codegen with synthetic resolution.
r
Right. I'm messing some with quotes on the jvm side based on the hello world sample, but I don't understand how to get it working on other platforms
r
Hi @russhwolf Quotes have a transformation step post parsing and previous to analysis which I believe all frontend share or you can exploit to generate multiplatform code
if you are just wanting to generate code based on annotations it’s called Transform.newSources
Even if you depend on the JVM you can use meta to transform any kotlin sources and tell it to bail after analysis
if you have some sample code and how you’d like it to be transformed we can provide an example
s
@raulraja fyi, analysis handler works on JVM only, so not sure if quotes will work on other platforms for now
r
I'm not yet at the point where I'm looking for specific help with the transform APIs (though I might get there). I first want to understand how to get the hello world sample plugin running on other platforms. If that's not possible yet I might wait a little longer before investing a lot of time into understanding the rest of it.
r
@shikasd I mean you can use to generate sources since it works at the psi level
and the compiler parser can presumably parse any kotlin
then after anlysis don’t let it codegen and it would work the same as kapt
s
yes, but js and native compiler don't run analysis handler
r
it works at the KtFile level
s
even the package name contains jvm 🙂
r
right but you could add a gradle step to run the quotes before the compile stepo
s
ah, right
r
and tell it to place the generated sources wherever you like
if you want analysis and typechecking then it may fail for platform specific stuff
We are following IR
r
That sounds like an acceptable tradeoff. If I understand correct it's no worse than you'd get with MpApt + KotlinPoet. But I could use some guidance in how to set it up.