Browse Source

Add OS arch to plugin provided dependencies (#113)

* Add OS arch to plugin provided dependencies

* Delete DesktopDependencies#all
pull/128/head 0.2.0-build127
Alexey Tsvetkov 4 years ago committed by GitHub
parent
commit
a71e6b6378
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt
  2. 29
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/osUtils.kt

34
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt

@ -8,6 +8,7 @@ import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.plugins.ExtensionAware
import org.jetbrains.compose.desktop.DesktopExtension
import org.jetbrains.compose.desktop.application.internal.configureApplicationImpl
import org.jetbrains.compose.desktop.application.internal.currentTarget
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@ -61,20 +62,29 @@ class ComposePlugin : Plugin<Project> {
object DesktopDependencies {
val common = composeDependency("org.jetbrains.compose.desktop:desktop")
val linux = composeDependency("org.jetbrains.compose.desktop:desktop-jvm-linux")
val windows = composeDependency("org.jetbrains.compose.desktop:desktop-jvm-windows")
val macos = composeDependency("org.jetbrains.compose.desktop:desktop-jvm-macos")
val all = composeDependency("org.jetbrains.compose.desktop:desktop-jvm-all")
val linux_x64 = composeDependency("org.jetbrains.compose.desktop:desktop-jvm-linux-x64")
val windows_x64 = composeDependency("org.jetbrains.compose.desktop:desktop-jvm-windows-x64")
val macos_x64 = composeDependency("org.jetbrains.compose.desktop:desktop-jvm-macos-x64")
val macos_arm64 = composeDependency("org.jetbrains.compose.desktop:desktop-jvm-macos-arm64")
@Deprecated(
"compose.desktop.linux is deprecated, use compose.desktop.linux_x64 instead",
replaceWith = ReplaceWith("linux_x64")
)
val linux = linux_x64
@Deprecated(
"compose.desktop.windows is deprecated, use compose.desktop.windows_x64 instead",
replaceWith = ReplaceWith("windows_x64")
)
val windows = windows_x64
@Deprecated(
"compose.desktop.macos is deprecated, use compose.desktop.macos_x64 instead",
replaceWith = ReplaceWith("macos_x64")
)
val macos = macos_x64
val currentOs by lazy {
val os = System.getProperty("os.name")
val artifactOs = when {
os == "Mac OS X" -> "macos"
os.startsWith("Win") -> "windows"
os.startsWith("Linux") -> "linux"
else -> throw Error("Unsupported OS $os")
}
composeDependency("org.jetbrains.compose.desktop:desktop-jvm-$artifactOs")
composeDependency("org.jetbrains.compose.desktop:desktop-jvm-${currentTarget.id}")
}
}
}

29
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/osUtils.kt

@ -1,7 +1,32 @@
package org.jetbrains.compose.desktop.application.internal
internal enum class OS {
Linux, Windows, MacOS
internal enum class OS(val id: String) {
Linux("linux"),
Windows("windows"),
MacOS("macos")
}
internal enum class Arch(val id: String) {
X64("x64"),
Arm64("arm64")
}
internal data class Target(val os: OS, val arch: Arch) {
val id: String
get() = "${os.id}-${arch.id}"
}
internal val currentTarget by lazy {
Target(currentOS, currentArch)
}
internal val currentArch by lazy {
val osArch = System.getProperty("os.arch")
when (osArch) {
"x86_64", "amd64" -> Arch.X64
"aarch64" -> Arch.Arm64
else -> error("Unknown OS arch: $osArch")
}
}
internal val currentOS: OS by lazy {

Loading…
Cancel
Save