Skip to content

Commit aee81d2

Browse files
returnCodaFi
authored andcommitted
Add Initial platform support for Haiku. (#11583)
1 parent 0eae9ea commit aee81d2

40 files changed

+449
-55
lines changed

CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ set(SWIFT_ANDROID_DEPLOY_DEVICE_PATH "" CACHE STRING
170170
"Path on an Android device where build products will be pushed. These are used when running the test suite against the device")
171171

172172
#
173-
# User-configurable ICU specific options for Android, FreeBSD, Linux.
173+
# User-configurable ICU specific options for Android, FreeBSD, Linux and Haiku.
174174
#
175175

176-
foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS)
176+
foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS;HAIKU)
177177
set(SWIFT_${sdk}_ICU_UC "" CACHE STRING
178178
"Path to a directory containing the icuuc library for ${sdk}")
179179
set(SWIFT_${sdk}_ICU_UC_INCLUDE "" CACHE STRING
@@ -536,6 +536,8 @@ else()
536536
set(SWIFT_HOST_VARIANT_SDK_default "CYGWIN")
537537
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
538538
set(SWIFT_HOST_VARIANT_SDK_default "WINDOWS")
539+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Haiku")
540+
set(SWIFT_HOST_VARIANT_SDK_default "HAIKU")
539541
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
540542
set(SWIFT_HOST_VARIANT_SDK_default "OSX")
541543
else()
@@ -677,6 +679,16 @@ elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WINDOWS")
677679
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
678680
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
679681

682+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "HAIKU")
683+
684+
set(CMAKE_EXECUTABLE_FORMAT "ELF")
685+
set(SWIFT_HOST_VARIANT "haiku" CACHE STRING
686+
"Deployment OS for Swift host tools (the compiler) [haiku].")
687+
688+
configure_sdk_unix(HAIKU "Haiku" "haiku" "haiku" "x86_64" "x86_64-unknown-haiku" "/")
689+
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
690+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
691+
680692
elseif("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
681693

682694
set(SWIFT_HOST_VARIANT "macosx" CACHE STRING

cmake/modules/AddSwift.cmake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ function(_add_variant_link_flags)
354354
# options. This causes conflicts.
355355
list(APPEND result "-nostdlib")
356356
endif()
357+
elseif("${LFLAGS_SDK}" STREQUAL "HAIKU")
358+
list(APPEND result "-lbsd" "-latomic" "-Wl,-Bsymbolic")
357359
elseif("${LFLAGS_SDK}" STREQUAL "ANDROID")
358360
list(APPEND result
359361
"-ldl" "-llog" "-latomic" "-licudataswift" "-licui18nswift" "-licuucswift"
@@ -1265,6 +1267,9 @@ endfunction()
12651267
# SWIFT_MODULE_DEPENDS_CYGWIN
12661268
# Swift modules this library depends on when built for Cygwin.
12671269
#
1270+
# SWIFT_MODULE_DEPENDS_HAIKU
1271+
# Swift modules this library depends on when built for Haiku.
1272+
#
12681273
# FRAMEWORK_DEPENDS
12691274
# System frameworks this library depends on.
12701275
#
@@ -1338,7 +1343,7 @@ function(add_swift_library name)
13381343
cmake_parse_arguments(SWIFTLIB
13391344
"${SWIFTLIB_options}"
13401345
"INSTALL_IN_COMPONENT;DEPLOYMENT_VERSION_OSX;DEPLOYMENT_VERSION_IOS;DEPLOYMENT_VERSION_TVOS;DEPLOYMENT_VERSION_WATCHOS"
1341-
"DEPENDS;LINK_LIBRARIES;SWIFT_MODULE_DEPENDS;SWIFT_MODULE_DEPENDS_OSX;SWIFT_MODULE_DEPENDS_IOS;SWIFT_MODULE_DEPENDS_TVOS;SWIFT_MODULE_DEPENDS_WATCHOS;SWIFT_MODULE_DEPENDS_FREEBSD;SWIFT_MODULE_DEPENDS_LINUX;SWIFT_MODULE_DEPENDS_CYGWIN;FRAMEWORK_DEPENDS;FRAMEWORK_DEPENDS_WEAK;FRAMEWORK_DEPENDS_OSX;FRAMEWORK_DEPENDS_IOS_TVOS;LLVM_COMPONENT_DEPENDS;FILE_DEPENDS;TARGET_SDKS;C_COMPILE_FLAGS;SWIFT_COMPILE_FLAGS;SWIFT_COMPILE_FLAGS_OSX;SWIFT_COMPILE_FLAGS_IOS;SWIFT_COMPILE_FLAGS_TVOS;SWIFT_COMPILE_FLAGS_WATCHOS;LINK_FLAGS;PRIVATE_LINK_LIBRARIES;INTERFACE_LINK_LIBRARIES;INCORPORATE_OBJECT_LIBRARIES;INCORPORATE_OBJECT_LIBRARIES_SHARED_ONLY"
1346+
"DEPENDS;LINK_LIBRARIES;SWIFT_MODULE_DEPENDS;SWIFT_MODULE_DEPENDS_OSX;SWIFT_MODULE_DEPENDS_IOS;SWIFT_MODULE_DEPENDS_TVOS;SWIFT_MODULE_DEPENDS_WATCHOS;SWIFT_MODULE_DEPENDS_FREEBSD;SWIFT_MODULE_DEPENDS_LINUX;SWIFT_MODULE_DEPENDS_CYGWIN;SWIFT_MODULE_DEPENDS_HAIKU;FRAMEWORK_DEPENDS;FRAMEWORK_DEPENDS_WEAK;FRAMEWORK_DEPENDS_OSX;FRAMEWORK_DEPENDS_IOS_TVOS;LLVM_COMPONENT_DEPENDS;FILE_DEPENDS;TARGET_SDKS;C_COMPILE_FLAGS;SWIFT_COMPILE_FLAGS;SWIFT_COMPILE_FLAGS_OSX;SWIFT_COMPILE_FLAGS_IOS;SWIFT_COMPILE_FLAGS_TVOS;SWIFT_COMPILE_FLAGS_WATCHOS;LINK_FLAGS;PRIVATE_LINK_LIBRARIES;INTERFACE_LINK_LIBRARIES;INCORPORATE_OBJECT_LIBRARIES;INCORPORATE_OBJECT_LIBRARIES_SHARED_ONLY"
13421347
${ARGN})
13431348
set(SWIFTLIB_SOURCES ${SWIFTLIB_UNPARSED_ARGUMENTS})
13441349

@@ -1369,7 +1374,7 @@ function(add_swift_library name)
13691374
if("${SWIFTLIB_TARGET_SDKS}" STREQUAL "")
13701375
set(SWIFTLIB_TARGET_SDKS ${SWIFT_SDKS})
13711376
endif()
1372-
list_replace(SWIFTLIB_TARGET_SDKS ALL_POSIX_PLATFORMS "ALL_APPLE_PLATFORMS;ANDROID;CYGWIN;FREEBSD;LINUX")
1377+
list_replace(SWIFTLIB_TARGET_SDKS ALL_POSIX_PLATFORMS "ALL_APPLE_PLATFORMS;ANDROID;CYGWIN;FREEBSD;LINUX;HAIKU")
13731378
list_replace(SWIFTLIB_TARGET_SDKS ALL_APPLE_PLATFORMS "${SWIFT_APPLE_PLATFORMS}")
13741379

13751380
# All Swift code depends on the standard library, except for the standard
@@ -1479,6 +1484,9 @@ function(add_swift_library name)
14791484
elseif("${sdk}" STREQUAL "CYGWIN")
14801485
list(APPEND swiftlib_module_depends_flattened
14811486
${SWIFTLIB_SWIFT_MODULE_DEPENDS_CYGWIN})
1487+
elseif("${sdk}" STREQUAL "HAIKU")
1488+
list(APPEND swiftlib_module_depends_flattened
1489+
${SWIFTLIB_SWIFT_MODULE_DEPENDS_HAIKU})
14821490
endif()
14831491

14841492
# Swift compiles depend on swift modules, while links depend on

cmake/modules/FindICU.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ foreach(MODULE ${ICU_FIND_COMPONENTS})
3131
endif()
3232
endforeach()
3333

34-
foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS)
34+
foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS;HAIKU)
3535
foreach(MODULE ${ICU_FIND_COMPONENTS})
3636
string(TOUPPER "${MODULE}" MODULE)
3737
if("${SWIFT_${sdk}_ICU_${MODULE}_INCLUDE}" STREQUAL "")

include/swift/Basic/LangOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ namespace swift {
268268
Target.getOSVersion(major, minor, revision);
269269
} else if (Target.isOSLinux() || Target.isOSFreeBSD() ||
270270
Target.isAndroid() || Target.isOSWindows() ||
271-
Target.isPS4() || Target.getTriple().empty()) {
271+
Target.isPS4() || Target.isOSHaiku() ||
272+
Target.getTriple().empty()) {
272273
major = minor = revision = 0;
273274
} else {
274275
llvm_unreachable("Unsupported target OS");

include/swift/Runtime/Concurrent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <stdint.h>
1818
#include "llvm/Support/Allocator.h"
1919

20-
#if defined(__FreeBSD__) || defined(__CYGWIN__)
20+
#if defined(__FreeBSD__) || defined(__CYGWIN__) || defined(__HAIKU__)
2121
#include <stdio.h>
2222
#endif
2323

include/swift/Runtime/Mutex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <type_traits>
2222

23-
#if (defined(__APPLE__) || defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__))
23+
#if (defined(__APPLE__) || defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__HAIKU__))
2424
#include "swift/Runtime/MutexPThread.h"
2525
#elif defined(_WIN32)
2626
#include "swift/Runtime/MutexWin32.h"

include/swift/Runtime/MutexPThread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef pthread_cond_t ConditionHandle;
2626
typedef pthread_mutex_t MutexHandle;
2727
typedef pthread_rwlock_t ReadWriteLockHandle;
2828

29-
#if defined(__CYGWIN__) || defined(__ANDROID__)
29+
#if defined(__CYGWIN__) || defined(__ANDROID__) || defined(__HAIKU__)
3030
// At the moment CYGWIN pthreads implementation doesn't support the use of
3131
// constexpr for static allocation versions. The way they define things
3232
// results in a reinterpret_cast which violates constexpr. Similarly, Android's

lib/Basic/LangOptions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static const StringRef SupportedConditionalCompilationOSs[] = {
3737
"Android",
3838
"PS4",
3939
"Cygwin",
40+
"Haiku",
4041
};
4142

4243
static const StringRef SupportedConditionalCompilationArches[] = {
@@ -181,6 +182,8 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
181182
addPlatformConditionValue(PlatformConditionKind::OS, "Cygwin");
182183
else if (triple.isPS4())
183184
addPlatformConditionValue(PlatformConditionKind::OS, "PS4");
185+
else if (triple.isOSHaiku())
186+
addPlatformConditionValue(PlatformConditionKind::OS, "Haiku");
184187
else
185188
UnsupportedOS = true;
186189

lib/Basic/Platform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
9797
case llvm::Triple::NetBSD:
9898
case llvm::Triple::OpenBSD:
9999
case llvm::Triple::Solaris:
100-
case llvm::Triple::Haiku:
101100
case llvm::Triple::Minix:
102101
case llvm::Triple::RTEMS:
103102
case llvm::Triple::NaCl:
@@ -135,6 +134,8 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
135134
}
136135
case llvm::Triple::PS4:
137136
return "ps4";
137+
case llvm::Triple::Haiku:
138+
return "haiku";
138139
}
139140
llvm_unreachable("unsupported OS");
140141
}

lib/Basic/Statistic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ using namespace llvm::sys;
3232

3333
static size_t
3434
getChildrenMaxResidentSetSize() {
35-
#if defined(HAVE_GETRUSAGE)
35+
#if defined(HAVE_GETRUSAGE) && !defined(__HAIKU__)
3636
struct rusage RU;
3737
::getrusage(RUSAGE_CHILDREN, &RU);
3838
return RU.ru_maxrss;

lib/Basic/TaskQueue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using namespace swift;
2323
using namespace swift::sys;
2424

2525
// Include the correct TaskQueue implementation.
26-
#if LLVM_ON_UNIX && !defined(__CYGWIN__)
26+
#if LLVM_ON_UNIX && !defined(__CYGWIN__) && !defined(__HAIKU__)
2727
#include "Unix/TaskQueue.inc"
2828
#else
2929
#include "Default/TaskQueue.inc"

lib/Driver/Driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ makeToolChain(Driver &driver, const llvm::Triple &target) {
212212
case llvm::Triple::Win32:
213213
return llvm::make_unique<toolchains::Cygwin>(driver, target);
214214
break;
215+
case llvm::Triple::Haiku:
216+
return llvm::make_unique<toolchains::GenericUnix>(driver, target);
217+
break;
215218
default:
216219
return nullptr;
217220
}

lib/Driver/ToolChains.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ bool toolchains::GenericUnix::shouldProvideRPathToLinker() const {
15141514

15151515
std::string toolchains::GenericUnix::getPreInputObjectPath(
15161516
StringRef RuntimeLibraryPath) const {
1517-
// On Linux and FreeBSD (really, ELF binaries) we need to add objects
1517+
// On Linux and FreeBSD and Haiku (really, ELF binaries) we need to add objects
15181518
// to provide markers and size for the metadata sections.
15191519
SmallString<128> PreInputObjectPath = RuntimeLibraryPath;
15201520
llvm::sys::path::append(PreInputObjectPath,
@@ -1559,7 +1559,13 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
15591559
Linker = getDefaultLinker();
15601560
}
15611561
if (!Linker.empty()) {
1562+
#if defined(__HAIKU__)
1563+
// For now, passing -fuse-ld on Haiku doesn't work as swiftc doesn't recognise
1564+
// it. Passing -use-ld= as the argument works fine.
1565+
Arguments.push_back(context.Args.MakeArgString("-use-ld=" + Linker));
1566+
#else
15621567
Arguments.push_back(context.Args.MakeArgString("-fuse-ld=" + Linker));
1568+
#endif
15631569
}
15641570

15651571
// Configure the toolchain.

stdlib/private/StdlibUnittest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ add_swift_library(swiftStdlibUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STD
4444
SWIFT_MODULE_DEPENDS_LINUX Glibc
4545
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
4646
SWIFT_MODULE_DEPENDS_CYGWIN Glibc
47+
SWIFT_MODULE_DEPENDS_HAIKU Glibc
4748
SWIFT_COMPILE_FLAGS ${swift_stdlib_unittest_compile_flags}
4849
TARGET_SDKS ALL_POSIX_PLATFORMS
4950
INSTALL_IN_COMPONENT stdlib-experimental)

stdlib/private/StdlibUnittest/RaceTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import SwiftPrivateLibcExtras
4141
import SwiftPrivatePthreadExtras
4242
#if os(OSX) || os(iOS)
4343
import Darwin
44-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
44+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
4545
import Glibc
4646
#endif
4747

stdlib/private/StdlibUnittest/StdlibCoreExtras.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import SwiftPrivate
1414
import SwiftPrivateLibcExtras
1515
#if os(OSX) || os(iOS)
1616
import Darwin
17-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
17+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
1818
import Glibc
1919
#endif
2020

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SwiftPrivateLibcExtras
2020

2121
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
2222
import Darwin
23-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
23+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
2424
import Glibc
2525
#endif
2626

@@ -1464,6 +1464,7 @@ public enum OSVersion : CustomStringConvertible {
14641464
case ps4
14651465
case windowsCygnus
14661466
case windows
1467+
case haiku
14671468

14681469
public var description: String {
14691470
switch self {
@@ -1493,6 +1494,8 @@ public enum OSVersion : CustomStringConvertible {
14931494
return "Cygwin"
14941495
case .windows:
14951496
return "Windows"
1497+
case .haiku:
1498+
return "Haiku"
14961499
}
14971500
}
14981501
}
@@ -1535,6 +1538,8 @@ func _getOSVersion() -> OSVersion {
15351538
return .windowsCygnus
15361539
#elseif os(Windows)
15371540
return .windows
1541+
#elseif os(Haiku)
1542+
return .haiku
15381543
#else
15391544
let productVersion = _stdlib_getSystemVersionPlistProperty("ProductVersion")!
15401545
let (major, minor, bugFix) = _parseDottedVersionTriple(productVersion)
@@ -1616,6 +1621,8 @@ public enum TestRunPredicate : CustomStringConvertible {
16161621
case windowsAny(reason: String)
16171622

16181623
case windowsCygnusAny(reason: String)
1624+
1625+
case haikuAny(reason: String)
16191626

16201627
case objCRuntime(/*reason:*/ String)
16211628
case nativeRuntime(/*reason:*/ String)
@@ -1708,6 +1715,9 @@ public enum TestRunPredicate : CustomStringConvertible {
17081715

17091716
case .windowsCygnusAny(reason: let reason):
17101717
return "windowsCygnusAny(*, reason: \(reason))"
1718+
1719+
case .haikuAny(reason: let reason):
1720+
return "haikuAny(*, reason: \(reason))"
17111721

17121722
case .objCRuntime(let reason):
17131723
return "Objective-C runtime, reason: \(reason))"
@@ -1991,6 +2001,14 @@ public enum TestRunPredicate : CustomStringConvertible {
19912001
default:
19922002
return false
19932003
}
2004+
2005+
case .haikuAny:
2006+
switch _getRunningOSVersion() {
2007+
case .haiku:
2008+
return true
2009+
default:
2010+
return false
2011+
}
19942012

19952013
case .objCRuntime:
19962014
#if _runtime(_ObjC)

stdlib/private/SwiftPrivateLibcExtras/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ add_swift_library(swiftSwiftPrivateLibcExtras ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES
1414
SWIFT_MODULE_DEPENDS_LINUX Glibc
1515
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
1616
SWIFT_MODULE_DEPENDS_CYGWIN Glibc
17+
SWIFT_MODULE_DEPENDS_HAIKU Glibc
1718
INSTALL_IN_COMPONENT stdlib-experimental)

stdlib/private/SwiftPrivateLibcExtras/Subprocess.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
// posix_spawn is not available on Android or Windows (MSVC).
14-
#if !defined(__ANDROID__) && (!defined(_WIN32) || defined(__CYGWIN__))
14+
#if !defined(__ANDROID__) && !defined(__HAIKU__) && (!defined(_WIN32) || defined(__CYGWIN__))
1515

1616
#include "swift/Runtime/Config.h"
1717

@@ -65,5 +65,5 @@ char ***swift_SwiftPrivateLibcExtras_NSGetEnviron(void) {
6565
return _NSGetEnviron();
6666
}
6767
#endif // defined(__APPLE__)
68-
#endif // !defined(__ANDROID__) && (!defined(_WIN32) || defined(__CGYWIN__))
68+
#endif // !defined(__ANDROID__) && !defined(__HAIKU__) && (!defined(_WIN32) || defined(__CGYWIN__))
6969

stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
import SwiftPrivate
1414
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
1515
import Darwin
16-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
16+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
1717
import Glibc
1818
#endif
1919

2020

2121
#if !os(Windows)
2222
// posix_spawn is not available on Windows.
2323
// posix_spawn is not available on Android.
24-
#if !os(Android)
24+
// posix_spawn is not available on Haiku.
25+
#if !os(Android) && !os(Haiku)
2526
// swift_posix_spawn isn't available in the public watchOS SDK, we sneak by the
2627
// unavailable attribute declaration here of the APIs that we need.
2728

@@ -83,7 +84,7 @@ public func spawnChild(_ args: [String])
8384
let childStdin = posixPipe()
8485
let childStderr = posixPipe()
8586

86-
#if os(Android)
87+
#if os(Android) || os(Haiku)
8788
// posix_spawn isn't available on Android. Instead, we fork and exec.
8889
// To correctly communicate the exit status of the child process to this
8990
// (parent) process, we'll use this pipe.
@@ -222,7 +223,7 @@ public func spawnChild(_ args: [String])
222223
return (pid, childStdin.writeFD, childStdout.readFD, childStderr.readFD)
223224
}
224225

225-
#if !os(Android)
226+
#if !os(Android) && !os(Haiku)
226227
#if os(Linux)
227228
internal func _make_posix_spawn_file_actions_t()
228229
-> swift_posix_spawn_file_actions_t {
@@ -307,6 +308,8 @@ internal func _getEnviron() -> UnsafeMutablePointer<UnsafeMutablePointer<CChar>?
307308
return environ
308309
#elseif os(Cygwin)
309310
return environ
311+
#elseif os(Haiku)
312+
return environ
310313
#else
311314
return __environ
312315
#endif

stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
import SwiftPrivate
1414
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
1515
import Darwin
16-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
16+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
1717
import Glibc
1818
#elseif os(Windows)
1919
import ucrt
2020
#endif
2121

2222
#if !os(Windows)
2323
public func _stdlib_mkstemps(_ template: inout String, _ suffixlen: CInt) -> CInt {
24-
#if os(Android)
25-
preconditionFailure("mkstemps doesn't work on Android")
24+
#if os(Android) || os(Haiku)
25+
preconditionFailure("mkstemps doesn't work on your platform")
2626
#else
2727
var utf8CStr = template.utf8CString
2828
let (fd, fileName) = utf8CStr.withUnsafeMutableBufferPointer {

0 commit comments

Comments
 (0)