Skip to content
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

Make mordant-omnibus publish on all MPP targets #228

Merged
merged 9 commits into from
Sep 7, 2024
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
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/mordant-js-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ kotlin {
sourceSets {
val jsCommonMain by creating { dependsOn(commonMain.get()) }
jsMain.get().dependsOn(jsCommonMain)
getByName("wasmJsMain").dependsOn(jsCommonMain)
wasmJsMain.get().dependsOn(jsCommonMain)
}
}

Expand Down
6 changes: 1 addition & 5 deletions buildSrc/src/main/kotlin/mordant-mpp-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
plugins {
id("mordant-kotlin-conventions")
id("mordant-js-conventions")
id("mordant-native-conventions")
}

kotlin {
jvm()
id("mordant-js-conventions")
}
10 changes: 0 additions & 10 deletions buildSrc/src/main/kotlin/mordant-native-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
plugins {
kotlin("multiplatform")
id("mordant-native-core-conventions")
}

Expand All @@ -12,13 +11,4 @@ kotlin {
watchosArm64()
watchosX64()
watchosSimulatorArm64()

sourceSets {
for (target in listOf(
"tvosX64", "tvosArm64", "tvosSimulatorArm64",
"watchosArm32", "watchosArm64", "watchosX64", "watchosSimulatorArm64",
)) {
sourceSets.getByName(target + "Main").kotlin.srcDirs("src/posixSharedMain/kotlin")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ plugins {
}

kotlin {
applyDefaultHierarchyTemplate()

linuxX64()
linuxArm64()
macosX64()
Expand All @@ -21,27 +23,4 @@ kotlin {
// watchosDeviceArm64()
// watchosX64()
// watchosSimulatorArm64()

applyDefaultHierarchyTemplate()

// https://kotlinlang.org/docs/multiplatform-hierarchy.html#see-the-full-hierarchy-template
sourceSets {
val posixMain by creating { dependsOn(nativeMain.get()) }
linuxMain.get().dependsOn(posixMain)
appleMain.get().dependsOn(posixMain)
val appleNonDesktopMain by creating { dependsOn(appleMain.get()) }
for (target in listOf(iosMain, tvosMain, watchosMain)) {
target.get().dependsOn(appleNonDesktopMain)
}
// Kotlin 2.0 changed the way MPP is compiled, so instead of copying shared sources to each
// target, it compiles intermediate sources separately. That means that code that previously
// compiled is broken due to errors like "declaration is using numbers with different bit
// widths". So we copy the shared sources to each target manually.
for (target in listOf(
"linuxX64", "linuxArm64",
"macosX64", "macosArm64",
)) {
sourceSets.getByName(target + "Main").kotlin.srcDirs("src/posixSharedMain/kotlin")
}
}
}
1 change: 1 addition & 0 deletions mordant-coroutines/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
}

kotlin {
jvm()
sourceSets {
commonMain.dependencies {
api(project(":mordant"))
Expand Down
Empty file.
10 changes: 9 additions & 1 deletion mordant-omnibus/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

// We don't use all the conventions plugins here since applying the mpp=convention results in
// "IllegalStateException: Configuration already finalized for previous property values"
plugins {
id("mordant-kotlin-conventions")
kotlin("multiplatform")
id("mordant-native-conventions")
id("mordant-publishing-conventions")
}

kotlin {
jvm()
js { nodejs() } // we don't have any code, but it's an error not to pick aa JS environment
@OptIn(ExperimentalWasmDsl::class)
wasmJs { nodejs() }
sourceSets {
commonMain.dependencies {
api(project(":mordant"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.github.ajalt.mordant.internal

// This intentionally empty file is a workaround for KT-52344, which fails to publish a target with
// no source files
23 changes: 23 additions & 0 deletions mordant/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
}

kotlin {
jvm()
sourceSets {
all {
languageSettings.optIn("kotlinx.cinterop.ExperimentalForeignApi")
Expand All @@ -19,5 +20,27 @@ kotlin {
jvmTest.dependencies {
api(libs.systemrules)
}
// Kotlin 2.0 changed the way MPP is compiled, so instead of copying shared sources to each
// target, it compiles intermediate sources separately. That means that code that previously
// compiled is broken due to errors like "declaration is using numbers with different bit
// widths". So we copy the shared sources to each target manually.
sourceSets {
// https://kotlinlang.org/docs/multiplatform-hierarchy.html#see-the-full-hierarchy-template
val posixMain by creating { dependsOn(nativeMain.get()) }
linuxMain.get().dependsOn(posixMain)
appleMain.get().dependsOn(posixMain)
val appleNonDesktopMain by creating { dependsOn(appleMain.get()) }
for (target in listOf(iosMain, tvosMain, watchosMain)) {
target.get().dependsOn(appleNonDesktopMain)
}
for (target in listOf(
"linuxX64", "linuxArm64",
"macosX64", "macosArm64",
"tvosX64", "tvosArm64", "tvosSimulatorArm64",
"watchosArm32", "watchosArm64", "watchosX64", "watchosSimulatorArm64",
)) {
sourceSets.getByName(target + "Main").kotlin.srcDirs("src/posixSharedMain/kotlin")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,24 @@ internal actual fun readFileIfExists(filename: String): String? {
}
}

private const val DUMB_RAW_MODE_ERROR = """Cannot find terminal interface that supports raw mode.

You need at least one of the `:mordant-jvm-*` modules on your classpath.
The `:mordant` module includes all of them as transitive dependencies.
If you're using `:mordant-core` instead, you need to add one or more manually.
If you're using only `:mordant-jvm-ffm`, make sure you're running with JVM 22+, and are passing
`--enable-native-access=ALL-UNNAMED` as a JVM argument.
"""

private object DumbTerminalInterface : StandardTerminalInterface() {
override fun stdoutInteractive(): Boolean = true
override fun stdinInteractive(): Boolean = true
override fun getTerminalSize(): Size? = null
override fun enterRawMode(mouseTracking: MouseTracking): AutoCloseable {
throw UnsupportedOperationException("Cannot enter raw mode on this system")
throw UnsupportedOperationException(DUMB_RAW_MODE_ERROR)
}

override fun readInputEvent(timeout: TimeMark, mouseTracking: MouseTracking): InputEvent? {
throw UnsupportedOperationException("Cannot read input on this system")
throw UnsupportedOperationException(DUMB_RAW_MODE_ERROR)
}
}