https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
z

zt

10/31/2023, 4:58 AM
How would I add arm64 support to my native linux x64 project? Currently I have this in my gradle config
Copy code
linuxX64("linux") {
        binaries {
            executable("prism") {
                entryPoint = "main"
            }
        }
    }
j

Jeff Lockhart

10/31/2023, 6:29 AM
Change to:
Copy code
linuxX64 {
    binaries {
        executable("prism") {
            entryPoint = "main"
        }
    }
}
linuxArm64 {
    binaries {
        executable("prism") {
            entryPoint = "main"
        }
    }
}
If you don't have any custom source set hierarchy applied, then you can use the default template to have both linuxX64 and linuxArm64 depend on the linux source set. With Kotlin <1.9.20 you can apply the default template with:
Copy code
targetHierarchy.default()
Or it will be applied by default in Kotlin 1.9.20.
z

zt

10/31/2023, 8:18 PM
Can I do the binaries configuration on both? so I don't need duplicate code
j

Jeff Lockhart

11/01/2023, 6:55 AM
Copy code
listOf(
    linuxX64(),
    linuxArm64()
).forEach {
    it.binaries {
        executable("prism") {
            entryPoint = "main"
        }
    }
}
z

zt

11/01/2023, 8:07 PM
I'm having some issues with this.
Copy code
kotlin {
    listOf(
        linuxX64(),
        linuxArm64()
    ).forEach {
        it.binaries {
            executable("prism") {
                entryPoint = "main"
            }
        }
    }

    sourceSets {
        linuxMain {
            dependencies {
                implementation(projects.common)
                implementation(libs.clikt)
                implementation(libs.kotlin.coroutines.core)
                implementation(libs.bundles.ktoml)
                implementation(libs.bundles.ktor)
            }
        }
    }
}
Cannot access 'com.akuleshov7.ktoml.source.TomlSourceReader' which is a supertype of 'com.akuleshov7.ktoml.file.TomlFileReader'. Check your module classpath for missing or conflicting dependencies
And my c interop is missing
let me try this option i see in the gradle logs
kotlin.mpp.enableCInteropCommonization=true
nvm that causes many many more errors
Common is just this
Copy code
plugins {
    alias(libs.plugins.kotlin.multiplatform)
}

kotlin {
    listOf(
        linuxX64(),
        linuxArm64()
    ).forEach {
        it.compilations.getByName("main") {
            cinterops.create("xlib")
        }
    }
}
j

Jeff Lockhart

11/01/2023, 10:06 PM
I would expect you'll need C interop commonization enabled in order to access the native APIs in your intermediate linux source set. What are the other errors enabling it causes?
z

zt

11/01/2023, 10:36 PM
This is a short snippet of the errors. It seems to be for every implementation
Copy code
Caused by: org.gradle.internal.component.NoMatchingConfigurationSelectionException: No matching variant of com.github.ajalt.clikt:clikt:4.2.1 was found. The consumer was configured to find a library for use during 'kotlin-metadata', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'linux_arm64' but:
  - Variant 'jsApiElements-published' capability com.github.ajalt.clikt:clikt:4.2.1 declares a library for use during 'kotlin-api':
      - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
      - Other compatible attributes:
          - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_arm64')
  - Variant 'jsRuntimeElements-published' capability com.github.ajalt.clikt:clikt:4.2.1 declares a library:
      - Incompatible because this component declares a component for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
      - Other compatible attributes:
          - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_arm64')
  - Variant 'jsSourcesElements-published' capability com.github.ajalt.clikt:clikt:4.2.1:
      - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a library for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
      - Other compatible attributes:
          - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_arm64')
  - Variant 'jvmApiElements-published' capability com.github.ajalt.clikt:clikt:4.2.1 declares a library for use during compile-time:
      - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
      - Other compatible attributes:
          - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_arm64')
  - Variant 'jvmRuntimeElements-published' capability com.github.ajalt.clikt:clikt:4.2.1 declares a library for use during runtime:
      - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
      - Other compatible attributes:
          - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_arm64')
  - Variant 'jvmSourcesElements-published' capability com.github.ajalt.clikt:clikt:4.2.1 declares a component for use during runtime:
      - Incompatible because this component declares documentation, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
      - Other compatible attributes:
          - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
          - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'linux_arm64')
  - Variant 'linuxX64ApiElements-published' capability com.github.ajalt.clikt:clikt:4.2.1 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
      - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_x64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'linux_arm64'
      - Other compatible attribute:
          - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
j

Jeff Lockhart

11/01/2023, 10:49 PM
This error indicates you're using a dependency which doesn't include the linuxArm64 target, specifically https://github.com/ajalt/clikt in this case. You'll need to be sure all your dependencies support the target before you're able to add support yourself.
z

zt

11/01/2023, 10:49 PM
oh
j

Jeff Lockhart

11/01/2023, 10:58 PM
For most dependencies that already support linuxX64, it should be straightforward to add linuxArm64 as well. You might be able to contribute the target in a PR. Many libraries have been adding support, since it's now officially a tier 2 target. The real issue has been being able to run CI tests on the platform. I was able to add *linuxArm64* support to my own library recently, once support became available in all dependencies.
10 Views