-
Notifications
You must be signed in to change notification settings - Fork 15
/
swift-android-foundation-release.patch
313 lines (286 loc) · 15.4 KB
/
swift-android-foundation-release.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
diff --git a/swift/stdlib/public/Platform/android.modulemap b/swift/stdlib/public/Platform/android.modulemap
index 78e7bda9976..dc25e5c3668 100644
--- a/swift/stdlib/public/Platform/android.modulemap
+++ b/swift/stdlib/public/Platform/android.modulemap
@@ -556,6 +556,12 @@ module _bits_sa_family_t [system] {
header "bits/sa_family_t.h"
export *
}
+
+module _bits_sockaddr_storage [system] {
+ header "bits/sockaddr_storage.h"
+ export *
+}
+
module _bits_stdatomic [system] {
// Note: this module is not part of 'stdatomic'
// as it depends on libc++ and forcing it to
diff --git a/swift-corelibs-foundation/Package.swift b/swift-corelibs-foundation/Package.swift
--- a/swift-corelibs-foundation/Package.swift
+++ b/swift-corelibs-foundation/Package.swift
@@ -176,7 +176,8 @@
"BlockRuntime",
"CMakeLists.txt"
],
- cSettings: coreFoundationBuildSettings
+ cSettings: coreFoundationBuildSettings,
+ linkerSettings: [.linkedLibrary("log", .when(platforms: [.android]))]
),
.target(
name: "_CFXMLInterface",
diff --git a/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift b/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift
--- a/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift
+++ b/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift
@@ -19,6 +19,8 @@
get { WASILibc.errno }
set { WASILibc.errno = newValue }
}
+#elseif os(Android)
+import Android
#endif
#if os(Windows)
diff --git a/swift-corelibs-foundation/Sources/Foundation/Process.swift b/swift-corelibs-foundation/Sources/Foundation/Process.swift
index 758dd1df..02970992 100644
--- a/swift-corelibs-foundation/Sources/Foundation/Process.swift
+++ b/swift-corelibs-foundation/Sources/Foundation/Process.swift
@@ -927,8 +927,8 @@ open class Process: NSObject, @unchecked Sendable {
}
let useFallbackChdir: Bool
if let dir = currentDirectoryURL?.path {
- let chdirResult = _CFPosixSpawnFileActionsChdir(fileActions, dir)
- useFallbackChdir = chdirResult == ENOSYS
+ // let chdirResult = _CFPosixSpawnFileActionsChdir(fileActions, dir)
+ useFallbackChdir = true ; let chdirResult = ENOSYS
if !useFallbackChdir {
try _throwIfPosixError(chdirResult)
}
From ab001004196b249af359d6152e5c2d06c11bee56
From: Alex Lorenz <arphaman@gmail.com>
Date: Tue, 29 Oct 2024 13:00:11 -0700
Subject: [PATCH] [android] fix the android build (#999)
Platform.swift regressed after 71eefee7fca08ecbeacc89098b74ab80319baa6b
---
diff --git a/swift-foundation/Sources/FoundationEssentials/Platform.swift b/swift-foundation/Sources/FoundationEssentials/Platform.swift
index d8b8fe6f..15a1362f 100644
--- a/swift-foundation/Sources/FoundationEssentials/Platform.swift
+++ b/swift-foundation/Sources/FoundationEssentials/Platform.swift
@@ -29,8 +29,7 @@ fileprivate let _pageSize: Int = {
// WebAssembly defines a fixed page size
fileprivate let _pageSize: Int = 65_536
#elseif os(Android)
-import Bionic
-import unistd
+import Android
fileprivate let _pageSize: Int = Int(getpagesize())
#elseif canImport(Glibc)
import Glibc
@@ -142,7 +141,7 @@ extension Platform {
typealias Operation<Input, Output> = (Input, UnsafeMutablePointer<Output>, UnsafeMutablePointer<CChar>, Int, UnsafeMutablePointer<UnsafeMutablePointer<Output>?>) -> Int32
#endif
- private static func withUserGroupBuffer<Input, Output, R>(_ input: Input, _ output: Output, sizeProperty: Int32, operation: Operation<Input, Output>, block: (Output) throws -> R) rethrows -> R? {
+ private static func withUserGroupBuffer<Input, Output, R>(_ input: Input, _ output: Output, sizeProperty: Int32, operation: Operation<Input, Output>, block: (Output) throws -> R?) rethrows -> R? {
var bufferLen = sysconf(sizeProperty)
if bufferLen == -1 {
bufferLen = 4096 // Generous default size estimate
@@ -172,31 +171,51 @@ extension Platform {
static func name(forUID uid: uid_t) -> String? {
withUserGroupBuffer(uid, passwd(), sizeProperty: Int32(_SC_GETPW_R_SIZE_MAX), operation: getpwuid_r) {
- String(cString: $0.pw_name)
+ // Android's pw_name `char *`` is nullable when it should be non-null.
+ // FIXME: avoid the coerce cast workaround once https://github.com/android/ndk/issues/2098 is fixed.
+ let pw_name: UnsafeMutablePointer<CChar>? = $0.pw_name
+ return pw_name.flatMap { String(cString: $0) }
}
}
static func fullName(forUID uid: uid_t) -> String? {
withUserGroupBuffer(uid, passwd(), sizeProperty: Int32(_SC_GETPW_R_SIZE_MAX), operation: getpwuid_r) {
- String(cString: $0.pw_gecos)
+#if os(Android) && _pointerBitWidth(_32)
+ // pw_gecos isn't available on 32-bit Android.
+ let pw_gecos: UnsafeMutablePointer<CChar>? = nil
+#else
+ // Android's pw_gecos `char *`` is nullable, so always coerce to a nullable pointer
+ // in order to be compatible with Android.
+ let pw_gecos: UnsafeMutablePointer<CChar>? = $0.pw_gecos
+#endif
+ return pw_gecos.flatMap { String(cString: $0) }
}
}
static func name(forGID gid: gid_t) -> String? {
withUserGroupBuffer(gid, group(), sizeProperty: Int32(_SC_GETGR_R_SIZE_MAX), operation: getgrgid_r) {
- String(cString: $0.gr_name)
+ // Android's gr_name `char *`` is nullable when it should be non-null.
+ // FIXME: avoid the coerce cast workaround once https://github.com/android/ndk/issues/2098 is fixed.
+ let gr_name: UnsafeMutablePointer<CChar>? = $0.gr_name
+ return gr_name.flatMap { String(cString: $0) }
}
}
static func homeDirectory(forUserName userName: String) -> String? {
withUserGroupBuffer(userName, passwd(), sizeProperty: Int32(_SC_GETPW_R_SIZE_MAX), operation: getpwnam_r) {
- String(cString: $0.pw_dir)
+ // Android's pw_dir `char *`` is nullable when it should be non-null.
+ // FIXME: avoid the coerce cast workaround once https://github.com/android/ndk/issues/2098 is fixed.
+ let pw_dir: UnsafeMutablePointer<CChar>? = $0.pw_dir
+ return pw_dir.flatMap { String(cString: $0) }
}
}
static func homeDirectory(forUID uid: uid_t) -> String? {
withUserGroupBuffer(uid, passwd(), sizeProperty: Int32(_SC_GETPW_R_SIZE_MAX), operation: getpwuid_r) {
- String(cString: $0.pw_dir)
+ // Android's pw_dir `char *`` is nullable when it should be non-null.
+ // FIXME: avoid the coerce cast workaround once https://github.com/android/ndk/issues/2098 is fixed.
+ let pw_dir: UnsafeMutablePointer<CChar>? = $0.pw_dir
+ return pw_dir.flatMap { String(cString: $0) }
}
}
}
commit ad6ca71b4eef90e3ae69b130e3cc989a21192020
Author: Alex Lorenz <arphaman@gmail.com>
Date: Wed Aug 14 10:56:25 2024 -0700
[android] fix the LP32 armv7/i686 android build (#846)
* [android] fix the LP32 armv7/i686 android build
* Update Sources/FoundationEssentials/Android+Extensions.swift
Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com>
* drop the android Lp32 specific operator &
---------
Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com>
diff --git a/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift b/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift
index 2540b14..a779837 100644
--- a/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift
+++ b/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift
@@ -325,7 +325,7 @@ internal func readBytesFromFile(path inPath: PathOrURL, reportProgress: Bool, ma
}
let fileSize = min(Int(clamping: filestat.st_size), maxLength ?? Int.max)
- let fileType = filestat.st_mode & S_IFMT
+ let fileType = mode_t(filestat.st_mode) & S_IFMT
#if !NO_FILESYSTEM
let shouldMap = shouldMapFileDescriptor(fd, path: inPath, options: options)
#else
diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift
index 991c5e8..d3e6de3 100644
--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift
+++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift
@@ -221,7 +221,7 @@ internal struct _FileManagerImpl {
var statBuf = stat()
let fd = open(path, 0, 0)
guard fd >= 0 else { return nil }
- if fstat(fd, &statBuf) < 0 || statBuf.st_mode & S_IFMT == S_IFDIR {
+ if fstat(fd, &statBuf) < 0 || mode_t(statBuf.st_mode) & S_IFMT == S_IFDIR {
close(fd)
return nil
}
@@ -240,7 +240,7 @@ internal struct _FileManagerImpl {
}
/* check for being same type */
- if myInfo.st_mode & S_IFMT != otherInfo.st_mode & S_IFMT {
+ if mode_t(myInfo.st_mode) & S_IFMT != mode_t(otherInfo.st_mode) & S_IFMT {
return false
}
diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift
index b8cd50a..bee9fb3 100644
--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift
+++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift
@@ -175,7 +175,8 @@ extension stat {
}
fileprivate var fileAttributes: [FileAttributeKey : Any] {
- let fileType = st_mode.fileType
+ // On 32 bit Android, st_mode is UInt32.
+ let fileType = mode_t(st_mode).fileType
var result: [FileAttributeKey : Any] = [
.size : _writeFileAttributePrimitive(st_size, as: UInt.self),
.modificationDate : modificationDate,
@@ -400,7 +401,7 @@ extension _FileManagerImpl {
guard stat(rep, &fileInfo) == 0 else {
return (false, false)
}
- let isDir = (fileInfo.st_mode & S_IFMT) == S_IFDIR
+ let isDir = (mode_t(fileInfo.st_mode) & S_IFMT) == S_IFDIR
return (true, isDir)
}
#endif
@@ -479,7 +480,7 @@ extension _FileManagerImpl {
return false
}
- if ((dirInfo.st_mode & S_ISVTX) != 0) && fileManager.fileExists(atPath: path) {
+ if ((mode_t(dirInfo.st_mode) & S_ISVTX) != 0) && fileManager.fileExists(atPath: path) {
// its sticky so verify that we own the file
// otherwise we answer YES on the principle that if
// we create files we can delete them
diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift
index 9bac967..e531cb5 100644
--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift
+++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift
@@ -49,19 +49,19 @@ extension FILETIME {
#if !os(Windows)
extension stat {
var isDirectory: Bool {
- (self.st_mode & S_IFMT) == S_IFDIR
+ (mode_t(self.st_mode) & S_IFMT) == S_IFDIR
}
var isRegular: Bool {
- (self.st_mode & S_IFMT) == S_IFREG
+ (mode_t(self.st_mode) & S_IFMT) == S_IFREG
}
var isSymbolicLink: Bool {
- (self.st_mode & S_IFMT) == S_IFLNK
+ (mode_t(self.st_mode) & S_IFMT) == S_IFLNK
}
var isSpecial: Bool {
- let type = self.st_mode & S_IFMT
+ let type = mode_t(self.st_mode) & S_IFMT
return type == S_IFBLK || type == S_IFCHR
}
}
diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift
index 2c9a02f..500da1d 100644
--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift
+++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift
@@ -367,7 +367,7 @@ struct _POSIXDirectoryContentsSequence: Sequence {
let statDir = directoryPath + "/" + fileName
if stat(statDir, &statBuf) == 0 {
// #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
- if (statBuf.st_mode & S_IFMT) == S_IFDIR {
+ if (mode_t(statBuf.st_mode) & S_IFMT) == S_IFDIR {
isDirectory = true
}
}
diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift
index 03adcc6..92e609f 100644
--- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift
+++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift
@@ -867,7 +867,7 @@ enum _FileOperations {
#if !os(WASI) // WASI doesn't have fchmod for now
// Set the file permissions using fchmod() instead of when open()ing to avoid umask() issues
- let permissions = fileInfo.st_mode & ~S_IFMT
+ let permissions = mode_t(fileInfo.st_mode) & ~S_IFMT
guard fchmod(dstfd, permissions) == 0 else {
try delegate.throwIfNecessary(errno, String(cString: srcPtr), String(cString: dstPtr))
return
diff --git a/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift b/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift
index 2e809fa..d01ca3f 100644
--- a/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift
+++ b/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift
@@ -198,7 +198,10 @@ final class _ProcessInfo: Sendable {
}
var fullUserName: String {
-#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
+#if os(Android) && (arch(i386) || arch(arm))
+ // On LP32 Android, pw_gecos doesn't exist and is presumed to be NULL.
+ return ""
+#elseif canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl)
let (euid, _) = Platform.getUGIDs()
if let fullName = Platform.fullName(forUID: euid) {
return fullName
diff --git a/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift b/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift
index 477d5d3..1ce75d6 100644
--- a/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift
+++ b/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift
@@ -737,7 +737,7 @@ extension String {
if lstat(buffer.baseAddress!, &statBuf) < 0 {
return nil
}
- if statBuf.st_mode & S_IFMT == S_IFLNK {
+ if mode_t(statBuf.st_mode) & S_IFMT == S_IFLNK {
/* Examples:
* fspath == /foo/bar0baz/quux/froboz
* linkx == /tic/tac/toe