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

How to generate code for common Ios target instead of individual (X64, Arm64) source sets #929

Open
Legion2 opened this issue Apr 4, 2022 · 8 comments

Comments

@Legion2
Copy link

Legion2 commented Apr 4, 2022

We use the shorthand ios() function to configure common ios source sets and we only have code in the iosMain source set. However ksp generates code into the IosX64 and IosArm64 source sets. For both source sets, identical code is generated, but we cannot access the definitions from the iosMain source set.

dependencies {
    add("kspAndroid", project(":processor"))
    add("kspIosX64", project(":processor"))
    add("kspIosArm64", project(":processor"))
}

If we try to configure add("kspIos", project(":processor")) we get the following error: Configuration with name 'kspIos' not found.

Either the commonization task should run on the generated sources and generate the common definitions or ksp should generate code for the iosMain source set.

@nrobi144
Copy link

nrobi144 commented May 6, 2022

Tried add("kspIos", myKspPlugin) on v1.6.10-1.0.4 and it works

@Legion2
Copy link
Author

Legion2 commented May 7, 2022

With 1.6.20-1.0.4 it does not work. We use ios() to add the ios targets in the kotlin dsl.

@bennyhuo
Copy link
Contributor

bennyhuo commented May 12, 2023

    add("kspCommonMainMetadata", project(":klue-compiler"))
    add("kspAndroid", project(":klue-compiler"))
    add("kspIosArm64", project(":klue-compiler"))
    add("kspIosSimulatorArm64", project(":klue-compiler"))
    add("kspIosX64", project(":klue-compiler"))
    add("kspJs", project(":klue-compiler"))

It works in Kotlin 1.8.20.

@Legion2
Copy link
Author

Legion2 commented May 12, 2023

    add("kspCommonMainMetadata", project(":klue-compiler"))
    add("kspAndroid", project(":klue-compiler"))
    add("kspIosArm64", project(":klue-compiler"))
    add("kspIosSimulatorArm64", project(":klue-compiler"))
    add("kspIosX64", project(":klue-compiler"))
    add("kspJs", project(":klue-compiler"))

It works in Kotlin 1.8.20.

This still only generates code for code for individual targets and commonMain but not iosMain.

@burnoo
Copy link

burnoo commented Nov 25, 2023

Found workaround, but it works only for extensions.

Koin example: You can add following code to your iosMain sourceSet:

package org.koin.ksp.generated // package should be same as your generated code

import org.koin.core.module.Module

@Suppress("UnusedReceiverParameter")
val Any.module: Module
    get() = throw RuntimeException("Koin module was not generated. Add ksp for all your targets")

On iosMain IDE will recognize the above extension, but on more specific target (e.g. IosArm64) it will use generated code instead, as val Module.module: Module is a better match than val Any.module: Module.

@ltttttttttttt
Copy link

Is there a formal solution now?

@H4kt
Copy link

H4kt commented May 24, 2024

+1
Facing the same issue

@Ribesg
Copy link

Ribesg commented Jun 6, 2024

This seemingly unrelated comment is another (imho, less hacky) workaround for the iosMain target JetBrains/compose-multiplatform#4928 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants