https://kotlinlang.org logo
#ksp
Title
# ksp
d

Dmytro Serdiuk

03/17/2024, 5:49 PM
Hello! I have a question about support of the ksp for multiplatform projects. Is it possible to run ksp on intermediate source sets? According to docs I see it could be applied to any compilation unit (like compileKotlinJvm) and there is an example for “commonMain” metadata target. But as I understand there are some limitations still from the roadmap “Improve support to multiplatform. For example, running KSP on a subset of targets/sharing computations between targets.” May I ask what limitations are still persist? Thanks
So as I understand, there is no option to configure the ksp for intermediate source sets and ksp could be only configured for target compilations(like leafs - end output)? May I ask for some input please @Jiaxiang Thank you
And one more question - what is the purpose of running the ksp on metadata target, if the generated code is not used for the leaf targets (android, ios etc.)? Thanks
Also As I understand, add(ksp<SourceSet>) in the documentation doesn’t work, as we need to specify the compilation target
j

Jiaxiang

03/18/2024, 6:37 PM
you are right that it is impossible to configure KSP on intermediate source sets, it is a limitation from the kotlin multiplatform compilation model.
👍 1
d

Dmytro Serdiuk

03/18/2024, 8:46 PM
thank you for the reply
@Jiaxiang, sorry for one more question, may I ask you to clarify please regarding roadmap: “Improve support to multiplatform. For example, running KSP on a subset of targets/sharing computations between targets.” as I understand, • sharing computations between targets - it’s running on intermediate sources sets • running KSP on a subset of targets - what does it mean?I thought it’s already done through add(ksp*) configuration Thanks
@Jiaxiang,sorry to bother you, may I ask you please two questions, as it’s hard to understand from the documentation/github issues/slack/ksp codebase. 1. if there is metadata target for the intermediate sourceset, why it’s impossible to usee it the same way as for commonMainKotlinMetadata - use for example iosMainKotlinMetadata target to generate intermediate sources? 2. “Improve support to multiplatform. For example, running KSP on a subset of targets/sharing computations between targets.” - what does it mean first and second improvement? Thank you and sorry for disturb
j

Jiaxiang

03/20/2024, 4:48 PM
1. metadata target is not the intermediate sourceset, in fact you can compile to klib for metadata tasks, and there is no such thing as ios metadata, for ios tasks, it should compile to native code. 2. first should be quite straightforward, second is about if KSP can save computation by sharing the computations for different targets (currently every target will trigger new KSP processing)
d

Dmytro Serdiuk

03/21/2024, 1:01 PM
@Jiaxiang, thanks for the answer. 1. ok, so metadata target exist in the intermediate source set (for example to produce klib for ios). Could it be used as a kspIosMetadata the same way as kspCommonMainMetadata(to generate common metadata)? Thanks
j

Jiaxiang

03/21/2024, 5:31 PM
if you can find a task named
compileIosMetadata
in your build then you will have the corresponding KSP task in your build, KSP creates tasks according to kotlin compilation tasks.
d

Dmytro Serdiuk

03/21/2024, 5:46 PM
I have task named compileIosMainKotlinMetadata, probably it’s created using ios() shortcut in Kotlin extension in gradle. But ksp don’t create a configuration for it, only for iOSArm64, that’s why I have this question. When I add “add(kspIosMetadata)” or any other configuration related to shared ios source set in the dependencies block, I have an exception that configuration name not found. Maybe you have any thoughts about it please?
I have found this PR https://github.com/google/ksp/pull/609 and I don’t understand why it relates to source set at all, if it uses just a target names for the configuration
This is default project from examples:
Copy code
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("multiplatform")
    id("com.google.devtools.ksp")
}

version = "1.0-SNAPSHOT"

kotlin {
    jvm {
        withJava()
    }
    js(IR) {
        browser()
        nodejs()
    }
    ios()
    linuxX64() {
        binaries {
            executable()
        }
    }
    // requires Android SDK
    androidNativeX64() {
        binaries {
            executable()
        }
    }
    // requires Android SDK
    androidNativeArm64() {
        binaries {
            executable()
        }
    }
    mingwX64()
    sourceSets {
        val commonMain by getting
        val linuxX64Main by getting
        val linuxX64Test by getting
        val androidNativeX64Main by getting {
            kotlin {
                srcDir("build/generated/ksp/metadata/commonMain/kotlin")
            }
        }
        val androidNativeArm64Main by getting
    }
}

dependencies {
    add("kspCommonMainMetadata", project(":test-processor"))
    add("kspJvm", project(":test-processor"))
    add("kspJvmTest", project(":test-processor"))
    add("kspJs", project(":test-processor"))
    add("kspJsTest", project(":test-processor"))
    add("kspAndroidNativeX64Test", project(":test-processor"))
    add("kspAndroidNativeArm64", project(":test-processor"))
    add("kspAndroidNativeArm64Test", project(":test-processor"))
    add("kspLinuxX64", project(":test-processor"))
    add("kspLinuxX64Test", project(":test-processor"))
    add("kspMingwX64", project(":test-processor"))
    add("kspMingwX64Test", project(":test-processor"))

    // The universal "ksp" configuration has performance issue and is deprecated on multiplatform since 1.0.1
    // ksp(project(":test-processor"))
}
It’s a default task attached in the screenshot - compileIosMainKotlinMetadata. List of configurations:
Copy code
androidNativeArm64ApiElements androidNativeArm64CInteropApiElements androidNativeArm64CompilationApi androidNativeArm64CompilationCompileOnly androidNativeArm64CompilationDependenciesMetadata androidNativeArm64CompilationImplementation androidNativeArm64CompilationRuntimeOnly androidNativeArm64CompileKlibraries androidNativeArm64MainApi androidNativeArm64MainApiDependenciesMetadata androidNativeArm64MainCompileOnly androidNativeArm64MainCompileOnlyDependenciesMetadata androidNativeArm64MainImplementation androidNativeArm64MainImplementationDependenciesMetadata androidNativeArm64MainIntransitiveDependenciesMetadata androidNativeArm64MainRuntimeOnly androidNativeArm64MetadataElements androidNativeArm64SourcesElements androidNativeArm64TestApi androidNativeArm64TestApiDependenciesMetadata androidNativeArm64TestCompilationApi androidNativeArm64TestCompilationCompileOnly androidNativeArm64TestCompilationDependenciesMetadata androidNativeArm64TestCompilationImplementation androidNativeArm64TestCompilationRuntimeOnly androidNativeArm64TestCompileKlibraries androidNativeArm64TestCompileOnly androidNativeArm64TestCompileOnlyDependenciesMetadata androidNativeArm64TestImplementation androidNativeArm64TestImplementationDependenciesMetadata androidNativeArm64TestIntransitiveDependenciesMetadata androidNativeArm64TestRuntimeOnly androidNativeX64ApiElements androidNativeX64CInteropApiElements androidNativeX64CompilationApi androidNativeX64CompilationCompileOnly androidNativeX64CompilationDependenciesMetadata androidNativeX64CompilationImplementation androidNativeX64CompilationRuntimeOnly androidNativeX64CompileKlibraries androidNativeX64MainApi androidNativeX64MainApiDependenciesMetadata androidNativeX64MainCompileOnly androidNativeX64MainCompileOnlyDependenciesMetadata androidNativeX64MainImplementation androidNativeX64MainImplementationDependenciesMetadata androidNativeX64MainIntransitiveDependenciesMetadata androidNativeX64MainRuntimeOnly androidNativeX64MetadataElements androidNativeX64SourcesElements androidNativeX64TestApi androidNativeX64TestApiDependenciesMetadata androidNativeX64TestCompilationApi androidNativeX64TestCompilationCompileOnly androidNativeX64TestCompilationDependenciesMetadata androidNativeX64TestCompilationImplementation androidNativeX64TestCompilationRuntimeOnly androidNativeX64TestCompileKlibraries androidNativeX64TestCompileOnly androidNativeX64TestCompileOnlyDependenciesMetadata androidNativeX64TestImplementation androidNativeX64TestImplementationDependenciesMetadata androidNativeX64TestIntransitiveDependenciesMetadata androidNativeX64TestRuntimeOnly annotationProcessor archives commonMainApi commonMainApiDependenciesMetadata commonMainCompileOnly commonMainCompileOnlyDependenciesMetadata commonMainImplementation commonMainImplementationDependenciesMetadata commonMainIntransitiveDependenciesMetadata commonMainRuntimeOnly commonTestApi commonTestApiDependenciesMetadata commonTestCompileOnly commonTestCompileOnlyDependenciesMetadata commonTestImplementation commonTestImplementationDependenciesMetadata commonTestIntransitiveDependenciesMetadata commonTestRuntimeOnly compileClasspath compileOnly default implementation iosArm64ApiElements iosArm64CInteropApiElements iosArm64CompilationApi iosArm64CompilationCompileOnly iosArm64CompilationDependenciesMetadata iosArm64CompilationImplementation iosArm64CompilationRuntimeOnly iosArm64CompileKlibraries iosArm64MainApi iosArm64MainApiDependenciesMetadata iosArm64MainCompileOnly iosArm64MainCompileOnlyDependenciesMetadata iosArm64MainImplementation iosArm64MainImplementationDependenciesMetadata iosArm64MainIntransitiveDependenciesMetadata iosArm64MainRuntimeOnly iosArm64MetadataElements iosArm64SourcesElements iosArm64TestApi iosArm64TestApiDependenciesMetadata iosArm64TestCompilationApi iosArm64TestCompilationCompileOnly iosArm64TestCompilationDependenciesMetadata iosArm64TestCompilationImplementation iosArm64TestCompilationRuntimeOnly iosArm64TestCompileKlibraries iosArm64TestCompileOnly iosArm64TestCompileOnlyDependenciesMetadata iosArm64TestImplementation iosArm64TestImplementationDependenciesMetadata iosArm64TestIntransitiveDependenciesMetadata iosArm64TestRuntimeOnly iosMainApi iosMainApiDependenciesMetadata iosMainCompileOnly iosMainCompileOnlyDependenciesMetadata iosMainImplementation iosMainImplementationDependenciesMetadata iosMainIntransitiveDependenciesMetadata iosMainRuntimeOnly iosTestApi iosTestApiDependenciesMetadata iosTestCompileOnly iosTestCompileOnlyDependenciesMetadata iosTestImplementation iosTestImplementationDependenciesMetadata iosTestIntransitiveDependenciesMetadata iosTestRuntimeOnly iosX64ApiElements iosX64CInteropApiElements iosX64CompilationApi iosX64CompilationCompileOnly iosX64CompilationDependenciesMetadata iosX64CompilationImplementation iosX64CompilationRuntimeOnly iosX64CompileKlibraries iosX64MainApi iosX64MainApiDependenciesMetadata iosX64MainCompileOnly iosX64MainCompileOnlyDependenciesMetadata iosX64MainImplementation iosX64MainImplementationDependenciesMetadata iosX64MainIntransitiveDependenciesMetadata iosX64MainRuntimeOnly iosX64MetadataElements iosX64SourcesElements iosX64TestApi iosX64TestApiDependenciesMetadata iosX64TestCompilationApi iosX64TestCompilationCompileOnly iosX64TestCompilationDependenciesMetadata iosX64TestCompilationImplementation iosX64TestCompilationRuntimeOnly iosX64TestCompileKlibraries iosX64TestCompileOnly iosX64TestCompileOnlyDependenciesMetadata iosX64TestImplementation iosX64TestImplementationDependenciesMetadata iosX64TestIntransitiveDependenciesMetadata iosX64TestRuntimeOnly jsApiElements jsCompilationApi jsCompilationCompileOnly jsCompilationImplementation jsCompilationRuntimeOnly jsCompileClasspath jsMainApi jsMainApiDependenciesMetadata jsMainCompileOnly jsMainCompileOnlyDependenciesMetadata jsMainImplementation jsMainImplementationDependenciesMetadata jsMainIntransitiveDependenciesMetadata jsMainRuntimeOnly jsNpmAggregated jsPublicPackageJsonConfiguration jsRuntimeClasspath jsRuntimeElements jsSourcesElements jsTestApi jsTestApiDependenciesMetadata jsTestCompilationApi jsTestCompilationCompileOnly jsTestCompilationImplementation jsTestCompilationRuntimeOnly jsTestCompileClasspath jsTestCompileOnly jsTestCompileOnlyDependenciesMetadata jsTestImplementation jsTestImplementationDependenciesMetadata jsTestIntransitiveDependenciesMetadata jsTestNpmAggregated jsTestRuntimeClasspath jsTestRuntimeOnly jvmApiElements jvmCompilationApi jvmCompilationCompileOnly jvmCompilationImplementation jvmCompilationRuntimeOnly jvmCompileClasspath jvmMainApi jvmMainApiDependenciesMetadata jvmMainCompileOnly jvmMainCompileOnlyDependenciesMetadata jvmMainImplementation jvmMainImplementationDependenciesMetadata jvmMainIntransitiveDependenciesMetadata jvmMainRuntimeOnly jvmRuntimeClasspath jvmRuntimeElements jvmSourcesElements jvmTestApi jvmTestApiDependenciesMetadata jvmTestCompilationApi jvmTestCompilationCompileOnly jvmTestCompilationImplementation jvmTestCompilationRuntimeOnly jvmTestCompileClasspath jvmTestCompileOnly jvmTestCompileOnlyDependenciesMetadata jvmTestImplementation jvmTestImplementationDependenciesMetadata jvmTestIntransitiveDependenciesMetadata jvmTestRuntimeClasspath jvmTestRuntimeOnly kotlinBuildToolsApiClasspath kotlinCompilerClasspath kotlinCompilerPluginClasspath kotlinCompilerPluginClasspathAndroidNativeArm64Main kotlinCompilerPluginClasspathAndroidNativeArm64Test kotlinCompilerPluginClasspathAndroidNativeX64Main kotlinCompilerPluginClasspathAndroidNativeX64Test kotlinCompilerPluginClasspathIosArm64Main kotlinCompilerPluginClasspathIosArm64Test kotlinCompilerPluginClasspathIosX64Main kotlinCompilerPluginClasspathIosX64Test kotlinCompilerPluginClasspathJsMain kotlinCompilerPluginClasspathJsTest kotlinCompilerPluginClasspathJvmMain kotlinCompilerPluginClasspathJvmTest kotlinCompilerPluginClasspathLinuxX64Main kotlinCompilerPluginClasspathLinuxX64Test kotlinCompilerPluginClasspathMetadataMain kotlinCompilerPluginClasspathMingwX64Main kotlinCompilerPluginClasspathMingwX64Test kotlinKlibCommonizerClasspath kotlinNativeCompilerPluginClasspath kotlinScriptDef kotlinScriptDefExtensions ksp kspAndroidNativeArm64 kspAndroidNativeArm64Test kspAndroidNativeX64 kspAndroidNativeX64Test kspCommonMainMetadata kspIosArm64 kspIosArm64Test kspIosX64 kspIosX64Test kspJs kspJsTest kspJvm kspJvmTest kspLinuxX64 kspLinuxX64Test kspMingwX64 kspMingwX64Test linuxX64ApiElements linuxX64CInteropApiElements linuxX64CompilationApi linuxX64CompilationCompileOnly linuxX64CompilationDependenciesMetadata linuxX64CompilationImplementation linuxX64CompilationRuntimeOnly linuxX64CompileKlibraries linuxX64MainApi linuxX64MainApiDependenciesMetadata linuxX64MainCompileOnly linuxX64MainCompileOnlyDependenciesMetadata linuxX64MainImplementation linuxX64MainImplementationDependenciesMetadata linuxX64MainIntransitiveDependenciesMetadata linuxX64MainRuntimeOnly linuxX64MetadataElements linuxX64SourcesElements linuxX64TestApi linuxX64TestApiDependenciesMetadata linuxX64TestCompilationApi linuxX64TestCompilationCompileOnly linuxX64TestCompilationDependenciesMetadata linuxX64TestCompilationImplementation linuxX64TestCompilationRuntimeOnly linuxX64TestCompileKlibraries linuxX64TestCompileOnly linuxX64TestCompileOnlyDependenciesMetadata linuxX64TestImplementation linuxX64TestImplementationDependenciesMetadata linuxX64TestIntransitiveDependenciesMetadata linuxX64TestRuntimeOnly metadataApiElements metadataCompilationApi metadataCompilationCompileOnly metadataCompilationImplementation metadataCompilationRuntimeOnly metadataCompileClasspath metadataSourcesElements mingwX64ApiElements mingwX64CInteropApiElements mingwX64CompilationApi mingwX64CompilationCompileOnly mingwX64CompilationDependenciesMetadata mingwX64CompilationImplementation mingwX64CompilationRuntimeOnly mingwX64CompileKlibraries mingwX64MainApi mingwX64MainApiDependenciesMetadata mingwX64MainCompileOnly mingwX64MainCompileOnlyDependenciesMetadata mingwX64MainImplementation mingwX64MainImplementationDependenciesMetadata mingwX64MainIntransitiveDependenciesMetadata mingwX64MainRuntimeOnly mingwX64MetadataElements mingwX64SourcesElements mingwX64TestApi mingwX64TestApiDependenciesMetadata mingwX64TestCompilationApi mingwX64TestCompilationCompileOnly mingwX64TestCompilationDependenciesMetadata mingwX64TestCompilationImplementation mingwX64TestCompilationRuntimeOnly mingwX64TestCompileKlibraries mingwX64TestCompileOnly mingwX64TestCompileOnlyDependenciesMetadata mingwX64TestImplementation mingwX64TestImplementationDependenciesMetadata mingwX64TestIntransitiveDependenciesMetadata mingwX64TestRuntimeOnly runtimeClasspath runtimeOnly testAnnotationProcessor testCompileClasspath testCompileOnly testImplementation testKotlinScriptDef testKotlinScriptDefExtensions testRuntimeClasspath testRuntimeOnly
List of targets:
Copy code
[androidNativeArm64, androidNativeX64, iosArm64, iosX64, js, jvm, linuxX64, metadata, mingwX64]
List of sourceSets:
Copy code
androidNativeArm64Main
androidNativeArm64Test
androidNativeX64Main
androidNativeX64Test
commonMain
commonTest
iosArm64Main
iosArm64Test
iosMain
iosTest
iosX64Main
iosX64Test
jsMain
jsTest
jvmMain
jvmTest
linuxX64Main
linuxX64Test
mingwX64Main
mingwX64Test
Tasks:
@Jiaxiang, sorry to bother you, may I ask you to help me understand how does it work please Thank you!
j

Jiaxiang

03/25/2024, 8:30 PM
if you can execute the task
compileIosMainKotlinCommonMainMetadata
then you should be able to execute
kspIosMainKotlinCommonMainMetadata
d

Dmytro Serdiuk

03/25/2024, 8:32 PM
Thanks for the answer, but I don’t understand, why CommonMain is contained in provided task names by you(
j

Jiaxiang

03/25/2024, 8:36 PM
what ksp’s gradle plugin does is to substitute the
compile
with
ksp
in the compile task name as the KSP task name.
d

Dmytro Serdiuk

03/25/2024, 9:24 PM
Thank you, but I don’t see any ksp tasks for compileIosMainKotlinMetadata task(
As you could see in the tasks list above(
j

Jiaxiang

03/25/2024, 11:12 PM
I don’t think any KSP tasks are being listed in the intellij gradle task list, you need to type it manually in command line to call it.
d

Dmytro Serdiuk

03/25/2024, 11:13 PM
Thank you!
Sorry for the long thread, unfortunately from my point of view the documentation has gaps, unclear statements and sometimes just outdated. It takes time to understand. Thank you very much for every your support!
👍 1
2 Views