Skip to content

Commit 4e3ed28

Browse files
authored
Merge pull request #84 from marcprux/master
Android Support
2 parents 3f8b072 + 86c3df5 commit 4e3ed28

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

.github/workflows/android.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Android
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
android:
11+
runs-on: ubuntu-24.04
12+
name: Android
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
- name: Build for Android
18+
uses: skiptools/swift-android-action@v2
19+
with:
20+
run-tests: false

Sources/PNG/System.swift

+19-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import Darwin
77
#elseif canImport(Glibc)
88
import Glibc
9+
#elseif canImport(Android)
10+
import Android
911
#elseif canImport(Musl)
1012
import Musl
1113
#elseif os(Windows)
@@ -15,7 +17,7 @@
1517
#warning("unsupported or untested platform (please open an issue at https://github.com/tayloraswift/swift-png/issues)")
1618
#endif
1719

18-
#if canImport(Darwin) || canImport(Glibc) || canImport(Musl) || os(Windows)
20+
#if canImport(Darwin) || canImport(Glibc) || canImport(Android) || canImport(Musl) || os(Windows)
1921

2022
/// A namespace for platform-dependent functionality.
2123
///
@@ -28,7 +30,11 @@ enum System
2830
public
2931
enum File
3032
{
33+
#if os(Android)
34+
typealias Descriptor = OpaquePointer
35+
#else
3136
typealias Descriptor = UnsafeMutablePointer<FILE>
37+
#endif
3238

3339
/// A type for reading data from files on disk.
3440
public
@@ -100,7 +106,12 @@ extension System.File.Source
100106
{
101107
(buffer:inout UnsafeMutableBufferPointer<UInt8>, count:inout Int) in
102108

103-
count = fread(buffer.baseAddress, MemoryLayout<UInt8>.stride,
109+
#if os(Android)
110+
let baseAddress = buffer.baseAddress!
111+
#else
112+
let baseAddress = buffer.baseAddress
113+
#endif
114+
count = fread(baseAddress, MemoryLayout<UInt8>.stride,
104115
capacity, self.descriptor)
105116
}
106117

@@ -213,7 +224,12 @@ extension System.File.Destination
213224
{
214225
let count:Int = buffer.withUnsafeBufferPointer
215226
{
216-
fwrite($0.baseAddress, MemoryLayout<UInt8>.stride,
227+
#if os(Android)
228+
let baseAddress = $0.baseAddress!
229+
#else
230+
let baseAddress = $0.baseAddress
231+
#endif
232+
return fwrite(baseAddress, MemoryLayout<UInt8>.stride,
217233
$0.count, self.descriptor)
218234
}
219235

0 commit comments

Comments
 (0)