Unverified Commit 52640c31 authored by dima.avdeev's avatar dima.avdeev Committed by GitHub

Fix skiko sample on iosSimulatorArm64 (#589)

parent 186bc0d7
# Skia multiplatform samples # Skia multiplatform samples
## run iOS with Xcode ## run iOS with Xcode
- Works only on Mac with Intel CPU (for now)
- Install xcodegen - Install xcodegen
- run `xcodegen` - run `xcodegen`
- run `open SkikoSample.xcodeproj` - run `open SkikoSample.xcodeproj`
......
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
buildscript { buildscript {
repositories { repositories {
mavenLocal() mavenLocal()
...@@ -14,7 +16,7 @@ buildscript { ...@@ -14,7 +16,7 @@ buildscript {
plugins { plugins {
kotlin("multiplatform") version "1.6.10" kotlin("multiplatform") version "1.6.10"
id("org.jetbrains.gradle.apple.applePlugin") version "222.849-0.15.1" id("org.jetbrains.gradle.apple.applePlugin") version "222.3345.143-0.16"
} }
val coroutinesVersion = "1.5.2" val coroutinesVersion = "1.5.2"
...@@ -61,30 +63,20 @@ val unzipTask = tasks.register("unzipWasm", Copy::class) { ...@@ -61,30 +63,20 @@ val unzipTask = tasks.register("unzipWasm", Copy::class) {
} }
kotlin { kotlin {
val targets = mutableListOf<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>()
if (hostOs == "macos") { if (hostOs == "macos") {
val nativeHostTarget = when (host) { macosX64() {
"macos-x64" -> macosX64() configureToLaunchFromXcode()
"macos-arm64" -> macosArm64()
else -> throw GradleException("Host OS is not supported yet")
} }
targets.add(nativeHostTarget) macosArm64() {
configureToLaunchFromXcode()
targets.add(iosX64())
targets.add(iosArm64())
ios {
binaries {
framework {
baseName = "shared"
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
)
} }
ios() {
configureToLaunchFromAppCode()
configureToLaunchFromXcode()
} }
iosSimulatorArm64() {
configureToLaunchFromAppCode()
configureToLaunchFromXcode()
} }
} }
...@@ -99,21 +91,6 @@ kotlin { ...@@ -99,21 +91,6 @@ kotlin {
binaries.executable() binaries.executable()
} }
targets.forEach {
it.apply {
binaries {
executable {
entryPoint = "org.jetbrains.skiko.sample.main"
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
)
}
}
}
}
sourceSets { sourceSets {
val commonMain by getting { val commonMain by getting {
dependencies { dependencies {
...@@ -148,28 +125,16 @@ kotlin { ...@@ -148,28 +125,16 @@ kotlin {
} }
if (hostOs == "macos") { if (hostOs == "macos") {
val archTargetMain = when (host) {
"macos-x64" -> {
val macosX64Main by getting { val macosX64Main by getting {
dependsOn(macosMain) dependsOn(macosMain)
} }
macosX64Main
}
"macos-arm64" -> {
val macosArm64Main by getting { val macosArm64Main by getting {
dependsOn(macosMain) dependsOn(macosMain)
} }
macosArm64Main
}
else -> throw GradleException("Host OS is not supported")
}
val iosMain by getting { val iosMain by getting {
dependsOn(darwinMain) dependsOn(darwinMain)
} }
val iosX64Main by getting { val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
val iosArm64Main by getting {
dependsOn(iosMain) dependsOn(iosMain)
} }
} }
...@@ -180,7 +145,12 @@ if (hostOs == "macos") { ...@@ -180,7 +145,12 @@ if (hostOs == "macos") {
project.tasks.register<Exec>("runIosSim") { project.tasks.register<Exec>("runIosSim") {
val device = "iPhone 11" val device = "iPhone 11"
workingDir = project.buildDir workingDir = project.buildDir
val binTask = project.tasks.named("linkReleaseExecutableIosX64") val linkExecutableTaskName = when (host) {
"macos-x64" -> "linkReleaseExecutableIosX64"
"macos-arm64" -> "linkReleaseExecutableIosSimulatorArm64"
else -> throw GradleException("Host OS is not supported")
}
val binTask = project.tasks.named(linkExecutableTaskName)
dependsOn(binTask) dependsOn(binTask)
commandLine = listOf( commandLine = listOf(
"xcrun", "xcrun",
...@@ -234,7 +204,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile>().configureEach ...@@ -234,7 +204,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile>().configureEach
enum class Target(val simulator: Boolean, val key: String) { enum class Target(val simulator: Boolean, val key: String) {
WATCHOS_X86(true, "watchos"), WATCHOS_ARM64(false, "watchos"), WATCHOS_X86(true, "watchos"), WATCHOS_ARM64(false, "watchos"),
IOS_X64(true, "iosX64"), IOS_ARM64(false, "iosArm64") IOS_X64(true, "iosX64"), IOS_ARM64(false, "iosArm64"), IOS_SIMULATOR_ARM64(true, "iosSimulatorArm64")
} }
...@@ -245,10 +215,13 @@ if (hostOs == "macos") { ...@@ -245,10 +215,13 @@ if (hostOs == "macos") {
val target = sdkName.orEmpty().let { val target = sdkName.orEmpty().let {
when { when {
it.startsWith("iphoneos") -> Target.IOS_ARM64 it.startsWith("iphoneos") -> Target.IOS_ARM64
it.startsWith("iphonesimulator") -> Target.IOS_X64
it.startsWith("watchos") -> Target.WATCHOS_ARM64 it.startsWith("watchos") -> Target.WATCHOS_ARM64
it.startsWith("watchsimulator") -> Target.WATCHOS_X86 it.startsWith("watchsimulator") -> Target.WATCHOS_X86
else -> Target.IOS_X64 else -> when (host) {
"macos-x64" -> Target.IOS_X64
"macos-arm64" -> Target.IOS_SIMULATOR_ARM64
else -> throw GradleException("Host OS is not supported")
}
} }
} }
...@@ -305,3 +278,29 @@ apple { ...@@ -305,3 +278,29 @@ apple {
} }
} }
} }
fun KotlinNativeTarget.configureToLaunchFromAppCode() {
binaries {
framework {
baseName = "shared"
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
)
}
}
}
fun KotlinNativeTarget.configureToLaunchFromXcode() {
binaries {
executable {
entryPoint = "org.jetbrains.skiko.sample.main"
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal",
"-linker-option", "-framework", "-linker-option", "CoreText",
"-linker-option", "-framework", "-linker-option", "CoreGraphics"
)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment