Skip to content

Commit de1bdf6

Browse files
committed
Allow specifying arbitrary additional compiler flags
1 parent 6bbfc2b commit de1bdf6

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

buildSrc/src/main/kotlin/CommunityProjectsBuild.kt

+10
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,13 @@ fun KotlinCommonCompilerOptions.configureKotlinUserProject() {
181181
"-Xrender-internal-diagnostic-names", // render the diagnostic names in CLI
182182
)
183183
}
184+
185+
/**
186+
* Additional compiler flags passed on a case-by-case basis. Should be applied after the other flags.
187+
* See <https://github.com/Kotlin/kotlinx.coroutines/pull/4392#issuecomment-2775630200>
188+
*/
189+
fun KotlinCommonCompilerOptions.addExtraCompilerFlags(project: Project) {
190+
(project.rootProject.properties["kotlin_additional_cli_options"] as? String)?.split(" ")?.forEach {
191+
if (it.isNotEmpty()) freeCompilerArgs.add(it)
192+
}
193+
}

buildSrc/src/main/kotlin/configure-compilation-conventions.gradle.kts

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ configure(subprojects) {
2727
freeCompilerArgs.addAll(
2828
"-Xno-param-assertions",
2929
"-Xno-call-assertions",
30-
"-Xno-receiver-assertions"
30+
"-Xno-receiver-assertions",
31+
"-Xjvm-default=disable",
3132
)
3233
}
3334
if (this@configureEach is KotlinNativeCompile) {
@@ -37,6 +38,7 @@ configure(subprojects) {
3738
"kotlin.experimental.ExperimentalNativeApi",
3839
)
3940
}
41+
addExtraCompilerFlags(project)
4042
}
4143

4244
}

buildSrc/src/main/kotlin/kotlin-multiplatform-conventions.gradle.kts

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ kotlin {
1515
jvm {
1616
compilations.all {
1717
compileTaskProvider.configure {
18-
compilerOptions {
19-
jvmTarget = JvmTarget.JVM_1_8
20-
freeCompilerArgs.addAll("-Xjvm-default=disable")
21-
}
18+
compilerOptions.jvmTarget = JvmTarget.JVM_1_8
2219
}
2320
}
2421
}

0 commit comments

Comments
 (0)