Skip to content

Commit

Permalink
Consolidate some CI code and patches after removing support for NDK 25
Browse files Browse the repository at this point in the history
  • Loading branch information
finagolfin committed Aug 29, 2024
1 parent 54866b7 commit 9c21449
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 142 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,21 @@ jobs:
tar xf ~/$SWIFT_TAG-ubuntu22.04.tar.gz
./$SWIFT_TAG-ubuntu22.04/usr/bin/swift --version
git apply swift-android-ci.patch
git apply -C1 swift-android.patch swift-android-both-ndks.patch
git apply -C1 swift-android.patch
git apply -C0 swift-android-foundation-ndk26.patch
if [[ ${{ matrix.version }} = 'release' ]]; then
sed -i "s%strsignal(signal).map%String(cString: strsignal(signal)) //%" swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift
git apply swift-android-stdlib-except-trunk.patch
git apply swift-android-release-stdlib.patch
STUPID_FILE_RENAMING=Tool
else
sed -i "s%r26%ndk/27%" swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
STUPID_FILE_RENAMING=Command
fi
git apply -C0 swift-android-foundation-ndk26.patch
if [ ${{ matrix.version }} = 'release' ]; then
git apply swift-android-stdlib-ndk26.patch
else
if [ ${{ matrix.version }} = 'devel' ]; then
git apply android-overlay/import-android-devel.patch
else
git apply swift-android-foundation-trunk.patch
fi
git apply android-overlay/foundation-fixes.patch android-overlay/swift-argument-parser.patch android-overlay/swift-stdlib-modulemap.patch android-overlay/swift-system.patch android-overlay/yams.patch
STUPID_FILE_RENAMING=Command
fi
sed -i "s%/data/data/com.termux/files%$SDK%" $SDK/usr/lib/pkgconfig/sqlite3.pc
Expand Down
119 changes: 0 additions & 119 deletions swift-android-both-ndks.patch

This file was deleted.

119 changes: 119 additions & 0 deletions swift-android-foundation-ndk26.patch
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,122 @@ index d90ece91..d2bbd22b 100644
return fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil)
}
if _stream == nil {
diff --git a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift
index a538a297..0a757c4b 100644
--- a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift
+++ b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift
@@ -310,9 +310,15 @@ open class FileHandle : NSObject {
let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0)
// Swift does not currently expose MAP_FAILURE
if data != UnsafeMutableRawPointer(bitPattern: -1) {
+ #if os(Android)
+ return NSData.NSDataReadResult(bytes: data, length: mapSize) { buffer, length in
+ munmap(buffer, length)
+ }
+ #else
return NSData.NSDataReadResult(bytes: data!, length: mapSize) { buffer, length in
munmap(buffer, length)
}
+ #endif
}
}

diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift
index d90ece91..d2bbd22b 100644
--- a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift
+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift
@@ -741,13 +741,13 @@ extension FileManager {
ps.deinitialize(count: 2)
ps.deallocate()

- if stream != nil {
+ if let openStream = stream {
defer {
- fts_close(stream)
+ fts_close(openStream)
}

- while let current = fts_read(stream)?.pointee {
- let itemPath = string(withFileSystemRepresentation: current.fts_path, length: Int(current.fts_pathlen))
+ while let current = fts_read(openStream)?.pointee, let current_path = current.fts_path {
+ let itemPath = string(withFileSystemRepresentation: current_path, length: Int(current.fts_pathlen))
guard alreadyConfirmed || shouldRemoveItemAtPath(itemPath, isURL: isURL) else {
continue
}
@@ -762,11 +768,11 @@ extension FileManager {
do {
switch Int32(current.fts_info) {
case FTS_DEFAULT, FTS_F, FTS_NSOK, FTS_SL, FTS_SLNONE:
- if unlink(current.fts_path) == -1 {
+ if unlink(current_path) == -1 {
throw _NSErrorWithErrno(errno, reading: false, path: itemPath)
}
case FTS_DP:
- if rmdir(current.fts_path) == -1 {
+ if rmdir(current_path) == -1 {
throw _NSErrorWithErrno(errno, reading: false, path: itemPath)
}
case FTS_DNR, FTS_ERR, FTS_NS:
@@ -1135,14 +1149,14 @@ extension FileManager {
}

_current = fts_read(stream)
- while let current = _current {
- let filename = FileManager.default.string(withFileSystemRepresentation: current.pointee.fts_path, length: Int(current.pointee.fts_pathlen))
+ while let current = _current, let current_path = current.pointee.fts_path {
+ let filename = FileManager.default.string(withFileSystemRepresentation: current_path, length: Int(current.pointee.fts_pathlen))

switch Int32(current.pointee.fts_info) {
case FTS_D:
let (showFile, skipDescendants) = match(filename: filename, to: _options, isDir: true)
if skipDescendants {
- fts_set(_stream, _current, FTS_SKIP)
+ fts_set(stream, current, FTS_SKIP)
}
if showFile {
return URL(fileURLWithPath: filename, isDirectory: true)
@@ -1315,7 +1329,7 @@ extension FileManager {
let finalErrno = originalItemURL.withUnsafeFileSystemRepresentation { (originalFS) -> Int32? in
return newItemURL.withUnsafeFileSystemRepresentation { (newItemFS) -> Int32? in
// This is an atomic operation in many OSes, but is not guaranteed to be atomic by the standard.
- if rename(newItemFS, originalFS) == 0 {
+ if let newFS = newItemFS, let origFS = originalFS, rename(newFS, origFS) == 0 {
return nil
} else {
return errno
diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift
index 1aa3038a..9fdb495c 100644
--- a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift
+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift
@@ -568,13 +568,13 @@ open class FileManager : NSObject {
let attributes = try windowsFileAttributes(atPath: path)
let type = FileAttributeType(attributes: attributes, atPath: path)
#else
- if let pwd = getpwuid(s.st_uid), pwd.pointee.pw_name != nil {
- let name = String(cString: pwd.pointee.pw_name)
+ if let pwd = getpwuid(s.st_uid), let pwd_name = pwd.pointee.pw_name {
+ let name = String(cString: pwd_name)
result[.ownerAccountName] = name
}

- if let grd = getgrgid(s.st_gid), grd.pointee.gr_name != nil {
- let name = String(cString: grd.pointee.gr_name)
+ if let grd = getgrgid(s.st_gid), let grd_name = grd.pointee.gr_name {
+ let name = String(cString: grd_name)
result[.groupOwnerAccountName] = name
}

diff --git a/swift-corelibs-foundation/Sources/Foundation/Host.swift b/swift-corelibs-foundation/Sources/Foundation/Host.swift
index 5fe7b29c..ce571abe 100644
--- a/swift-corelibs-foundation/Sources/Foundation/Host.swift
+++ b/swift-corelibs-foundation/Sources/Foundation/Host.swift
@@ -25,7 +25,8 @@ import WinSDK

// getnameinfo uses size_t for its 4th and 6th arguments.
private func getnameinfo(_ addr: UnsafePointer<sockaddr>?, _ addrlen: socklen_t, _ host: UnsafeMutablePointer<Int8>?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer<Int8>?, _ servlen: socklen_t, _ flags: Int32) -> Int32 {
- return Glibc.getnameinfo(addr, addrlen, host, Int(hostlen), serv, Int(servlen), flags)
+ guard let saddr = addr else { return -1 }
+ return Glibc.getnameinfo(saddr, addrlen, host, Int(hostlen), serv, Int(servlen), flags)
}

// getifaddrs and freeifaddrs are not available in Android 6.0 or earlier, so call these functions dynamically.
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,16 @@ index f8daa50325c..66be85a77f0 100644
#else
return pipe(unsafeFds.baseAddress)
#endif
diff --git a/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h b/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h
index 1e4132f6279..045b8a28746 100644
--- a/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h
+++ b/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h
@@ -61,7 +61,7 @@ SWIFT_READONLY
static inline int _swift_stdlib_memcmp(const void *s1, const void *s2,
__swift_size_t n) {
// FIXME: Is there a way to identify Glibc specifically?
-#if defined(__gnu_linux__)
+#if defined(__gnu_linux__) || defined(__ANDROID__)
extern int memcmp(const void * _Nonnull, const void * _Nonnull, __swift_size_t);
#else
extern int memcmp(const void * _Null_unspecified, const void * _Null_unspecified, __swift_size_t);
13 changes: 0 additions & 13 deletions swift-android-stdlib-ndk26.patch

This file was deleted.

1 change: 0 additions & 1 deletion swift-android.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/swift/utils/swift_build_support/swift_build_support/targets.py
index 9932b854cb6..ad3ac757665 100644
--- a/swift/utils/swift_build_support/swift_build_support/targets.py
Expand Down

0 comments on commit 9c21449

Please sign in to comment.