diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml new file mode 100644 index 00000000..f4eb58cb --- /dev/null +++ b/.github/workflows/android.yml @@ -0,0 +1,20 @@ +name: Android + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + android: + runs-on: ubuntu-24.04 + name: Android + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Build for Android + uses: skiptools/swift-android-action@v2 + with: + run-tests: false diff --git a/Sources/JPEG/decode.swift b/Sources/JPEG/decode.swift index a3d3b920..0fb5d8fb 100644 --- a/Sources/JPEG/decode.swift +++ b/Sources/JPEG/decode.swift @@ -1768,6 +1768,20 @@ extension JPEG.Data.Spectral:RandomAccessCollection /// /// - Returns: /// The plane. + #if os(Android) // workaround for an Android toolchain crash in `yield` + public + subscript(p:Int) -> Plane + { + get + { + self.planes[p] + } + set + { + self.planes[p] = newValue + } + } + #else public subscript(p:Int) -> Plane { @@ -1780,6 +1794,7 @@ extension JPEG.Data.Spectral:RandomAccessCollection yield &self.planes[p] } } + #endif /// Returns the index of the plane storing the color channel represented /// by the given component key, or `nil` if the component key is a /// non-recognized component. diff --git a/Sources/JPEGSystem/os.swift b/Sources/JPEGSystem/os.swift index 2cdcc8d4..dc2940b2 100644 --- a/Sources/JPEGSystem/os.swift +++ b/Sources/JPEGSystem/os.swift @@ -8,11 +8,13 @@ import JPEG import Darwin #elseif os(Linux) import Glibc +#elseif os(Android) + import Android #else #warning("unsupported or untested platform (please open an issue at https://github.com/tayloraswift/swift-jpeg/issues)") #endif -#if os(macOS) || os(Linux) +#if os(macOS) || os(Linux) || os(Android) /// A namespace for platform-dependent functionality. /// @@ -25,7 +27,11 @@ enum System public enum File { + #if os(Android) + typealias Descriptor = OpaquePointer + #else typealias Descriptor = UnsafeMutablePointer + #endif /// A type for reading data from files on disk. public @@ -102,7 +108,12 @@ extension System.File.Source { (buffer:inout UnsafeMutableBufferPointer, count:inout Int) in - count = fread(buffer.baseAddress, MemoryLayout.stride, + #if os(Android) + let baseAddress = buffer.baseAddress! + #else + let baseAddress = buffer.baseAddress + #endif + count = fread(baseAddress, MemoryLayout.stride, capacity, self.descriptor) } @@ -210,7 +221,12 @@ extension System.File.Destination { let count:Int = buffer.withUnsafeBufferPointer { - fwrite($0.baseAddress, MemoryLayout.stride, + #if os(Android) + let baseAddress = $0.baseAddress! + #else + let baseAddress = $0.baseAddress + #endif + return fwrite(baseAddress, MemoryLayout.stride, $0.count, self.descriptor) }