Skip to content

Commit 640b21c

Browse files
Fix Android builds with NDK r28 and later (#203)
The nullability annotations of many POSIX functions changed in r28. Also switch the CI to test with both the latest LTS version (r27d) and the latest stable version (r29).
1 parent 40b3fdc commit 640b21c

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
macos_build_command: 'xcrun swift-format lint -s -r --configuration ./.swift-format . && xcrun swift test && xcrun swift test -c release && xcrun swift test --disable-default-traits'
4040
enable_linux_static_sdk_build: true
4141
enable_android_sdk_build: true
42+
android_ndk_version: '["r27d", "r29"]'
4243
linux_static_sdk_versions: '["6.1", "nightly-6.2"]'
4344
linux_static_sdk_build_command: |
4445
for triple in aarch64-swift-linux-musl x86_64-swift-linux-musl ; do

Sources/Subprocess/Thread.swift

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -307,29 +307,16 @@ internal func pthread_create(
307307
self.body = body
308308
}
309309
}
310-
#if canImport(Darwin)
311-
func proc(_ context: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer? {
312-
(Unmanaged<AnyObject>.fromOpaque(context).takeRetainedValue() as! Context).body()
313-
return context
314-
}
315-
#elseif canImport(Glibc) || canImport(Musl)
316310
func proc(_ context: UnsafeMutableRawPointer?) -> UnsafeMutableRawPointer? {
317311
(Unmanaged<AnyObject>.fromOpaque(context!).takeRetainedValue() as! Context).body()
318312
return context
319313
}
320-
#elseif canImport(Bionic)
321-
func proc(_ context: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer {
322-
(Unmanaged<AnyObject>.fromOpaque(context).takeRetainedValue() as! Context).body()
323-
return context
324-
}
325-
#endif
326-
327314
#if canImport(Glibc) || canImport(Bionic)
328315
var thread = pthread_t()
329316
#else
330317
var thread: pthread_t?
331318
#endif
332-
let rc = pthread_create(
319+
let rc = _subprocess_pthread_create(
333320
&thread,
334321
nil,
335322
proc,

Sources/_SubprocessCShims/include/process_shims.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "target_conditionals.h"
1616

1717
#if !TARGET_OS_WINDOWS
18+
#include <pthread.h>
1819
#include <unistd.h>
1920

2021
#if _POSIX_SPAWN
@@ -39,6 +40,13 @@
3940
extern "C" {
4041
#endif
4142

43+
int _subprocess_pthread_create(
44+
pthread_t * _Nonnull ptr,
45+
pthread_attr_t const * _Nullable attr,
46+
void * _Nullable (* _Nonnull start)(void * _Nullable),
47+
void * _Nullable context
48+
);
49+
4250
#if __has_include(<mach/vm_page_size.h>)
4351
vm_size_t _subprocess_vm_size(void);
4452
#endif

Sources/_SubprocessCShims/process_shims.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ int _was_process_suspended(int status) {
7979
return WIFSTOPPED(status);
8080
}
8181

82+
int _subprocess_pthread_create(
83+
pthread_t * _Nonnull ptr,
84+
pthread_attr_t const * _Nullable attr,
85+
void * _Nullable (* _Nonnull start)(void * _Nullable),
86+
void * _Nullable context
87+
) {
88+
return pthread_create(ptr, attr, start, context);
89+
}
90+
8291
#endif
8392

8493
#if __has_include(<mach/vm_page_size.h>)

0 commit comments

Comments
 (0)