I'm trying to debug a library I'm using that gener...
# ksp
a
I'm trying to debug a library I'm using that generates code with KSP, now upgraded to KSP 2x. Naturally, some of the KSP functionality isn't working but it's something quite particular. Android still works great, but the iOS target appears to be missing one particular thing. The library expects that some of the code it generates will supercede some boilerplate code. I call a library static helper class/method whose default implementation throws an exception, but the library generates a version of that same class that runs the generated code. With KSP 2 this works on Android, but no longer works on iOS. The kicker is that I can see that the code is being generated, even in iOS, but for some reason the generated code is not being picked up by the compiler.
Okay, as an update I can confirm that the generated code in iosArm64Main is not being recognized as a place where source code resides by the compiler. I verified this by changing the name of one of the generated functions. Android found the new generated name just fine, but iosMain is not. Did something change with KSP 2 to enable iosMain to recognize generated iosArm64Main code?
e
Did you also just update to Kotlin 2.x.x from Kotlin 1.x.x? If so, it sounds like https://kotlinlang.org/docs/whatsnew20.html#separation-of-common-and-platform-sources-during-compilation
a
Ah, yep! That is gonna be the culprit, thanks so much! Sheeh I wish I would have stumbled upon that in my searching; they literally reference my use case; platform code overriding/superceding common code. Now I just gotta figure out how to make this library operate under these new constraints. @eygraber did you have to mess with anything along these lines w/ kotlin-inject?
e
a
Hah I feel the pain in that response 🤣
😂 1
Oh, one question I had about the
@KmpComponentCreate
annotation @eygraber - for iOS can you put the
Copy code
@KmpComponentCreate
expect fun createAppComponent(): AppComponent
function in just iosMain, or do you need to create it for each iOS target (e.g.
iosX64()
,
iosArm64()
)? I've adjusted my library to generate some code that is resulting in a specific iOS target (simulator in this case) with the expect version just in iosMain and it appears to not like that.
e
It depends on how you configure KSP. In kotlin-inject the suggestion is to run KSP on the target configurations (e.g.
kspIosX64
, etc...) and put your
@KmpComponentCreate expect fun
into the intermediate source set where it makes sense (e.g.
iosMain
,
appleMain
,
commonMain
, etc...).
a
Okay good to know. The challenge I'm having is even though I define the
expect
function w/ annotation in
iosMain
, when I generate the
actual
function in generated target code
(e.g. iosArm64Main)
via the processor, it says there is no corresponding
expect
method and won't build. Is there some KSP setting or trick to ensure that the iosMain and generated target code know about each other?
e
Does the generated
actual fun
have the exact same signature as the
expect fun
(package, annotations, etc...)?
a
Hmmm I didn't add the annotation to the generated version. I'll try that.
It worked! You pointed me in the right direction @eygraber Thank you so much!
🎉 1