-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Expect Actual Ancestor Components and Common Descendant Components #361
Comments
I pushed some code to https://github.com/eygraber/kotlin-inject/tree/expect-actual-ancestor-components highlighting the issue. Running
Commenting out the common KSP dependency and uncommenting the JVM KSP dependency and the JS KSP dependency and rerunning the gradle command should then work. However if you use Kotlin 2.0 then it won't work anymore (because the common source set can't see the generated platform source sets anymore). |
In case you took a look at the branch already, one piece was missing that was making both scenarios fail. I pushed a fix for that, so it should be good as of now. |
To restate, the problem is that when created by a common source set, a component or any of its ancestors that have an
The goal is to have I've been trying out a few different ways to model this so that there needs to be little to no action taken by the user, but I don't think that's (currently) feasible:
So going back to the proposed solutions from the OP:
Given the constraints, 1 would be the best solution. It would be nice to pair that with 2 so that the user doesn't have to do anything at all (i.e. write the common One issue with 1 would be that if the user is running KSP against the common compilation, there will be @evant I can put up a PR implementing solution 1 if that's something you're OK with. |
I put up a PR to see what it would look like. |
To close the circle, there could be another processor added to kotlin-inject that generates an expect create fun in commonMain based on |
I have a component hierarchy that has an expect component in the middle of it, and the actual implementations provide platform specific bindings. That requires that all downstream components be generated for all platforms, even if they themselves are common, because common generated code wouldn't be able to see these platform specific bindings.
Pre Kotlin 2.0 this isn't a problem in some cases because common source sets can (incorrectly) reference generated platform code. However once Kotlin 2.0 is released this won't work anymore for any of the cases.
To solve the issue, all downstream components (which is ~99% of the components in my project) will need to specify expect/actual declarations for the
create
functions for each platform (this project supports 5 platform targets) in each module (and I typically have 1 downstream component per module).That's kind of painful, and I'm wondering if there's a way for kotlin-inject to detect (or be told about) this situation, and generate the expect/actual declarations for
create
.I'm not sure if it could be done in the same processor, or if it would need a different processor, or if it's even possible with KSP at all (I think it would need something like Support source set-specific code generation in Multiplatform projects).
Other options that (hopefully) don't require changes in KSP are:
create
function as actual and then the user just needs to specify a commonexpect create
functionexpect create
functioncreate
functions as actualThe text was updated successfully, but these errors were encountered: