You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
243 lines
7.5 KiB
243 lines
7.5 KiB
import org.jetbrains.compose.compose |
|
import org.jetbrains.compose.desktop.application.dsl.TargetFormat |
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget |
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
|
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension |
|
|
|
buildscript { |
|
repositories { |
|
mavenLocal() |
|
mavenCentral() |
|
google() |
|
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") |
|
} |
|
} |
|
|
|
plugins { |
|
kotlin("multiplatform") version "1.6.10" |
|
id("org.jetbrains.compose") version "1.1.0-beta04" |
|
} |
|
|
|
version = "1.0-SNAPSHOT" |
|
|
|
val resourcesDir = "$buildDir/resources" |
|
val skikoWasm by configurations.creating |
|
|
|
dependencies { |
|
skikoWasm("org.jetbrains.skiko:skiko-js-wasm-runtime:0.6.9") |
|
} |
|
|
|
val unzipTask = tasks.register("unzipWasm", Copy::class) { |
|
destinationDir = file(resourcesDir) |
|
from(skikoWasm.map { zipTree(it) }) |
|
} |
|
|
|
repositories { |
|
mavenLocal() |
|
mavenCentral() |
|
google() |
|
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") |
|
} |
|
|
|
kotlin { |
|
jvm("desktop") |
|
js(IR) { |
|
browser() |
|
binaries.executable() |
|
} |
|
macosX64 { |
|
binaries { |
|
executable { |
|
entryPoint = "main" |
|
freeCompilerArgs += listOf( |
|
"-linker-option", "-framework", "-linker-option", "Metal" |
|
) |
|
} |
|
} |
|
} |
|
macosArm64 { |
|
binaries { |
|
executable { |
|
entryPoint = "main" |
|
freeCompilerArgs += listOf( |
|
"-linker-option", "-framework", "-linker-option", "Metal" |
|
) |
|
} |
|
} |
|
} |
|
iosX64("uikitX64") { |
|
binaries { |
|
executable() { |
|
entryPoint = "main" |
|
freeCompilerArgs += listOf( |
|
"-linker-option", "-framework", "-linker-option", "Metal", |
|
"-linker-option", "-framework", "-linker-option", "CoreText", |
|
"-linker-option", "-framework", "-linker-option", "CoreGraphics" |
|
) |
|
// TODO: the current compose binary surprises LLVM, so disable checks for now. |
|
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode" |
|
} |
|
} |
|
} |
|
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" |
|
) |
|
// TODO: the current compose binary surprises LLVM, so disable checks for now. |
|
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode" |
|
} |
|
} |
|
} |
|
|
|
sourceSets { |
|
val commonMain by getting { |
|
dependencies { |
|
implementation(compose.ui) |
|
implementation(compose.foundation) |
|
implementation(compose.material) |
|
implementation(compose.runtime) |
|
implementation("org.jetbrains.skiko:skiko:0.6.7") |
|
} |
|
} |
|
|
|
val commonTest by getting { |
|
dependencies { |
|
implementation(kotlin("test-common")) |
|
implementation(kotlin("test-annotations-common")) |
|
} |
|
} |
|
|
|
val desktopMain by getting { |
|
dependencies { |
|
implementation(compose.desktop.currentOs) |
|
} |
|
} |
|
|
|
val jsMain by getting { |
|
resources.setSrcDirs(resources.srcDirs) |
|
resources.srcDirs(unzipTask.map { it.destinationDir }) |
|
} |
|
|
|
val nativeMain by creating { |
|
dependsOn(commonMain) |
|
} |
|
val macosMain by creating { |
|
dependsOn(nativeMain) |
|
} |
|
val macosX64Main by getting { |
|
dependsOn(macosMain) |
|
} |
|
val macosArm64Main by getting { |
|
dependsOn(macosMain) |
|
} |
|
val uikitMain by creating { |
|
dependsOn(nativeMain) |
|
} |
|
val uikitX64Main by getting { |
|
dependsOn(uikitMain) |
|
} |
|
val uikitArm64Main by getting { |
|
dependsOn(uikitMain) |
|
} |
|
} |
|
} |
|
|
|
compose.desktop { |
|
application { |
|
mainClass = "Main_desktopKt" |
|
|
|
nativeDistributions { |
|
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) |
|
packageName = "Falling Balls" |
|
packageVersion = "1.0.0" |
|
|
|
windows { |
|
menuGroup = "Compose Examples" |
|
// see https://wixtoolset.org/documentation/manual/v3/howtos/general/generate_guids.html |
|
upgradeUuid = "18159995-d967-4CD2-8885-77BFA97CFA9F" |
|
} |
|
} |
|
} |
|
} |
|
|
|
tasks.withType<KotlinCompile> { |
|
kotlinOptions.jvmTarget = "11" |
|
} |
|
|
|
kotlin { |
|
targets.withType<KotlinNativeTarget> { |
|
binaries.all { |
|
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode" |
|
} |
|
} |
|
} |
|
|
|
// a temporary workaround for a bug in jsRun invocation - see https://youtrack.jetbrains.com/issue/KT-48273 |
|
afterEvaluate { |
|
rootProject.extensions.configure<NodeJsRootExtension> { |
|
versions.webpackDevServer.version = "4.0.0" |
|
versions.webpackCli.version = "4.9.0" |
|
nodeVersion = "16.0.0" |
|
} |
|
} |
|
|
|
enum class Target(val simulator: Boolean, val key: String) { |
|
UIKIT_X64(true, "uikitX64"), UIKIT_ARM64(false, "uikitArm64") |
|
} |
|
|
|
if (System.getProperty("os.name") == "Mac OS X") { |
|
// Create Xcode integration tasks. |
|
val sdkName: String? = System.getenv("SDK_NAME") |
|
|
|
val target = sdkName.orEmpty().let { |
|
when { |
|
it.startsWith("iphoneos") -> Target.UIKIT_ARM64 |
|
it.startsWith("iphonesimulator") -> Target.UIKIT_X64 |
|
else -> Target.UIKIT_X64 |
|
} |
|
} |
|
|
|
val targetBuildDir: String? = System.getenv("TARGET_BUILD_DIR") |
|
val executablePath: String? = System.getenv("EXECUTABLE_PATH") |
|
val buildType = System.getenv("CONFIGURATION")?.let { |
|
org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.valueOf(it.toUpperCase()) |
|
} ?: org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG |
|
|
|
val currentTarget = kotlin.targets[target.key] as org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget |
|
val kotlinBinary = currentTarget.binaries.getExecutable(buildType) |
|
val xcodeIntegrationGroup = "Xcode integration" |
|
|
|
val packForXCode = if (sdkName == null || targetBuildDir == null || executablePath == null) { |
|
// The build is launched not by Xcode -> |
|
// We cannot create a copy task and just show a meaningful error message. |
|
tasks.create("packForXCode").doLast { |
|
throw IllegalStateException("Please run the task from Xcode") |
|
} |
|
} else { |
|
// Otherwise copy the executable into the Xcode output directory. |
|
tasks.create("packForXCode", Copy::class.java) { |
|
dependsOn(kotlinBinary.linkTask) |
|
|
|
destinationDir = file(targetBuildDir) |
|
|
|
val dsymSource = kotlinBinary.outputFile.absolutePath + ".dSYM" |
|
val dsymDestination = File(executablePath).parentFile.name + ".dSYM" |
|
val oldExecName = kotlinBinary.outputFile.name |
|
val newExecName = File(executablePath).name |
|
|
|
from(dsymSource) { |
|
into(dsymDestination) |
|
rename(oldExecName, newExecName) |
|
} |
|
|
|
from(kotlinBinary.outputFile) { |
|
rename { executablePath } |
|
} |
|
} |
|
} |
|
}
|
|
|