Skip to content

Commit da59322

Browse files
committed
Move Alex's patch on the CI that was just merged to trunk
1 parent 8603acd commit da59322

6 files changed

+705
-349
lines changed

.github/workflows/sdks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ jobs:
214214
else
215215
if [ ${{ matrix.version }} = 'devel' ]; then
216216
git apply swift-android-foundation-devel.patch
217+
else
218+
git apply swift-android-foundation-trunk.patch
217219
fi
218220
git apply swift-android-ci-except-release.patch swift-android-foundation-except-release.patch
219221
fi

swift-android-foundation-devel.patch

Lines changed: 349 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,355 @@ index 2b5b5e05..60f1dde8 100644
3939
],
4040
resources: [
4141
.copy("Foundation/Resources")
42+
diff --git a/swift-corelibs-foundation/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h b/swift-corelibs-foundation/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h
43+
index a2ba56cd..91a312dc 100644
44+
--- a/swift-corelibs-foundation/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h
45+
+++ b/swift-corelibs-foundation/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h
46+
@@ -69,6 +69,13 @@
47+
#include <sys/stat.h>
48+
#include <sys/syscall.h>
49+
#include <termios.h>
50+
+#include <linux/fcntl.h>
51+
+#ifdef __swift__
52+
+// The linux/stat header is private in the Android modulemap.
53+
+#pragma clang module import posix_filesystem.linux_stat
54+
+#else
55+
+#include <linux/stat.h>
56+
+#endif
57+
#elif TARGET_OS_WASI
58+
#include <fcntl.h>
59+
#include <sys/stat.h>
60+
diff --git a/swift-corelibs-foundation/Sources/Foundation/CGFloat.swift b/swift-corelibs-foundation/Sources/Foundation/CGFloat.swift
61+
index ffe3a6c6..c59977f8 100644
62+
--- a/swift-corelibs-foundation/Sources/Foundation/CGFloat.swift
63+
+++ b/swift-corelibs-foundation/Sources/Foundation/CGFloat.swift
64+
@@ -7,6 +7,10 @@
65+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
66+
//
67+
68+
+#if canImport(Android)
69+
+import Android
70+
+#endif
71+
+
72+
@frozen
73+
public struct CGFloat: Sendable {
74+
#if arch(i386) || arch(arm) || arch(wasm32)
75+
diff --git a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift
76+
index b07c49ac..b540e284 100644
77+
--- a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift
78+
+++ b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift
79+
@@ -34,6 +34,11 @@ import WASILibc
80+
fileprivate let _read = WASILibc.read(_:_:_:)
81+
fileprivate let _write = WASILibc.write(_:_:_:)
82+
fileprivate let _close = WASILibc.close(_:)
83+
+#elseif canImport(Android)
84+
+import Android
85+
+fileprivate let _read = Android.read(_:_:_:)
86+
+fileprivate let _write = Android.write(_:_:_:)
87+
+fileprivate let _close = Android.close(_:)
88+
#endif
89+
90+
#if canImport(WinSDK)
91+
@@ -321,10 +326,15 @@ open class FileHandle : NSObject, @unchecked Sendable {
92+
if options.contains(.alwaysMapped) {
93+
// Filesizes are often 64bit even on 32bit systems
94+
let mapSize = min(length, Int(clamping: statbuf.st_size))
95+
+ #if canImport(Android)
96+
+ // Bionic mmap() now returns _Nonnull, so the force unwrap below isn't needed.
97+
let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0)
98+
+ #else
99+
+ let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0)!
100+
+ #endif
101+
// Swift does not currently expose MAP_FAILURE
102+
if data != UnsafeMutableRawPointer(bitPattern: -1) {
103+
- return NSData.NSDataReadResult(bytes: data!, length: mapSize) { buffer, length in
104+
+ return NSData.NSDataReadResult(bytes: data, length: mapSize) { buffer, length in
105+
munmap(buffer, length)
106+
}
107+
}
108+
diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift
109+
index e89b3bf6..a82fe1c2 100644
110+
--- a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift
111+
+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift
112+
@@ -7,6 +7,10 @@
113+
//
114+
#if !os(Windows)
115+
116+
+#if canImport(Android)
117+
+import Android
118+
+#endif
119+
+
120+
#if os(Android) && (arch(i386) || arch(arm)) // struct stat.st_mode is UInt32
121+
internal func &(left: UInt32, right: mode_t) -> mode_t {
122+
return mode_t(left) & right
123+
@@ -398,13 +402,13 @@ extension FileManager {
124+
125+
_current = fts_read(stream)
126+
while let current = _current {
127+
- let filename = FileManager.default.string(withFileSystemRepresentation: current.pointee.fts_path, length: Int(current.pointee.fts_pathlen))
128+
+ let filename = FileManager.default.string(withFileSystemRepresentation: current.pointee.fts_path!, length: Int(current.pointee.fts_pathlen))
129+
130+
switch Int32(current.pointee.fts_info) {
131+
case FTS_D:
132+
let (showFile, skipDescendants) = match(filename: filename, to: _options, isDir: true)
133+
if skipDescendants {
134+
- fts_set(_stream, _current, FTS_SKIP)
135+
+ fts_set(stream, current, FTS_SKIP)
136+
}
137+
if showFile {
138+
return URL(fileURLWithPath: filename, isDirectory: true)
139+
@@ -578,7 +582,7 @@ extension FileManager {
140+
let finalErrno = originalItemURL.withUnsafeFileSystemRepresentation { (originalFS) -> Int32? in
141+
return newItemURL.withUnsafeFileSystemRepresentation { (newItemFS) -> Int32? in
142+
// This is an atomic operation in many OSes, but is not guaranteed to be atomic by the standard.
143+
- if rename(newItemFS, originalFS) == 0 {
144+
+ if rename(newItemFS!, originalFS!) == 0 {
145+
return nil
146+
} else {
147+
return errno
148+
diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift
149+
index a5d75820..a19464d7 100644
150+
--- a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift
151+
+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift
152+
@@ -21,6 +21,8 @@ import WinSDK
153+
154+
#if os(WASI)
155+
import WASILibc
156+
+#elseif canImport(Bionic)
157+
+import Bionic
158+
#endif
159+
160+
#if os(Windows)
161+
diff --git a/swift-corelibs-foundation/Sources/Foundation/Host.swift b/swift-corelibs-foundation/Sources/Foundation/Host.swift
162+
index 6c4f5291..fb130631 100644
163+
--- a/swift-corelibs-foundation/Sources/Foundation/Host.swift
164+
+++ b/swift-corelibs-foundation/Sources/Foundation/Host.swift
165+
@@ -12,8 +12,9 @@
166+
import WinSDK
167+
#endif
168+
169+
-#if os(Android)
170+
- // Android Glibc differs a little with respect to the Linux Glibc.
171+
+#if canImport(Android)
172+
+ import Android
173+
+ // Android Bionic differs a little with respect to the Linux Glibc.
174+
175+
// IFF_LOOPBACK is part of the enumeration net_device_flags, which needs to
176+
// convert to UInt32.
177+
@@ -24,8 +25,8 @@ import WinSDK
178+
}
179+
180+
// getnameinfo uses size_t for its 4th and 6th arguments.
181+
- private func getnameinfo(_ addr: UnsafePointer<sockaddr>?, _ addrlen: socklen_t, _ host: UnsafeMutablePointer<Int8>?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer<Int8>?, _ servlen: socklen_t, _ flags: Int32) -> Int32 {
182+
- return Glibc.getnameinfo(addr, addrlen, host, Int(hostlen), serv, Int(servlen), flags)
183+
+ private func getnameinfo(_ addr: UnsafePointer<sockaddr>, _ addrlen: socklen_t, _ host: UnsafeMutablePointer<Int8>?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer<Int8>?, _ servlen: socklen_t, _ flags: Int32) -> Int32 {
184+
+ return Android.getnameinfo(addr, addrlen, host, Int(hostlen), serv, Int(servlen), flags)
185+
}
186+
187+
// getifaddrs and freeifaddrs are not available in Android 6.0 or earlier, so call these functions dynamically.
188+
diff --git a/swift-corelibs-foundation/Sources/Foundation/NSData.swift b/swift-corelibs-foundation/Sources/Foundation/NSData.swift
189+
index ae54f971..65eb0d93 100644
190+
--- a/swift-corelibs-foundation/Sources/Foundation/NSData.swift
191+
+++ b/swift-corelibs-foundation/Sources/Foundation/NSData.swift
192+
@@ -11,6 +11,9 @@
193+
#if !os(WASI)
194+
import Dispatch
195+
#endif
196+
+#if canImport(Android)
197+
+import Android
198+
+#endif
199+
200+
extension NSData {
201+
public typealias ReadingOptions = Data.ReadingOptions
202+
@@ -469,6 +472,8 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
203+
let createMode = Int(Musl.S_IRUSR) | Int(Musl.S_IWUSR) | Int(Musl.S_IRGRP) | Int(Musl.S_IWGRP) | Int(Musl.S_IROTH) | Int(Musl.S_IWOTH)
204+
#elseif canImport(WASILibc)
205+
let createMode = Int(WASILibc.S_IRUSR) | Int(WASILibc.S_IWUSR) | Int(WASILibc.S_IRGRP) | Int(WASILibc.S_IWGRP) | Int(WASILibc.S_IROTH) | Int(WASILibc.S_IWOTH)
206+
+#elseif canImport(Android)
207+
+ let createMode = Int(Android.S_IRUSR) | Int(Android.S_IWUSR) | Int(Android.S_IRGRP) | Int(Android.S_IWGRP) | Int(Android.S_IROTH) | Int(Android.S_IWOTH)
208+
#endif
209+
guard let fh = FileHandle(path: path, flags: flags, createMode: createMode) else {
210+
throw _NSErrorWithErrno(errno, reading: false, path: path)
211+
diff --git a/swift-corelibs-foundation/Sources/Foundation/NSError.swift b/swift-corelibs-foundation/Sources/Foundation/NSError.swift
212+
index 6f21d3a0..dcd6f3f1 100644
213+
--- a/swift-corelibs-foundation/Sources/Foundation/NSError.swift
214+
+++ b/swift-corelibs-foundation/Sources/Foundation/NSError.swift
215+
@@ -16,6 +16,8 @@ import Darwin
216+
import Glibc
217+
#elseif canImport(CRT)
218+
import CRT
219+
+#elseif canImport(Android)
220+
+import Android
221+
#endif
222+
223+
@_implementationOnly import CoreFoundation
224+
diff --git a/swift-corelibs-foundation/Sources/Foundation/NSLock.swift b/swift-corelibs-foundation/Sources/Foundation/NSLock.swift
225+
index fe1d08b7..9d0fadc9 100644
226+
--- a/swift-corelibs-foundation/Sources/Foundation/NSLock.swift
227+
+++ b/swift-corelibs-foundation/Sources/Foundation/NSLock.swift
228+
@@ -11,6 +11,8 @@
229+
230+
#if canImport(Glibc)
231+
import Glibc
232+
+#elseif canImport(Bionic)
233+
+import Bionic
234+
#endif
235+
236+
#if os(Windows)
237+
diff --git a/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift b/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift
238+
index 8043ef00..23b602f6 100644
239+
--- a/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift
240+
+++ b/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift
241+
@@ -10,6 +10,8 @@
242+
@_implementationOnly import CoreFoundation
243+
#if os(Windows)
244+
import WinSDK
245+
+#elseif canImport(Android)
246+
+import Android
247+
#elseif os(WASI)
248+
import WASILibc
249+
#endif
250+
diff --git a/swift-corelibs-foundation/Sources/Foundation/NSPlatform.swift b/swift-corelibs-foundation/Sources/Foundation/NSPlatform.swift
251+
index a1809026..5424f5bb 100644
252+
--- a/swift-corelibs-foundation/Sources/Foundation/NSPlatform.swift
253+
+++ b/swift-corelibs-foundation/Sources/Foundation/NSPlatform.swift
254+
@@ -10,6 +10,9 @@
255+
#if os(macOS) || os(iOS)
256+
fileprivate let _NSPageSize = Int(vm_page_size)
257+
#elseif os(Linux) || os(Android) || os(OpenBSD)
258+
+#if canImport(Android)
259+
+import Android
260+
+#endif
261+
fileprivate let _NSPageSize = Int(getpagesize())
262+
#elseif os(Windows)
263+
import WinSDK
264+
diff --git a/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift b/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift
265+
index 03176c17..1509c31d 100644
266+
--- a/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift
267+
+++ b/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift
268+
@@ -19,6 +19,8 @@ internal import Synchronization
269+
@_exported import Glibc
270+
#elseif canImport(Musl)
271+
@_exported import Musl
272+
+#elseif canImport(Bionic)
273+
+@_exported import Bionic
274+
#elseif os(WASI)
275+
@_exported import WASILibc
276+
#elseif os(Windows)
277+
diff --git a/swift-corelibs-foundation/Sources/Foundation/NSURL.swift b/swift-corelibs-foundation/Sources/Foundation/NSURL.swift
278+
index 6af73f16..9e6f20d0 100644
279+
--- a/swift-corelibs-foundation/Sources/Foundation/NSURL.swift
280+
+++ b/swift-corelibs-foundation/Sources/Foundation/NSURL.swift
281+
@@ -22,6 +22,8 @@ import Darwin
282+
import Glibc
283+
#elseif canImport(Musl)
284+
import Musl
285+
+#elseif canImport(Bionic)
286+
+import Bionic
287+
#endif
288+
289+
// NOTE: this represents PLATFORM_PATH_STYLE
290+
diff --git a/swift-corelibs-foundation/Sources/Foundation/Port.swift b/swift-corelibs-foundation/Sources/Foundation/Port.swift
291+
index c4ed8282..e71f591b 100644
292+
--- a/swift-corelibs-foundation/Sources/Foundation/Port.swift
293+
+++ b/swift-corelibs-foundation/Sources/Foundation/Port.swift
294+
@@ -107,7 +107,7 @@ fileprivate let FOUNDATION_SOCK_STREAM = SOCK_STREAM
295+
fileprivate let FOUNDATION_IPPROTO_TCP = IPPROTO_TCP
296+
#endif
297+
298+
-#if canImport(Glibc) && !os(Android) && !os(OpenBSD)
299+
+#if canImport(Glibc) && !os(OpenBSD)
300+
import Glibc
301+
fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM.rawValue)
302+
fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
303+
@@ -119,14 +119,19 @@ fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM)
304+
fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
305+
#endif
306+
307+
-#if canImport(Glibc) && os(Android) || os(OpenBSD)
308+
+#if canImport(Glibc) && os(OpenBSD)
309+
import Glibc
310+
fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM)
311+
fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
312+
fileprivate let INADDR_ANY: in_addr_t = 0
313+
-#if os(OpenBSD)
314+
fileprivate let INADDR_LOOPBACK = 0x7f000001
315+
#endif
316+
+
317+
+#if canImport(Android)
318+
+import Android
319+
+fileprivate let FOUNDATION_SOCK_STREAM = Int32(Android.SOCK_STREAM)
320+
+fileprivate let FOUNDATION_IPPROTO_TCP = Int32(Android.IPPROTO_TCP)
321+
+fileprivate let INADDR_ANY: in_addr_t = 0
322+
#endif
323+
324+
325+
diff --git a/swift-corelibs-foundation/Sources/Foundation/Process.swift b/swift-corelibs-foundation/Sources/Foundation/Process.swift
326+
index ee35c23a..5e8cfbaa 100644
327+
--- a/swift-corelibs-foundation/Sources/Foundation/Process.swift
328+
+++ b/swift-corelibs-foundation/Sources/Foundation/Process.swift
329+
@@ -18,6 +18,8 @@ import struct WinSDK.HANDLE
330+
331+
#if canImport(Darwin)
332+
import Darwin
333+
+#elseif canImport(Android)
334+
+import Android
335+
#endif
336+
337+
internal import Synchronization
338+
diff --git a/swift-corelibs-foundation/Sources/Foundation/Thread.swift b/swift-corelibs-foundation/Sources/Foundation/Thread.swift
339+
index 5e79579c..0985a482 100644
340+
--- a/swift-corelibs-foundation/Sources/Foundation/Thread.swift
341+
+++ b/swift-corelibs-foundation/Sources/Foundation/Thread.swift
342+
@@ -17,6 +17,8 @@ import WinSDK
343+
import Glibc
344+
#elseif canImport(Musl)
345+
import Musl
346+
+#elseif canImport(Bionic)
347+
+import Bionic
348+
#endif
349+
350+
// WORKAROUND_SR9811
351+
diff --git a/swift-corelibs-foundation/Sources/FoundationNetworking/HTTPCookie.swift b/swift-corelibs-foundation/Sources/FoundationNetworking/HTTPCookie.swift
352+
index e0d1cbbd..237c1daf 100644
353+
--- a/swift-corelibs-foundation/Sources/FoundationNetworking/HTTPCookie.swift
354+
+++ b/swift-corelibs-foundation/Sources/FoundationNetworking/HTTPCookie.swift
355+
@@ -15,6 +15,8 @@ import Foundation
356+
357+
#if os(Windows)
358+
import WinSDK
359+
+#elseif canImport(Android)
360+
+import Android
361+
#endif
362+
363+
public struct HTTPCookiePropertyKey : RawRepresentable, Equatable, Hashable, Sendable {
364+
diff --git a/swift-corelibs-foundation/Sources/plutil/main.swift b/swift-corelibs-foundation/Sources/plutil/main.swift
365+
index 29316d16..29584596 100644
366+
--- a/swift-corelibs-foundation/Sources/plutil/main.swift
367+
+++ b/swift-corelibs-foundation/Sources/plutil/main.swift
368+
@@ -15,6 +15,9 @@ import Glibc
369+
#elseif canImport(Musl)
370+
import Foundation
371+
import Musl
372+
+#elseif canImport(Bionic)
373+
+import Foundation
374+
+import Bionic
375+
#elseif canImport(CRT)
376+
import Foundation
377+
import CRT
378+
diff --git a/swift-corelibs-foundation/Sources/xdgTestHelper/main.swift b/swift-corelibs-foundation/Sources/xdgTestHelper/main.swift
379+
index d515a63f..fb037e24 100644
380+
--- a/swift-corelibs-foundation/Sources/xdgTestHelper/main.swift
381+
+++ b/swift-corelibs-foundation/Sources/xdgTestHelper/main.swift
382+
@@ -19,6 +19,8 @@ import FoundationNetworking
383+
#endif
384+
#if os(Windows)
385+
import WinSDK
386+
+#elseif canImport(Android)
387+
+import Android
388+
#endif
389+
390+
enum HelperCheckStatus : Int32 {
42391
commit 4339393f2c1f3bceaf20bc2c25ee828a2e0394aa
43392
Author: Alex Lorenz <[email protected]>
44393
Date: Thu Dec 12 07:34:34 2024 -0800

swift-android-foundation-except-release.patch

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ index 16e05052609..7ab8cebfab8 100755
1010

1111
cmake_options=(
1212
-DENABLE_SWIFT=YES
13-
diff --git a/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift b/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift
14-
index 8043ef00..23b602f6 100644
15-
--- a/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift
16-
+++ b/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift
17-
@@ -10,6 +10,8 @@
18-
@_implementationOnly import CoreFoundation
19-
#if os(Windows)
20-
import WinSDK
21-
+#elseif canImport(Android)
22-
+import Android
23-
#elseif os(WASI)
24-
import WASILibc
25-
#endif
2613
diff --git a/swift-corelibs-foundation/Sources/Foundation/Process.swift b/swift-corelibs-foundation/Sources/Foundation/Process.swift
2714
index 758dd1df..02970992 100644
2815
--- a/swift-corelibs-foundation/Sources/Foundation/Process.swift

0 commit comments

Comments
 (0)