question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support source set-specific code generation in Multiplatform projects

See original GitHub issue

As shown in #963, this repository’s multiplatform example generates identical code for all source sets, resulting in “Redeclaration” compiler errors once dependencies are set up correctly. While this example can be fixed by generating code for the commonMain source set only, this will not work with projects requiring separate code sets generated for different source sets.

OliverO2/kotlin-multiplatform-ksp contains an example project where this problem has been solved via source set detection:

https://github.com/OliverO2/kotlin-multiplatform-ksp/blob/214eef9e529ca3dae8a6e38123790b4795302969/symbol-processor/src/jvmMain/kotlin/QualifiableProcessor.kt#L37-L38

https://github.com/OliverO2/kotlin-multiplatform-ksp/blob/214eef9e529ca3dae8a6e38123790b4795302969/symbol-processor/src/jvmMain/kotlin/QualifiableProcessor.kt#L55-L56

As there seems to be no reliable API providing the required information on input and output source sets, the solution is unstable.

In addition, the output source set is only detected via the codeGenerator’s generated file path, which makes it unsuitable for collecting information before deciding on code generation.

Would it seem feasible for a future KSP release to provide information on input and output source sets via the SymbolProcessorEnvironment or the Resolver?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:11
  • Comments:5

github_iconTop GitHub Comments

1reaction
neetopiacommented, Jun 24, 2022

Sorry I am currently packed with other tasks, will reach back (also follow up on your PR) probably next week.

0reactions
OliverO2commented, Aug 15, 2022

Excluding (human written) parent sources from getNewFiles/getAllFiles/getSymbolsWithAnnotation/etc. would immediately solve use case 1 (generate code from symbols in its current (output) source set only). It would not cover use case 2 (generate expect/actual code, triggered by annotations in a shared source set). The latter would require full source set-awareness in the processor and complete access to parent source set symbols.

If a processor is to generate some (non-trivial) source set-specific code, it must have some idea about the source set’s targets and know which (library) APIs are available. Such information could be conferred via source set-specific configuration (arg option) or determined via the (hardwired) source set name in the processor itself. For completeness, we’d have to keep in mind the edge case of #1037, when there might not be a separate compilation for some intermediate source sets.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Share code on platforms - Kotlin
With Kotlin Multiplatform, you can share the code using the mechanisms Kotlin provides: Share code among all platforms used in your project.
Read more >
IntelliJ IDEA 2017.3: Support for Kotlin Multi-platform Projects
The IDE will generate a multi-platform project with the following modules: a common module for the shared code between the platforms, and two ......
Read more >
Top 13 Scripting Languages You Should Pay Attention to in ...
Programming languages are more code-intensive as you have to do many ... Python is a free and open source project, managed by the...
Read more >
Creating a multiplatform binary framework bundle
Combine variants of a binary framework or library into an XCFramework bundle that supports multiple platforms.
Read more >
8.1 Customizing Git - Git Configuration
Many, many configuration options are supported, but a large fraction of them ... You can put patterns in your project's .gitignore file to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found