Skip to content

Commit

Permalink
add iosSimulatorArm64 target (#566)
Browse files Browse the repository at this point in the history
* add iosSimulatorArm64 target

Co-authored-by: Oleksandr Karpovich <[email protected]>
  • Loading branch information
eymar and Oleksandr Karpovich authored Aug 22, 2022
1 parent c2f2093 commit b6c8e6a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:
- shell: bash
run: |
./gradlew --stacktrace --info -Pskiko.native.enabled=true -Pskiko.test.onci=true :skiko:iosX64Test
# iosSimulatorArm64Test will build the binary but the tests will be skipped due to X64 host machine
./gradlew --stacktrace --info -Pskiko.native.enabled=true -Pskiko.test.onci=true :skiko:iosSimulatorArm64Test
./gradlew --stacktrace --info -Pskiko.native.enabled=true :skiko:publishToMavenLocal
# TODO run iOS specific tests on iPhone simulator
- uses: actions/upload-artifact@v2
Expand Down
50 changes: 35 additions & 15 deletions skiko/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ val windowsSdkPaths: WindowsSdkPaths by lazy {
findWindowsSdkPathsForCurrentOS(gradle)
}

fun KotlinTarget.isIosSimArm64() =
name.contains("iosSimulatorArm64", ignoreCase = true)

fun String.withSuffix(isIosSim: Boolean = false) =
this + if (isIosSim) "Sim" else ""

if (supportWasm) {
val skiaWasmDir = registerOrGetSkiaDirProvider(OS.Wasm, Arch.Wasm)

Expand Down Expand Up @@ -127,10 +133,12 @@ if (supportWasm) {
}
}

fun compileNativeBridgesTask(os: OS, arch: Arch): TaskProvider<CompileSkikoCppTask> {
val skiaNativeDir = registerOrGetSkiaDirProvider(os, arch)
fun compileNativeBridgesTask(os: OS, arch: Arch, isArm64Simulator: Boolean): TaskProvider<CompileSkikoCppTask> {
val skiaNativeDir = registerOrGetSkiaDirProvider(os, arch, isIosSim = isArm64Simulator)

return project.registerSkikoTask<CompileSkikoCppTask>("compileNativeBridges", os, arch) {
val actionName = "compileNativeBridges".withSuffix(isIosSim = isArm64Simulator)

return project.registerSkikoTask<CompileSkikoCppTask>(actionName, os, arch) {
dependsOn(skiaNativeDir)
val unpackedSkia = skiaNativeDir.get()

Expand All @@ -142,16 +150,18 @@ fun compileNativeBridgesTask(os: OS, arch: Arch): TaskProvider<CompileSkikoCppTa
when (os) {
OS.IOS -> {
val sdkRoot = "/Applications/Xcode.app/Contents/Developer/Platforms"
val iphoneOsSdk = "$sdkRoot/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
val iphoneSimSdk = "$sdkRoot/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
val iosArchFlags = when (arch) {
Arch.Arm64 -> arrayOf(
"-target", "arm64-apple-ios",
"-mios-version-min=11.0",
"-isysroot", "$sdkRoot/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
"-target", if (isArm64Simulator) "arm64-apple-ios-simulator" else "arm64-apple-ios",
"-isysroot", if (isArm64Simulator) iphoneSimSdk else iphoneOsSdk,
"-miphoneos-version-min=11.0"
)
Arch.X64 -> arrayOf(
"-target", "x86_64-apple-ios-simulator",
"-mios-version-min=11.0",
"-isysroot", "$sdkRoot/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
"-isysroot", iphoneSimSdk
)
else -> throw GradleException("Unsupported arch: $arch")
}
Expand Down Expand Up @@ -250,6 +260,7 @@ kotlin {
configureNativeTarget(OS.Linux, Arch.X64, linuxX64())
configureNativeTarget(OS.IOS, Arch.Arm64, iosArm64())
configureNativeTarget(OS.IOS, Arch.X64, iosX64())
configureNativeTarget(OS.IOS, Arch.Arm64, iosSimulatorArm64())
}

sourceSets {
Expand Down Expand Up @@ -399,6 +410,12 @@ kotlin {
val iosArm64Test by getting {
dependsOn(iosTest)
}
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
val iosSimulatorArm64Test by getting {
dependsOn(iosTest)
}
}
}
}
Expand All @@ -408,10 +425,11 @@ fun configureNativeTarget(os: OS, arch: Arch, target: KotlinNativeTarget) {
if (!os.isCompatibleWithHost) return

target.generateVersion(os, arch)
val isArm64Simulator = target.isIosSimArm64()

val targetString = "${os.id}-${arch.id}"
val targetString = "${os.idWithSuffix(isIosSim = isArm64Simulator)}-${arch.id}"

val unzipper = registerOrGetSkiaDirProvider(os, arch)
val unzipper = registerOrGetSkiaDirProvider(os, arch, isArm64Simulator)
val unpackedSkia = unzipper.get()
val skiaDir = unpackedSkia.absolutePath

Expand Down Expand Up @@ -456,10 +474,11 @@ fun configureNativeTarget(os: OS, arch: Arch, target: KotlinNativeTarget) {
}
}

val crossCompileTask = compileNativeBridgesTask(os, arch)
val crossCompileTask = compileNativeBridgesTask(os, arch, isArm64Simulator = isArm64Simulator)

// TODO: move to LinkSkikoTask.
val linkTask = project.registerSkikoTask<Exec>("linkNativeBridges", os, arch) {
val actionName = "linkNativeBridges".withSuffix(isIosSim = isArm64Simulator)
val linkTask = project.registerSkikoTask<Exec>(actionName, os, arch) {
dependsOn(crossCompileTask)
val objectFilesDir = crossCompileTask.map { it.outDir.get() }
val objectFiles = project.fileTree(objectFilesDir) {
Expand Down Expand Up @@ -973,9 +992,10 @@ fun KotlinTarget.generateVersion(
targetArch: Arch
) {
val targetName = this.name
val isArm64Simulator = isIosSimArm64()
val generatedDir = project.layout.buildDirectory.dir("generated/$targetName")
val generateVersionTask = project.registerSkikoTask<DefaultTask>(
"generateVersion${toTitleCase(platformType.name)}",
"generateVersion${toTitleCase(platformType.name)}".withSuffix(isIosSim = isArm64Simulator),
targetOs,
targetArch
) {
Expand Down Expand Up @@ -1252,9 +1272,9 @@ if (skiko.isCIBuild || mavenCentral.signArtifacts) {
* Do not call inside tasks.register or tasks.call callback
* (tasks' registration during other task's registration is prohibited)
*/
fun registerOrGetSkiaDirProvider(os: OS, arch: Arch): Provider<File> {
val taskNameSuffix = joinToTitleCamelCase(buildType.id, os.id, arch.id)
val skiaRelease = skiko.skiaReleaseFor(os, arch, buildType)
fun registerOrGetSkiaDirProvider(os: OS, arch: Arch, isIosSim: Boolean = false): Provider<File> {
val taskNameSuffix = joinToTitleCamelCase(buildType.id, os.idWithSuffix(isIosSim = isIosSim), arch.id)
val skiaRelease = skiko.skiaReleaseFor(os, arch, buildType, isIosSim)
val downloadSkia = tasks.registerOrGetTask<Download>("downloadSkia$taskNameSuffix") {
onlyIf { !dest.exists() }
onlyIfModified(true)
Expand Down
14 changes: 9 additions & 5 deletions skiko/buildSrc/src/main/kotlin/properties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ enum class OS(

val isWindows
get() = this == Windows

fun idWithSuffix(isIosSim: Boolean = false): String {
return id + if (isIosSim) "Sim" else ""
}
}

val OS.isCompatibleWithHost: Boolean
Expand Down Expand Up @@ -126,11 +130,11 @@ class SkikoProperties(private val myProject: Project) {
val includeTestHelpers: Boolean
get() = !isRelease

fun skiaReleaseFor(os: OS, arch: Arch, buildType: SkiaBuildType): String {
val target = "${os.id}-${arch.id}"
fun skiaReleaseFor(os: OS, arch: Arch, buildType: SkiaBuildType, isIosSim: Boolean = false): String {
val target = "${os.idWithSuffix(isIosSim = isIosSim)}-${arch.id}"
val tag = myProject.property("dependencies.skia.$target") as String
val suffix = if (os == OS.Linux && arch == Arch.X64) "-ubuntu18" else ""
return "${tag}/Skia-${tag}-${os.id}-${buildType.id}-${arch.id}$suffix"
return "${tag}/Skia-${tag}-${os.idWithSuffix(isIosSim = isIosSim)}-${buildType.id}-${arch.id}$suffix"
}

val releaseGithubVersion: String
Expand Down Expand Up @@ -187,6 +191,6 @@ object SkikoArtifacts {
// does not seem possible (at least without adding a dash to a target's tasks),
// so we're using the default naming pattern instead.
// See https://youtrack.jetbrains.com/issue/KT-50001.
fun nativeArtifactIdFor(os: OS, arch: Arch) =
"skiko-${os.id}${arch.id}"
fun nativeArtifactIdFor(os: OS, arch: Arch, isIosSim: Boolean = false) =
"skiko-${os.id + if (isIosSim) "simulator" else ""}${arch.id}"
}
2 changes: 1 addition & 1 deletion skiko/buildSrc/src/main/kotlin/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ fun toTitleCase(s: String): String =
fun Task.projectDirs(vararg relativePaths: String): List<Directory> {
val projectDir = project.layout.projectDirectory
return relativePaths.map { path -> projectDir.dir(path) }
}
}
3 changes: 2 additions & 1 deletion skiko/ci/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ val skikoArtifactIds: List<String> =
SkikoArtifacts.nativeArtifactIdFor(OS.MacOS, Arch.X64),
SkikoArtifacts.nativeArtifactIdFor(OS.IOS, Arch.X64),
SkikoArtifacts.nativeArtifactIdFor(OS.IOS, Arch.Arm64),
SkikoArtifacts.nativeArtifactIdFor(OS.IOS, Arch.Arm64, isIosSim = true),
)

val downloadSkikoArtifactsFromComposeDev by tasks.registering(DownloadFromSpaceMavenRepoTask::class) {
Expand Down Expand Up @@ -98,4 +99,4 @@ fun Project.skikoMavenModules(version: String): Provider<List<ModuleToUpload>> =
fun connectToGitHub() =
GitHubBuilder()
.withOAuthToken(System.getenv("SKIKO_GH_RELEASE_TOKEN"))
.build()
.build()
2 changes: 2 additions & 0 deletions skiko/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dependencies.skia.macos-arm64=m105-f204b137b9-5
dependencies.skia.wasm-wasm=m105-f204b137b9-5
dependencies.skia.ios-x64=m105-f204b137b9-5
dependencies.skia.ios-arm64=m105-f204b137b9-5
dependencies.skia.iosSim-arm64=m105-f204b137b9-5
dependencies.skia.iosSim-x64=m105-f204b137b9-5
dependencies.skia.android-x64=m105-f204b137b9-5
dependencies.skia.android-arm64=m105-f204b137b9-5

Expand Down
2 changes: 1 addition & 1 deletion skiko/src/jvmMain/cpp/common/RuntimeEffect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ Java_org_jetbrains_skia_RuntimeEffectKt__1nMakeForColorFilter(JNIEnv* env,
env->ThrowNew(java::lang::RuntimeException::cls, result.errorText.c_str());
return 0;
}
}
}
2 changes: 1 addition & 1 deletion skiko/src/jvmMain/cpp/common/interop.hh
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,4 @@ private:
jobject callback;
};

typedef JCallback<jboolean> JBooleanCallback;
typedef JCallback<jboolean> JBooleanCallback;
2 changes: 1 addition & 1 deletion skiko/src/jvmMain/cpp/common/paragraph/ParagraphBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_paragraph_ParagraphBu
ParagraphBuilder* instance = reinterpret_cast<ParagraphBuilder*>(static_cast<uintptr_t>(ptr));
Paragraph* paragraph = instance->Build().release();
return reinterpret_cast<jlong>(paragraph);
}
}

0 comments on commit b6c8e6a

Please sign in to comment.