When updating to use kotlin 1.3.71 from 1.3.61 I s...
# kotlin-native
b
When updating to use kotlin 1.3.71 from 1.3.61 I switched to declaring generics with
Copy code
tasks.withType<KotlinCompile> {
  kotlinOptions.freeCompilerArgs += "-Xobjc-generics"
}
instead of
extraOpts("-Xobjc-generics")
, but I am seeing types returned as Any where I did not before. Any tips on the right way to enable generics for 1.3.71?
a
Hello, @Brendan Weinstein! Try something like
Copy code
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile> {
        this.compilation.kotlinOptions { freeCompilerArgs = freeCompilerArgs + "-Xobjc-generics" }
    }
r
I have it in project build.gradle.kts in KMP project like this
Copy code
buildscript {
  repositories {
    ...
  }
  dependencies {
    ...
  }
}
allprojects {
  repositories{
    ...
  }
  pluginManager.withPlugin("kotlin-multiplatform") {
        val kotlinExtension = project.extensions.getByName("kotlin") as org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
        val uniqueName = "${project.group}.${project.name}"
        kotlinExtension.targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget::class.java) {
            // todo add ("-linker-options", "-lsqlite3")
            compilations["main"].kotlinOptions.freeCompilerArgs += listOf("-Xobjc-generics","-module-name", uniqueName)
        }
    }
}
unfortunetly as you can see my todo I don’t know how to add “-lsqlite3” flag to linker options
a
Maybe you can try to do it like that
Copy code
targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget::class.java) {
        binaries.configureEach{
            linkerOpts("-lsqlite3")
            freeCompilerArgs += listOf("-Xobjc-generics","-module-name", "a")
        }
    }
🙏 1
👍 2
b
Yup that works. I can also do
Copy code
compilations.forEach {
  it.kotlinOptions { freeCompilerArgs = freeCompilerArgs + "-Xobjc-generics" }
}
If there's a quick answer, just curious what the difference between a binary and a compilation. There's no
gradle dsl
documentation :/
a
IIRC this is about Gradle plugin two-staged compilation process. When you are targeting Kotlin/Native target, you got a
compileKotlin<Target>
task, that generates a
.klib
file, and
link<Debug|Release><BinaryKind><Target>
, which produces a binary file from the
.klib
. Both targets include K/N compiler call inside. I assume that both flags should be specified per binary according to this doc(on Objective-C generics) and this one(see Configuring binaries).
Gradle noob here. What would be the groovy equivalent of this? This is what my build script looks like:
Copy code
kotlin {
  targets {
    fromPreset(presets.macosX64, 'macos') {    
      binaries {
        framework('shared') {
          isStatic = false
          linkerOpts.add("-lsqlite3")
        }
      }
    }
    ...
a
Hello, @saket! Maybe something like this should work for you?
s
Yes this works, but will the syntax change if I’m using cocoapods that handles generation of a framework?
a
I think it should not, as you set this argument per compilation, not per binary.
s
Got it, thank you!