Skip to content

Commit

Permalink
Merge pull request #648 from FabioCornelli/watchos-support
Browse files Browse the repository at this point in the history
Add WatchOS support
  • Loading branch information
Alex009 authored Apr 19, 2024
2 parents 0d35aef + 60eafe0 commit 7dcf26b
Show file tree
Hide file tree
Showing 35 changed files with 784 additions and 41 deletions.
19 changes: 15 additions & 4 deletions .github/compilation-check-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ on:

jobs:
build-library:
runs-on: ${{ matrix.os }}
strategy:
matrix:
<<: *runner_matrix
runs-on: macOS-latest

steps:
- *checkout
Expand All @@ -76,10 +73,13 @@ jobs:

- name: Check
run: ./local-check.sh
shell: bash
- name: Plugin local publish
run: ./gradlew -p resources-generator publishToMavenLocal
shell: bash
- name: Library local publish
run: ./gradlew publishToMavenLocal
shell: bash

- name: Upload artifacts
uses: actions/upload-artifact@v3
Expand All @@ -106,6 +106,7 @@ jobs:

- name: Sample - android-mpp-app
run: cd samples/android-mpp-app && ./local-check.sh
shell: bash

- *publish_test_report
- *upload_reports
Expand All @@ -126,6 +127,7 @@ jobs:

- name: Sample - auto-manifest
run: cd samples/auto-manifest && ./local-check.sh
shell: bash

- *publish_test_report
- *upload_reports
Expand All @@ -146,6 +148,7 @@ jobs:

- name: Sample - compose-jvm-app
run: cd samples/compose-jvm-app && ./local-check.sh
shell: bash

- *publish_test_report
- *upload_reports
Expand All @@ -166,6 +169,7 @@ jobs:

- name: Sample - resources-gallery
run: cd samples/resources-gallery && ./local-check.sh
shell: bash

- *publish_test_report
- *upload_reports
Expand All @@ -186,6 +190,7 @@ jobs:

- name: Sample - default-hierarchy-gallery-mobile
run: cd samples/default-hierarchy-gallery-mobile && ./local-check.sh
shell: bash

- *publish_test_report
- *upload_reports
Expand All @@ -203,6 +208,7 @@ jobs:

- name: Sample - ios-static-xcframework
run: cd samples/ios-static-xcframework && ./local-check.sh
shell: bash

- *publish_test_report
- *upload_reports
Expand All @@ -220,6 +226,7 @@ jobs:

- name: Sample - ios-cocoapods-static-framework
run: cd samples/ios-cocoapods-static-framework && ./local-check.sh
shell: bash

- *publish_test_report
- *upload_reports
Expand All @@ -237,6 +244,7 @@ jobs:

- name: Sample - kotlin-ios-app
run: cd samples/kotlin-ios-app && ./local-check.sh
shell: bash

- *publish_test_report
- *upload_reports
Expand All @@ -257,6 +265,7 @@ jobs:

- name: Sample - compose-resources-gallery
run: cd samples/compose-resources-gallery && ./local-check.sh
shell: bash

- *publish_test_report
- *upload_reports
Expand All @@ -277,6 +286,7 @@ jobs:

- name: Sample - kotlin-2-sample
run: cd samples/kotlin-2-sample && ./local-check.sh
shell: bash

- *publish_test_report
- *upload_reports
Expand All @@ -297,6 +307,7 @@ jobs:

- name: Sample - cm-resources-sample
run: cd samples/cm-resources-sample && ./local-check.sh
shell: bash

- *publish_test_report
- *upload_reports
22 changes: 15 additions & 7 deletions .github/workflows/compilation-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ on:

jobs:
build-library:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macOS-latest
- windows-latest
- ubuntu-latest
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- name: Set up JDK 17
Expand All @@ -39,10 +33,13 @@ jobs:
${{ runner.os }}-konan-
- name: Check
run: ./local-check.sh
shell: bash
- name: Plugin local publish
run: ./gradlew -p resources-generator publishToMavenLocal
shell: bash
- name: Library local publish
run: ./gradlew publishToMavenLocal
shell: bash
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -94,6 +91,7 @@ jobs:
path: ~/.m2/repository/dev/icerock
- name: Sample - android-mpp-app
run: cd samples/android-mpp-app && ./local-check.sh
shell: bash
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: ${{ always() }}
Expand Down Expand Up @@ -140,6 +138,7 @@ jobs:
path: ~/.m2/repository/dev/icerock
- name: Sample - auto-manifest
run: cd samples/auto-manifest && ./local-check.sh
shell: bash
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: ${{ always() }}
Expand Down Expand Up @@ -186,6 +185,7 @@ jobs:
path: ~/.m2/repository/dev/icerock
- name: Sample - compose-jvm-app
run: cd samples/compose-jvm-app && ./local-check.sh
shell: bash
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: ${{ always() }}
Expand Down Expand Up @@ -232,6 +232,7 @@ jobs:
path: ~/.m2/repository/dev/icerock
- name: Sample - resources-gallery
run: cd samples/resources-gallery && ./local-check.sh
shell: bash
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: ${{ always() }}
Expand Down Expand Up @@ -278,6 +279,7 @@ jobs:
path: ~/.m2/repository/dev/icerock
- name: Sample - default-hierarchy-gallery-mobile
run: cd samples/default-hierarchy-gallery-mobile && ./local-check.sh
shell: bash
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: ${{ always() }}
Expand Down Expand Up @@ -318,6 +320,7 @@ jobs:
path: ~/.m2/repository/dev/icerock
- name: Sample - ios-static-xcframework
run: cd samples/ios-static-xcframework && ./local-check.sh
shell: bash
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: ${{ always() }}
Expand Down Expand Up @@ -358,6 +361,7 @@ jobs:
path: ~/.m2/repository/dev/icerock
- name: Sample - ios-cocoapods-static-framework
run: cd samples/ios-cocoapods-static-framework && ./local-check.sh
shell: bash
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: ${{ always() }}
Expand Down Expand Up @@ -398,6 +402,7 @@ jobs:
path: ~/.m2/repository/dev/icerock
- name: Sample - kotlin-ios-app
run: cd samples/kotlin-ios-app && ./local-check.sh
shell: bash
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: ${{ always() }}
Expand Down Expand Up @@ -444,6 +449,7 @@ jobs:
path: ~/.m2/repository/dev/icerock
- name: Sample - compose-resources-gallery
run: cd samples/compose-resources-gallery && ./local-check.sh
shell: bash
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: ${{ always() }}
Expand Down Expand Up @@ -490,6 +496,7 @@ jobs:
path: ~/.m2/repository/dev/icerock
- name: Sample - kotlin-2-sample
run: cd samples/kotlin-2-sample && ./local-check.sh
shell: bash
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: ${{ always() }}
Expand Down Expand Up @@ -536,6 +543,7 @@ jobs:
path: ~/.m2/repository/dev/icerock
- name: Sample - cm-resources-sample
run: cd samples/cm-resources-sample && ./local-check.sh
shell: bash
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: ${{ always() }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ kotlin {
dependsOn(appleTest)
}
}

sourceSets.matching {
it.name == "watchosMain"
}.configureEach {
this.dependsOn(sourceSets.getByName("appleMain"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ kotlin {
}

sourceSets {
val commonMain by getting

val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
Expand All @@ -46,7 +48,6 @@ kotlin {
iosSimulatorArm64Test.dependsOn(this)
}

val commonMain by getting
val macosArm64Main by getting
val macosX64Main by getting

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
id("multiplatform-library-convention")
}

kotlin {
watchosX64()
watchosArm32()
watchosArm64()
watchosSimulatorArm64()

sourceSets {
val commonMain by getting

val watchosMain by creating {
dependsOn(commonMain)
}
val watchosX64Main by getting {
dependsOn(watchosMain)
}
val watchosArm32Main by getting{
dependsOn(watchosMain)
}
val watchosArm64Main by getting{
dependsOn(watchosMain)
}
val watchosSimulatorArm64Main by getting{
dependsOn(watchosMain)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import kotlinx.cinterop.CPointed
import kotlinx.cinterop.CPointer
import kotlinx.cinterop.CValue
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.readBytes
import kotlinx.cinterop.refTo
import org.jetbrains.skia.ColorAlphaType
import org.jetbrains.skia.ColorType
Expand Down
2 changes: 1 addition & 1 deletion resources-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

plugins {
id("multiplatform-library-convention")
id("multiplatform-library-extended-convention")
id("multiplatform-android-publish-convention")
id("apple-main-convention")
id("detekt-convention")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.resources.test

import dev.icerock.moko.resources.FontResource
import dev.icerock.moko.resources.ImageResource

actual fun createImageResourceMock(): ImageResource = ImageResource("")
actual fun createFontResourceMock(): FontResource = FontResource("")
2 changes: 1 addition & 1 deletion resources/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

plugins {
id("multiplatform-library-convention")
id("multiplatform-library-extended-convention")
id("multiplatform-android-publish-convention")
id("apple-main-convention")
id("kotlin-parcelize")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

package dev.icerock.moko.resources

import cnames.structs.CGDataProvider
import cnames.structs.CGFont
import cnames.structs.__CFData
import cnames.structs.__CFString
import cnames.structs.__CFURL
import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.CPointer
import kotlinx.cinterop.ExperimentalForeignApi
Expand Down Expand Up @@ -45,12 +49,12 @@ actual class FontResource(
internal val fontRef: CGFontRef by lazy {
val fontData: NSData = this.data
val cfDataRef: CPointer<__CFData>? = CFDataCreate(
kCFAllocatorDefault,
fontData.bytes() as CPointer<UInt8Var>,
fontData.length.toLong().convert()
allocator = kCFAllocatorDefault,
bytes = fontData.bytes() as CPointer<UInt8Var>,
length = fontData.length.toLong().convert()
)
val dataProvider = CGDataProviderCreateWithCFData(cfDataRef)
val cgFont = CGFontCreateWithDataProvider(dataProvider)!!
val dataProvider: CPointer<CGDataProvider>? = CGDataProviderCreateWithCFData(cfDataRef)
val cgFont: CPointer<CGFont> = CGFontCreateWithDataProvider(dataProvider)!!

CGDataProviderRelease(dataProvider)
CFRelease(cfDataRef)
Expand Down Expand Up @@ -82,22 +86,23 @@ actual class FontResource(
// an NSString so `as NSString` is fine.
// UNCHECKED_CAST - NSString and CFStringRef are toll-free bridged
@Suppress("CAST_NEVER_SUCCEEDS", "UNCHECKED_CAST")
val cfStringFilePath = CFBridgingRetain(filePath as NSString) as CFStringRef
val cfFontUrlRef = CFURLCreateWithFileSystemPath(
kCFAllocatorDefault,
cfStringFilePath,
kCFURLPOSIXPathStyle,
false
val cfStringFilePath: CPointer<__CFString> =
CFBridgingRetain(filePath as NSString) as CFStringRef
val cfFontUrlRef: CPointer<__CFURL>? = CFURLCreateWithFileSystemPath(
allocator = kCFAllocatorDefault,
filePath = cfStringFilePath,
pathStyle = kCFURLPOSIXPathStyle,
isDirectory = false
)

var nsError: NSError? = null

memScoped {
val error = alloc<CFErrorRefVar>()
if (!CTFontManagerRegisterFontsForURL(
cfFontUrlRef,
kCTFontManagerScopeProcess,
error.ptr
fontURL = cfFontUrlRef,
scope = kCTFontManagerScopeProcess,
error = error.ptr
)
) {
error.value?.let {
Expand Down
Loading

0 comments on commit 7dcf26b

Please sign in to comment.