Skip to content

Commit a4a5c41

Browse files
committed
Add support for posix_spawn_file_actions_addchdir{_np} on FreeBSD, NetBSD, Android, QNX, and Musl
This just syncs up the implementation with swift-corelibs-foundation which supports additional platforms. This will allow the working-directory attribute of llbuild build tasks to function correctly.
1 parent 0a1497d commit a4a5c41

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

lib/Basic/Subprocess.cpp

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,39 @@ int pthread_fchdir_np(int fd)
7575
#define __GLIBC_PREREQ(maj, min) 0
7676
#endif
7777

78-
#ifndef HAVE_POSIX_SPAWN_CHDIR
79-
#if defined(__sun) || \
80-
(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) || \
81-
__GLIBC_PREREQ(2, 29)
82-
#define HAVE_POSIX_SPAWN_CHDIR 1
83-
#else
84-
#define HAVE_POSIX_SPAWN_CHDIR 0
85-
#endif
86-
#endif
87-
8878
#if !defined(_WIN32) && defined(HAVE_POSIX_SPAWN)
79+
// Implementation mostly copied from _CFPosixSpawnFileActionsChdir in swift-corelibs-foundation
8980
static int posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t * __restrict file_actions,
9081
const char * __restrict path) {
91-
#if HAVE_POSIX_SPAWN_CHDIR
92-
return ::posix_spawn_file_actions_addchdir_np(file_actions, path);
93-
#else
94-
#if defined(__APPLE__) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500
82+
#if defined(__GLIBC__) && !__GLIBC_PREREQ(2, 29)
83+
// Glibc versions prior to 2.29 don't support posix_spawn_file_actions_addchdir_np, impacting:
84+
// - Amazon Linux 2 (EoL mid-2025)
85+
return ENOSYS;
86+
#elif defined(__APPLE__) && defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
87+
// Conditionally available on macOS if building with a deployment target older than 10.15
9588
if (__builtin_available(macOS 10.15, *)) {
96-
return ::posix_spawn_file_actions_addchdir_np(file_actions, path);
89+
return posix_spawn_file_actions_addchdir_np(file_actions, path);
9790
}
98-
#endif
99-
100-
// Any other POSIX platform returns ENOSYS (Function not implemented),
101-
// to simplify the fallback logic around the call site.
10291
return ENOSYS;
92+
#elif defined(__OpenBSD__)
93+
// Currently missing as of:
94+
// - OpenBSD 7.5 (April 2024)
95+
return ENOSYS;
96+
#elif defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) || (defined(__ANDROID__) && __ANDROID_API__ >= 34) || defined(__musl__)
97+
// Pre-standard posix_spawn_file_actions_addchdir_np version available in:
98+
// - Solaris 11.3 (October 2015)
99+
// - Glibc 2.29 (February 2019)
100+
// - macOS 10.15 (October 2019)
101+
// - musl 1.1.24 (October 2019)
102+
// - FreeBSD 13.1 (May 2022)
103+
// - Android 14 (October 2023)
104+
return posix_spawn_file_actions_addchdir_np((posix_spawn_file_actions_t *)file_actions, path);
105+
#else
106+
// Standardized posix_spawn_file_actions_addchdir version (POSIX.1-2024, June 2024) available in:
107+
// - Solaris 11.4 (August 2018)
108+
// - NetBSD 10.0 (March 2024)
109+
// - QNX 8 (December 2023)
110+
return posix_spawn_file_actions_addchdir((posix_spawn_file_actions_t *)file_actions, path);
103111
#endif
104112
}
105113
#endif

0 commit comments

Comments
 (0)