Skip to content

Android Support #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions Sources/JPEG/decode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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.
Expand Down
22 changes: 19 additions & 3 deletions Sources/JPEGSystem/os.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -25,7 +27,11 @@ enum System
public
enum File
{
#if os(Android)
typealias Descriptor = OpaquePointer
#else
typealias Descriptor = UnsafeMutablePointer<FILE>
#endif

/// A type for reading data from files on disk.
public
Expand Down Expand Up @@ -102,7 +108,12 @@ extension System.File.Source
{
(buffer:inout UnsafeMutableBufferPointer<UInt8>, count:inout Int) in

count = fread(buffer.baseAddress, MemoryLayout<UInt8>.stride,
#if os(Android)
let baseAddress = buffer.baseAddress!
#else
let baseAddress = buffer.baseAddress
#endif
count = fread(baseAddress, MemoryLayout<UInt8>.stride,
capacity, self.descriptor)
}

Expand Down Expand Up @@ -210,7 +221,12 @@ extension System.File.Destination
{
let count:Int = buffer.withUnsafeBufferPointer
{
fwrite($0.baseAddress, MemoryLayout<UInt8>.stride,
#if os(Android)
let baseAddress = $0.baseAddress!
#else
let baseAddress = $0.baseAddress
#endif
return fwrite(baseAddress, MemoryLayout<UInt8>.stride,
$0.count, self.descriptor)
}

Expand Down