From d94b2719f878e89f50562bddd093bc974da73f15 Mon Sep 17 00:00:00 2001 From: Syer10 Date: Mon, 5 Dec 2022 22:26:09 -0500 Subject: [PATCH] Wow, it sorta, but not relly, works --- i18n/build.gradle.kts | 13 +++++-- ios/build.gradle.kts | 83 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 4 deletions(-) diff --git a/i18n/build.gradle.kts b/i18n/build.gradle.kts index 7d29e8fd..3b890253 100644 --- a/i18n/build.gradle.kts +++ b/i18n/build.gradle.kts @@ -20,9 +20,16 @@ kotlin { } } } - iosX64() - iosArm64() - iosSimulatorArm64() + val configuration: org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget.() -> Unit = { + binaries { + framework { + baseName = "i18n" + } + } + } + iosX64(configure = configuration) + iosArm64(configure = configuration) + iosSimulatorArm64(configure = configuration) sourceSets { val commonMain by getting { diff --git a/ios/build.gradle.kts b/ios/build.gradle.kts index adccb7a9..ce67f686 100644 --- a/ios/build.gradle.kts +++ b/ios/build.gradle.kts @@ -1,5 +1,9 @@ import org.jetbrains.compose.compose +import org.jetbrains.compose.experimental.uikit.tasks.ExperimentalPackComposeApplicationForXCodeTask import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink +import java.io.File +import kotlin.reflect.full.declaredMemberProperties @Suppress("DSL_SCOPE_VIOLATION") plugins { @@ -157,4 +161,81 @@ kotlin { buildkonfig { packageName = "ca.gosyer.jui.ios.build" -} \ No newline at end of file +} + +// todo: Remove when resolved: https://github.com/icerockdev/moko-resources/issues/372 +// copy .bundle from all .klib to .kexe +tasks.withType() + .configureEach { + val linkTask: KotlinNativeLink = this + val outputDir: File = this.outputFile.get().parentFile + + @Suppress("ObjectLiteralToLambda") // lambda broke up-to-date + val action = object : Action { + override fun execute(t: Task) { + (linkTask.libraries + linkTask.sources) + .filter { library -> library.extension == "klib" } + .filter(File::exists) + .forEach { inputFile -> + val klibKonan = org.jetbrains.kotlin.konan.file.File(inputFile.path) + val klib = org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl( + klib = klibKonan, + component = "default" + ) + val layout = klib.extractingToTemp + + // extracting bundles + layout + .resourcesDir + .absolutePath + .let(::File) + .listFiles { file: File -> file.extension == "bundle" } + // copying bundles to app + ?.forEach { + logger.info("${it.absolutePath} copying to $outputDir") + it.copyRecursively( + target = File(outputDir, it.name), + overwrite = true + ) + } + } + } + } + doLast(action) + } + +// copy .bundle from .kexe to .app +tasks.withType() + .configureEach { + val packTask: ExperimentalPackComposeApplicationForXCodeTask = this + + val kclass = ExperimentalPackComposeApplicationForXCodeTask::class + val kotlinBinaryField = + kclass.declaredMemberProperties.single { it.name == "kotlinBinary" } + val destinationDirField = + kclass.declaredMemberProperties.single { it.name == "destinationDir" } + val executablePathField = + kclass.declaredMemberProperties.single { it.name == "executablePath" } + + @Suppress("ObjectLiteralToLambda") // lambda broke up-to-date + val action = object : Action { + override fun execute(t: Task) { + val kotlinBinary: RegularFile = + (kotlinBinaryField.get(packTask) as RegularFileProperty).get() + val destinationDir: Directory = + (destinationDirField.get(packTask) as DirectoryProperty).get() + val executablePath: String = + (executablePathField.get(packTask) as Provider).get() + + val outputDir: File = File(destinationDir.asFile, executablePath).parentFile + + val bundleSearchDir: File = kotlinBinary.asFile.parentFile + bundleSearchDir + .listFiles { file: File -> file.extension == "bundle" } + ?.forEach { file -> + file.copyRecursively(File(outputDir, file.name), true) + } + } + } + doLast(action) + }