Skip to content

Commit

Permalink
Support tvOS (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
orangy authored May 21, 2024
1 parent 5058bbc commit 44f2d51
Show file tree
Hide file tree
Showing 31 changed files with 345 additions and 136 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
path: ./skiko/build/reports/tests
retention-days: 5

ios:
iOS:
runs-on: macos-13
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -99,6 +99,29 @@ jobs:
path: ./skiko/build/reports/tests
retention-days: 5

tvOS:
# TVOS requires macos 13
runs-on: macos-13
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
- shell: bash
run: |
./gradlew --stacktrace --info -Pskiko.native.enabled=true -Pskiko.test.onci=true :skiko:tvosX64Test
# tvosSimulatorArm64Test 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:tvosSimulatorArm64Test
- uses: actions/upload-artifact@v2
if: always()
with:
name: test-reports-macos
path: ./skiko/build/reports/tests
retention-days: 5

linux:
runs-on: ubuntu-20.04
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
52 changes: 45 additions & 7 deletions samples/SkiaMultiplatformSample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.*

buildscript {
repositories {
Expand Down Expand Up @@ -82,11 +82,19 @@ kotlin {
macosArm64() {
configureToLaunchFromXcode()
}
ios() {
iosSimulatorArm64() {
configureToLaunchFromAppCode()
configureToLaunchFromXcode()
}
iosSimulatorArm64() {
tvosX64() {
configureToLaunchFromAppCode()
configureToLaunchFromXcode()
}
tvosArm64() {
configureToLaunchFromAppCode()
configureToLaunchFromXcode()
}
tvosSimulatorArm64() {
configureToLaunchFromAppCode()
configureToLaunchFromXcode()
}
Expand Down Expand Up @@ -165,12 +173,27 @@ kotlin {
val macosArm64Main by getting {
dependsOn(macosMain)
}
val iosMain by getting {
val uikitMain by creating {
dependsOn(darwinMain)
}
val iosMain by creating {
dependsOn(uikitMain)
}
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
val tvosMain by creating {
dependsOn(uikitMain)
}
val tvosX64Main by getting {
dependsOn(tvosMain)
}
val tvosArm64Main by getting {
dependsOn(tvosMain)
}
val tvosSimulatorArm64Main by getting {
dependsOn(tvosMain)
}
}
}
}
Expand Down Expand Up @@ -213,7 +236,7 @@ if (hostOs == "macos") {
}

project.tasks.register<JavaExec>("runAwt") {
val kotlinTask = project.tasks.named("compileKotlinAwt")
val kotlinTask = project.tasks.named("compileKotlinAwt")
dependsOn(kotlinTask)
systemProperty("skiko.fps.enabled", "true")
systemProperty("skiko.linux.autodpi", "true")
Expand All @@ -237,18 +260,31 @@ tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile>().configureEach
}

enum class Target(val simulator: Boolean, val key: String) {
WATCHOS_X86(true, "watchos"), WATCHOS_ARM64(false, "watchos"),
IOS_X64(true, "iosX64"), IOS_ARM64(false, "iosArm64"), IOS_SIMULATOR_ARM64(true, "iosSimulatorArm64")
WATCHOS_X86(true, "watchos"),
WATCHOS_ARM64(false, "watchos"),
IOS_X64(true, "iosX64"),
IOS_ARM64(false, "iosArm64"),
IOS_SIMULATOR_ARM64(true, "iosSimulatorArm64"),
TVOS_X64(true, "tvosX64"),
TVOS_ARM64(true, "tvosArm64"),
TVOS_SIMULATOR_ARM64(true, "tvosSimulatorArm64"),
}


if (hostOs == "macos") {
// Create Xcode integration tasks.
val sdkName: String? = System.getenv("SDK_NAME")

println("Configuring XCode for $sdkName")
val target = sdkName.orEmpty().let {
when {
it.startsWith("iphoneos") -> Target.IOS_ARM64
it.startsWith("appletvsimulator") -> when (host) {
"macos-x64" -> Target.TVOS_X64
"macos-arm64" -> Target.TVOS_SIMULATOR_ARM64
else -> throw GradleException("Host OS is not supported")
}
it.startsWith("appletvos") -> Target.TVOS_ARM64
it.startsWith("watchos") -> Target.WATCHOS_ARM64
it.startsWith("watchsimulator") -> Target.WATCHOS_X86
else -> when (host) {
Expand Down Expand Up @@ -279,6 +315,8 @@ if (hostOs == "macos") {
// Otherwise copy the executable into the Xcode output directory.
tasks.create("packForXCode", Copy::class.java) {
dependsOn(kotlinBinary.linkTask)

println("Packing for XCode: ${kotlinBinary.target}")

destinationDir = file(targetBuildDir)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
24 changes: 24 additions & 0 deletions samples/SkiaMultiplatformSample/plists/tvOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>UILaunchStoryboardName</key>
<string></string>
</dict>
</plist>
30 changes: 27 additions & 3 deletions samples/SkiaMultiplatformSample/project.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: SkikoSample
name: Skiko Sample
options:
bundleIdPrefix: org.jetbrains
settings:
DEVELOPMENT_TEAM: N462MKSJ7M
CODE_SIGN_IDENTITY: "iPhone Developer"
CODE_SIGN_IDENTITY: "Apple Development"
CODE_SIGN_STYLE: Automatic
MARKETING_VERSION: "1.0"
CURRENT_PROJECT_VERSION: "4"
SDKROOT: iphoneos
targets:
SkikoSample:
Skiko Sample iOS:
type: application
platform: iOS
deploymentTarget: "12.0"
Expand All @@ -32,3 +32,27 @@ targets:
ENABLE_BITCODE: "YES"
ONLY_ACTIVE_ARCH: "NO"
VALID_ARCHS: "arm64"
Skiko Sample tvOS:
type: application
platform: tvOS
deploymentTarget: "14.0"
prebuildScripts:
- script: cd "$SRCROOT" && ./gradlew -p . packForXCode
name: GradleCompile
info:
path: plists/tvOS/Info.plist
properties:
UILaunchStoryboardName: ""
sources:
- path: "src/"
excludes:
- "android*/**"
- "awt*/**"
- "iosApp*/**"
- "js*/**"
settings:
LIBRARY_SEARCH_PATHS: "$(inherited)"
ENABLE_BITCODE: "YES"
ONLY_ACTIVE_ARCH: "NO"
VALID_ARCHS: "arm64"

88 changes: 69 additions & 19 deletions skiko/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ kotlin {
if (supportNativeIosX64) {
skikoProjectContext.configureNativeTarget(OS.IOS, Arch.X64, iosX64())
}
if (supportNativeTvosArm64) {
skikoProjectContext.configureNativeTarget(OS.TVOS, Arch.Arm64, tvosArm64())
}
if (supportNativeTvosSimulatorArm64) {
skikoProjectContext.configureNativeTarget(OS.TVOS, Arch.Arm64, tvosSimulatorArm64())
}
if (supportNativeTvosX64) {
skikoProjectContext.configureNativeTarget(OS.TVOS, Arch.X64, tvosX64())
}

sourceSets {
val commonMain by getting {
Expand Down Expand Up @@ -299,35 +308,76 @@ kotlin {
dependsOn(macosTest)
}
}
if (supportAnyNativeIos) {
val iosMain by creating {
if (supportAnyNativeIos || supportAllNativeTvos) {
val uikitMain by creating {
dependsOn(darwinMain)
}
val iosTest by creating {
val uikitTest by creating {
dependsOn(darwinTest)
}
if (supportNativeIosArm64) {
val iosArm64Main by getting {
dependsOn(iosMain)

if (supportAnyNativeIos) {
val iosMain by creating {
dependsOn(uikitMain)
}
val iosArm64Test by getting {
dependsOn(iosTest)
val iosTest by creating {
dependsOn(uikitTest)
}
}
if (supportNativeIosSimulatorArm64) {
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
if (supportNativeIosArm64) {
val iosArm64Main by getting {
dependsOn(iosMain)
}
val iosArm64Test by getting {
dependsOn(iosTest)
}
}
val iosSimulatorArm64Test by getting {
dependsOn(iosTest)
if (supportNativeIosSimulatorArm64) {
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
val iosSimulatorArm64Test by getting {
dependsOn(iosTest)
}
}
if (supportNativeIosX64) {
val iosX64Main by getting {
dependsOn(iosMain)
}
val iosX64Test by getting {
dependsOn(iosTest)
}
}
}
if (supportNativeIosX64) {
val iosX64Main by getting {
dependsOn(iosMain)
if (supportAnyNativeTvos) {
val tvosMain by creating {
dependsOn(uikitMain)
}
val tvosTest by creating {
dependsOn(uikitTest)
}
if (supportNativeTvosArm64) {
val tvosArm64Main by getting {
dependsOn(tvosMain)
}
val tvosArm64Test by getting {
dependsOn(tvosTest)
}
}
if (supportNativeTvosSimulatorArm64) {
val tvosSimulatorArm64Main by getting {
dependsOn(tvosMain)
}
val tvosSimulatorArm64Test by getting {
dependsOn(tvosTest)
}
}
val iosX64Test by getting {
dependsOn(iosTest)
if (supportNativeTvosX64) {
val tvosX64Main by getting {
dependsOn(tvosMain)
}
val tvosX64Test by getting {
dependsOn(tvosTest)
}
}
}
}
Expand Down
21 changes: 18 additions & 3 deletions skiko/buildSrc/src/main/kotlin/SkikoProjectContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class SkikoProjectContext(
* (tasks' registration during other task's registration is prohibited)
*/
fun SkikoProjectContext.registerOrGetSkiaDirProvider(
os: OS, arch: Arch, isIosSim: Boolean = false
os: OS, arch: Arch, isUikitSim: Boolean = false
): Provider<File> = with(this.project) {
val taskNameSuffix = joinToTitleCamelCase(buildType.id, os.idWithSuffix(isIosSim = isIosSim), arch.id)
val skiaRelease = skiko.skiaReleaseFor(os, arch, buildType, isIosSim)
val taskNameSuffix = joinToTitleCamelCase(buildType.id, os.idWithSuffix(isUikitSim = isUikitSim), arch.id)
val skiaRelease = skiko.skiaReleaseFor(os, arch, buildType, isUikitSim)
val downloadSkia = tasks.registerOrGetTask<Download>("downloadSkia$taskNameSuffix") {
onlyIf { !dest.exists() }
onlyIfModified(true)
Expand Down Expand Up @@ -89,6 +89,21 @@ val Project.supportNativeIosX64: Boolean
val Project.supportAnyNativeIos: Boolean
get() = supportAllNativeIos || supportNativeIosArm64 || supportNativeIosSimulatorArm64 || supportNativeIosX64

val Project.supportAllNativeTvos: Boolean
get() = supportAllNative || findProperty("skiko.native.tvos.enabled") == "true" || isInIdea

val Project.supportNativeTvosArm64: Boolean
get() = supportAllNativeTvos || findProperty("skiko.native.tvos.arm64.enabled") == "true" || isInIdea

val Project.supportNativeTvosSimulatorArm64: Boolean
get() = supportAllNativeTvos || findProperty("skiko.native.tvos.simulatorArm64.enabled") == "true" || isInIdea

val Project.supportNativeTvosX64: Boolean
get() = supportAllNativeTvos || findProperty("skiko.native.tvos.x64.enabled") == "true" || isInIdea

val Project.supportAnyNativeTvos: Boolean
get() = supportAllNativeTvos || supportNativeTvosArm64 || supportNativeTvosSimulatorArm64 || supportNativeTvosX64

val Project.supportNativeMac: Boolean
get() = supportAllNative || findProperty("skiko.native.mac.enabled") == "true" || isInIdea

Expand Down
Loading

0 comments on commit 44f2d51

Please sign in to comment.