Skip to content

Commit

Permalink
enable KlibsCrossCompilation for kmp example
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-enko committed Dec 4, 2024
1 parent 75bffdf commit 08f531b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ class ExampleProjectsTest {
ExampleProject.CompositeBuild -> ":build"
else -> ":dokkaGenerate"
}

init {
updateGradleProperties()
}

private fun updateGradleProperties() {
when (exampleProjectName) {
ExampleProject.KotlinMultiplatform -> {
project.gradleProperties {
// kotlin.native.enableKlibsCrossCompilation must be set to `true`
// otherwise Kotlin can't generate a Klib for Coroutines in macosMain
// when generating on Linux machines, resulting in 'Error class: unknown class'
// for CoroutineScope appearing in the generated docs.
kotlin.native.enableKlibsCrossCompilation = true
}
}

else -> {}
}

project.runner.writeGradleProperties(project.gradleProperties)
}
}

/**
Expand Down Expand Up @@ -170,9 +192,8 @@ class ExampleProjectsTest {
format = "html",
)

verifyNoUnknownClassErrorsInHtmlFiles(
testCase = testCase,
format = "html",
verifyNoUnknownClassErrorsInHtml(
dokkaOutputDir = testCase.dokkaOutputDir.resolve("html")
)
}

Expand Down Expand Up @@ -237,12 +258,9 @@ class ExampleProjectsTest {
}
}

private fun verifyNoUnknownClassErrorsInHtmlFiles(
testCase: TestCase,
format: String,
private fun verifyNoUnknownClassErrorsInHtml(
dokkaOutputDir: Path,
) {
val dokkaOutputDir = testCase.dokkaOutputDir.resolve(format)

withClue("expect no 'unknown class' message in output files") {
val htmlFiles = dokkaOutputDir.walk()
.filter { it.isRegularFile() && it.extension == "html" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ data class GradlePropertiesBuilder(
/** Kotlin specific options. */
data class KotlinArgs(
var mppStabilityWarning: Boolean? = true,
)
val native: NativeArgs = NativeArgs(),
) {

data class NativeArgs(
var enableKlibsCrossCompilation: Boolean? = null
)
}

/** Dokka specific options. */
data class DokkaArgs(
Expand Down Expand Up @@ -105,6 +111,7 @@ data class GradlePropertiesBuilder(

with(kotlin) {
putNotNull("kotlin.mpp.stability.nowarn", mppStabilityWarning?.let { !it })
putNotNull("kotlin.native.enableKlibsCrossCompilation", native.enableKlibsCrossCompilation)
}

with(gradle) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
kotlin("multiplatform") version "1.9.25"
kotlin("multiplatform") version "2.1.0"
id("org.jetbrains.dokka") version "2.0.20-SNAPSHOT"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ org.gradle.parallel=true

org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true

# kotlin.native.enableKlibsCrossCompilation must be set to `true`
# otherwise Kotlin can't generate a Klib for Coroutines in macosMain
# when generating on Linux machines, resulting in 'Error class: unknown class'
# for CoroutineScope appearing in the generated docs.
kotlin.native.enableKlibsCrossCompilation=true

0 comments on commit 08f531b

Please sign in to comment.