Skip to content

Enable allWarningsAsErrors compiler option for :runtime and :examples:kotlin-multiplatform projects #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/kotlin-multiplatform/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ kotlin {

applyDefaultHierarchyTemplate()

targets.configureEach {
compilations.configureEach {
kotlinOptions.allWarningsAsErrors = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compilerOptions can be used instead of kotlinOptions to avoid further changes when the latter is deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.
But configuring compilerOptions in Groovy is not as handy as in Kotlin.
It is not possible to call compilerOptions.configure {} function because of resolution ambiguity between fun configure(configuration: T.() -> Unit) and fun configure(configuration: Action<T>).
So the compilerOptions.options needs to be configured directly.

}
}

sourceSets.configureEach {
languageSettings {
progressiveMode = true
Expand Down
15 changes: 12 additions & 3 deletions runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ kotlin {

targets.configureEach {
compilations.configureEach {
kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes"
compilerOptions.options.with {
allWarningsAsErrors.set(true)
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
}

Expand All @@ -54,8 +57,6 @@ kotlin {
resources.srcDirs = ["$it.name/resources"]
languageSettings {
progressiveMode = true
optIn('kotlin.experimental.ExperimentalNativeApi')
optIn("kotlinx.cinterop.ExperimentalForeignApi")
}
}

Expand Down Expand Up @@ -108,3 +109,11 @@ if (project.findProperty("publication_repository") == "space") {
tasks.withType(KotlinNativeCompile).matching { it.name.toLowerCase().contains("test") }.configureEach {
it.dependsOn(tasks.withType(Sign))
}

tasks.withType(KotlinNativeCompile).configureEach {
compilerOptions.freeCompilerArgs.addAll(
"-opt-in=kotlin.experimental.ExperimentalNativeApi",
"-opt-in=kotlin.native.runtime.NativeRuntimeApi",
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could continue using languageSettings.optIn DSL but move it to nativeMain source set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this approach doesn't work. The opt-ins are not passed to the dependent source sets automatically.
This causes:

Inconsistent settings for Kotlin source sets: 'androidNativeArm32Main' depends on 'nativeMain'
  'androidNativeArm32Main': set of opt-in annotations in use is []
  'nativeMain': set of opt-in annotations in use is [kotlin.experimental.ExperimentalNativeApi, kotlin.native.runtime.NativeRuntimeApi, kotlinx.cinterop.ExperimentalForeignApi]
  The dependent source set must use all opt-in annotations that its dependency uses.

)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kotlinx.benchmark.native

import kotlinx.benchmark.*
import kotlin.native.internal.GC
import kotlin.native.runtime.GC
import kotlin.time.*

class NativeExecutor(
Expand Down Expand Up @@ -218,7 +218,6 @@ class NativeExecutor(
return getStackTrace().joinToString("\n") + "\nCause: ${nested.message}\n" + nested.stacktrace()
}

@OptIn(ExperimentalTime::class)
private inline fun measure(
cycles: Int,
nativeGCAfterIteration: Boolean,
Expand All @@ -239,7 +238,6 @@ class NativeExecutor(
return duration.toDouble(DurationUnit.NANOSECONDS) / cycles
}

@OptIn(ExperimentalTime::class)
private inline fun <T> measureWarmup(
name: String,
config: BenchmarkConfiguration,
Expand Down