Browse Source

Simplify kapp build

app-api
Nikolay Igotti 3 years ago
parent
commit
3b5fd17dd3
  1. 269
      components/Kapp/demo/build.gradle.kts
  2. 2
      components/Kapp/demo/src/darwinMain/kotlin/org/jetbrains/compose/kapp/demo/Simple.darwin.kt
  3. 11
      components/Kapp/library/build.gradle.kts
  4. 2
      components/gradle.properties

269
components/Kapp/demo/build.gradle.kts

@ -6,68 +6,104 @@ plugins {
id("org.jetbrains.compose")
}
val withNative = true
enum class OS {
IOS,
WINDOWS,
LINUX,
MACOS,
BROWSER
}
kotlin {
jvm("desktop")
js(IR) {
browser()
binaries.executable()
}
enum class ARCH {
X64,
ARM64,
JS
}
if (withNative) {
macosX64 {
binaries {
executable {
entryPoint = "org.jetbrains.compose.kapp.demo.main"
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
)
}
}
enum class BACKEND {
JVM,
NATIVE,
JS
}
data class Platform(val os: OS, val arch: ARCH, val backend: BACKEND)
val JVM_ALL = listOf(
Platform(OS.LINUX, ARCH.X64, BACKEND.JVM),
Platform(OS.WINDOWS, ARCH.X64, BACKEND.JVM),
Platform(OS.MACOS, ARCH.X64, BACKEND.JVM),
Platform(OS.MACOS, ARCH.ARM64, BACKEND.JVM)
)
val MACOS_ALL = listOf(
Platform(OS.MACOS, ARCH.X64, BACKEND.NATIVE),
Platform(OS.MACOS, ARCH.ARM64, BACKEND.NATIVE)
)
val IOS_ALL = listOf(
Platform(OS.IOS, ARCH.X64, BACKEND.NATIVE),
Platform(OS.IOS, ARCH.ARM64, BACKEND.NATIVE)
)
val WEB = Platform(OS.BROWSER, ARCH.JS, BACKEND.JS)
fun org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget.makeNativeDarwinTarget(entry: String) {
binaries {
executable {
entryPoint = entry
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
)
}
}
}
/*
macosArm64 {
binaries {
executable {
entryPoint = "org.jetbrains.compose.kapp.demo.main"
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
)
}
val allSourceSets = mutableMapOf<Platform, org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>()
fun org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension.kapp(
entryPoint: String,
platforms: List<Platform>
) {
platforms.groupBy { it.backend }.forEach {
when (it.key) {
BACKEND.JVM -> {
jvm("desktop")
}
} */
iosX64("uikitX64") {
binaries {
executable {
entryPoint = "org.jetbrains.compose.kapp.demo.main"
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
)
BACKEND.JS -> {
js(IR) {
browser()
binaries.executable()
}
}
}
/*
iosArm64("uikitArm64") {
binaries {
executable {
entryPoint = "main"
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
)
BACKEND.NATIVE -> {
it.value.forEach { platform ->
when {
platform.os == OS.MACOS && platform.arch == ARCH.X64 -> {
macosX64 {
makeNativeDarwinTarget(entryPoint)
}
}
platform.os == OS.MACOS && platform.arch == ARCH.ARM64 -> {
macosArm64 {
makeNativeDarwinTarget(entryPoint)
}
}
platform.os == OS.IOS && platform.arch == ARCH.X64 -> {
iosX64("uikitX64") {
makeNativeDarwinTarget(entryPoint)
}
}
platform.os == OS.IOS && platform.arch == ARCH.ARM64 -> {
iosArm64("uikitArm64") {
makeNativeDarwinTarget(entryPoint)
}
}
}
}
}
}*/
}
}
sourceSets {
@ -76,48 +112,92 @@ kotlin {
implementation(project(":Kapp:library"))
}
}
platforms.groupBy { it.backend }.forEach {
when (it.key) {
BACKEND.JVM -> {
val desktopMain by getting {
dependsOn(commonMain)
dependencies {
implementation(compose.desktop.currentOs)
}
}
it.value.forEach { platform ->
allSourceSets[platform] = desktopMain
}
val desktopMain by getting {
dependsOn(commonMain)
dependencies {
implementation(compose.desktop.currentOs)
}
BACKEND.JS -> {
val jsMain by getting {
dependsOn(commonMain)
}
it.value.forEach { platform ->
allSourceSets[platform] = jsMain
}
}
BACKEND.NATIVE -> {
val darwinMain by creating {
dependsOn(commonMain)
}
val macosMain by creating {
dependsOn(darwinMain)
}
val uikitMain by creating {
dependsOn(darwinMain)
}
it.value.forEach { platform ->
when {
platform.os == OS.MACOS && platform.arch == ARCH.X64 -> {
val macosX64Main by getting {
dependsOn(macosMain)
}
allSourceSets[platform] = macosX64Main
}
platform.os == OS.MACOS && platform.arch == ARCH.ARM64 -> {
val macosArm64Main by getting {
dependsOn(macosMain)
}
allSourceSets[platform] = macosArm64Main
}
platform.os == OS.IOS && platform.arch == ARCH.X64 -> {
val uikitX64Main by getting {
dependsOn(uikitMain)
}
allSourceSets[platform] = uikitX64Main
}
platform.os == OS.IOS && platform.arch == ARCH.ARM64 -> {
val uikitArm64Main by getting {
dependsOn(uikitMain)
}
allSourceSets[platform] = uikitArm64Main
}
}
}
}
}
}
}
val jsMain by getting
if (withNative) {
val darwinMain by creating {
dependsOn(commonMain)
}
val macosMain by creating {
dependsOn(darwinMain)
}
val macosX64Main by getting {
dependsOn(macosMain)
}
/*
val macosArm64Main by getting {
dependsOn(macosMain)
} */
val uikitMain by creating {
dependsOn(darwinMain)
}
// TODO: remove those two.
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
val uikitX64Main by getting {
dependsOn(uikitMain)
}
//val uikitArm64Main by getting {
// dependsOn(uikitMain)
//}
}
rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension> {
versions.webpackDevServer.version = "4.0.0"
versions.webpackCli.version = "4.9.0"
nodeVersion = "16.0.0"
}
}
kotlin {
kapp(
entryPoint = "org.jetbrains.compose.kapp.demo.main",
JVM_ALL + WEB + MACOS_ALL + IOS_ALL
)
}
// TODO: ensure that those two are also configured by `kapp` function.
compose.desktop {
application {
mainClass = "org.jetbrains.compose.kapp.demo.Simple_desktopKt"
@ -126,18 +206,5 @@ compose.desktop {
compose.experimental {
web.application
if (withNative)
uikit.application
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
afterEvaluate {
rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension> {
versions.webpackDevServer.version = "4.0.0"
versions.webpackCli.version = "4.9.0"
nodeVersion = "16.0.0"
}
uikit.application
}

2
components/Kapp/demo/src/darwinMain/kotlin/org/jetbrains/compose/kapp/demo/Simple.darwin.kt

@ -1,5 +1,3 @@
package org.jetbrains.compose.kapp.demo
import androidx.compose.runtime.Composable
fun main() = simpleDemoApp()

11
components/Kapp/library/build.gradle.kts

@ -17,9 +17,9 @@ kotlin {
if (withNative) {
iosX64("uikitX64")
//iosArm64("uikitArm64")
iosArm64("uikitArm64")
macosX64()
// macosArm64()
macosArm64()
}
sourceSets {
@ -51,10 +51,9 @@ kotlin {
dependsOn(macosMain)
}
/*
val macosArm64Main by getting {
dependsOn(macosMain)
} */
}
val uikitMain by creating {
dependsOn(darwinMain)
@ -63,10 +62,10 @@ kotlin {
val uikitX64Main by getting {
dependsOn(uikitMain)
}
/*
val uikitArm64Main by getting {
dependsOn(uikitMain)
} */
}
}
}
}

2
components/gradle.properties

@ -5,7 +5,7 @@ kotlin.code.style=official
# __KOTLIN_COMPOSE_VERSION__
kotlin.version=1.6.10
# __LATEST_COMPOSE_RELEASE_VERSION__
compose.version=1.2.0-alpha01-dev602
compose.version=1.2.0-alpha01-dev606
# TODO: remove after 1.6.20
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false

Loading…
Cancel
Save