I’m trying to find a way to detect if a binary is ...
# kotlin-native
t
I’m trying to find a way to detect if a binary is debug or release, so I can disable/enable logging. I tried something like this:
Copy code
val commonMain by sourceSets.getting
val iosMain by sourceSets.creating {
    dependsOn(commonMain)
    dependencies {
        // iOS dependencies
    }
}
val iosDebug by sourceSets.creating {
    dependsOn(iosMain)
}
val iosRelease by sourceSets.creating {
    dependsOn(iosMain)
}
targetFromPreset(iosTarget, "ios") {
    val debugCompilation = compilations.create("debug")
    val releaseCompilation = compilations.create("release")

    binaries {
        framework("common", listOf(DEBUG)) {
            compilation = debugCompilation
        }
        framework("common", listOf(RELEASE)) {
            compilation = releaseCompilation
        }
    }
}
I think this should work, I can use
expect
in iosMain and
actual
in iosDebug/iosRelease. However, the iosTest task I have throws an error it cannot find the
actual
implementation for the
expect
property. This is probably because the test uses iosMain instead of iosDebug. Is there a way to change that?
If there is another way to detect debug/release, instead of multiple sourcesets, please let me know. This is where I got the idea to use multiple sourcesets: https://github.com/JetBrains/kotlin-native/issues/2562#issuecomment-456395263
r
You could try using BuildKonfig, although I don't know if it needs updates to work with 1.3.40 https://github.com/yshrsmz/BuildKonfig
👍 1
k
That’s kind of cool. Will check that out myself
t
@russhwolf That looks really interesting, I will look into it. Still would like to know of another way without depending on plugins. I don’t want to run into compatibility issues when updating Kotlin. So if anyone knows how to fix the sourcesets for the tests, let me know please.
@russhwolf just tried out BuildKonfig and it works perfectly with Kotlin 1.3.41. I used the flavor feature to pass command line arguments from XCode (different targets). I’m still interested how I could make the sourcesets work for the tests in my project.