Skip to content

Commit 4830841

Browse files
authored
Merge pull request #10359 from CodaFi/cygni-imperator
2 parents ffa5898 + 0cf1b52 commit 4830841

19 files changed

+77
-87
lines changed

cmake/modules/SwiftSource.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ function(handle_swift_sources
5959
if (NOT SWIFTSOURCES_IS_MAIN)
6060
list(APPEND swift_compile_flags "-module-link-name" "${name}")
6161
endif()
62-
if("${SWIFTSOURCES_SDK}" STREQUAL "CYGWIN")
63-
list(APPEND swift_compile_flags -DCYGWIN)
64-
endif()
6562

6663
if(swift_sources)
6764
compute_library_subdir(SWIFTSOURCES_LIBRARY_SUBDIR

lib/Basic/LangOptions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static const StringRef SupportedConditionalCompilationOSs[] = {
3636
"Windows",
3737
"Android",
3838
"PS4",
39+
"Cygwin",
3940
};
4041

4142
static const StringRef SupportedConditionalCompilationArches[] = {
@@ -157,6 +158,8 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
157158
addPlatformConditionValue(PlatformConditionKind::OS, "FreeBSD");
158159
else if (triple.isOSWindows())
159160
addPlatformConditionValue(PlatformConditionKind::OS, "Windows");
161+
else if (triple.isWindowsCygwinEnvironment())
162+
addPlatformConditionValue(PlatformConditionKind::OS, "Cygwin");
160163
else if (triple.isPS4())
161164
addPlatformConditionValue(PlatformConditionKind::OS, "PS4");
162165
else

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) || CYGWIN
44+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
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) || CYGWIN
17+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
1818
import Glibc
1919
#endif
2020

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 2 additions & 2 deletions
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) || CYGWIN
23+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
2424
import Glibc
2525
#endif
2626

@@ -1497,7 +1497,7 @@ func _getOSVersion() -> OSVersion {
14971497
return .ps4
14981498
#elseif os(Android)
14991499
return .android
1500-
#elseif os(Windows) && CYGWIN
1500+
#elseif os(Cygwin)
15011501
return .windowsCygnus
15021502
#elseif os(Windows)
15031503
return .windows

stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
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) || CYGWIN
16+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
1717
import Glibc
1818
#endif
1919

2020

21-
#if !os(Windows) || CYGWIN
22-
// posix_spawn is not available on Android or Windows.
21+
#if !os(Windows)
22+
// posix_spawn is not available on Windows.
23+
// posix_spawn is not available on Android.
2324
#if !os(Android)
2425
// swift_posix_spawn isn't available in the public watchOS SDK, we sneak by the
2526
// unavailable attribute declaration here of the APIs that we need.
@@ -264,7 +265,7 @@ public enum ProcessTerminationStatus : CustomStringConvertible {
264265

265266
public func posixWaitpid(_ pid: pid_t) -> ProcessTerminationStatus {
266267
var status: CInt = 0
267-
#if CYGWIN
268+
#if os(Cygwin)
268269
withUnsafeMutablePointer(to: &status) {
269270
statusPtr in
270271
let statusPtrWrapper = __wait_status_ptr_t(__int_ptr: statusPtr)
@@ -304,7 +305,7 @@ internal func _getEnviron() -> UnsafeMutablePointer<UnsafeMutablePointer<CChar>?
304305
return environ
305306
#elseif os(Android)
306307
return environ
307-
#elseif CYGWIN
308+
#elseif os(Cygwin)
308309
return environ
309310
#else
310311
return __environ

stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
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) || CYGWIN
16+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
1717
import Glibc
1818
#elseif os(Windows)
1919
import ucrt
2020
#endif
2121

22-
#if !os(Windows) || CYGWIN
22+
#if !os(Windows)
2323
public func _stdlib_mkstemps(_ template: inout String, _ suffixlen: CInt) -> CInt {
2424
#if os(Android)
2525
preconditionFailure("mkstemps doesn't work on Android")
@@ -85,7 +85,7 @@ public struct _stdlib_fd_set {
8585
}
8686
}
8787

88-
#if !os(Windows) || CYGWIN
88+
#if !os(Windows)
8989
public func _stdlib_select(
9090
_ readfds: inout _stdlib_fd_set, _ writefds: inout _stdlib_fd_set,
9191
_ errorfds: inout _stdlib_fd_set, _ timeout: UnsafeMutablePointer<timeval>?
@@ -99,7 +99,7 @@ public func _stdlib_select(
9999
let readAddr = readfds.baseAddress
100100
let writeAddr = writefds.baseAddress
101101
let errorAddr = errorfds.baseAddress
102-
#if CYGWIN
102+
#if os(Cygwin)
103103
typealias fd_set = _types_fd_set
104104
#endif
105105
func asFdSetPtr(
@@ -125,10 +125,10 @@ public func _stdlib_select(
125125
public func _stdlib_pipe() -> (readEnd: CInt, writeEnd: CInt, error: CInt) {
126126
var fds: [CInt] = [0, 0]
127127
let ret = fds.withUnsafeMutableBufferPointer { unsafeFds -> CInt in
128-
#if !os(Windows) || CYGWIN
129-
return pipe(unsafeFds.baseAddress)
130-
#else
128+
#if os(Windows)
131129
return _pipe(unsafeFds.baseAddress, 0, 0)
130+
#else
131+
return pipe(unsafeFds.baseAddress)
132132
#endif
133133
}
134134
return (readEnd: fds[0], writeEnd: fds[1], error: ret)

stdlib/private/SwiftPrivatePthreadExtras/PthreadBarriers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
1414
import Darwin
15-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || CYGWIN
15+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
1616
import Glibc
1717
#endif
1818

@@ -43,7 +43,7 @@ public var _stdlib_PTHREAD_BARRIER_SERIAL_THREAD: CInt {
4343
}
4444

4545
public struct _stdlib_pthread_barrier_t {
46-
#if CYGWIN || os(FreeBSD)
46+
#if os(Cygwin) || os(FreeBSD)
4747
var mutex: UnsafeMutablePointer<pthread_mutex_t?>?
4848
var cond: UnsafeMutablePointer<pthread_cond_t?>?
4949
#else

stdlib/private/SwiftPrivatePthreadExtras/SwiftPrivatePthreadExtras.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
1919
import Darwin
20-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || CYGWIN
20+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
2121
import Glibc
2222
#endif
2323

@@ -59,7 +59,7 @@ internal func invokeBlockContext(
5959
return context.run()
6060
}
6161

62-
#if CYGWIN || os(FreeBSD)
62+
#if os(Cygwin) || os(FreeBSD)
6363
public typealias _stdlib_pthread_attr_t = UnsafePointer<pthread_attr_t?>
6464
#else
6565
public typealias _stdlib_pthread_attr_t = UnsafePointer<pthread_attr_t>

stdlib/public/Platform/Platform.swift

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -141,23 +141,23 @@ public func snprintf(ptr: UnsafeMutablePointer<Int8>, _ len: Int, _ format: Unsa
141141
// fcntl.h
142142
//===----------------------------------------------------------------------===//
143143

144-
#if !os(Windows) || CYGWIN
144+
#if os(Windows)
145145
@_silgen_name("_swift_Platform_open")
146146
func _swift_Platform_open(
147147
_ path: UnsafePointer<CChar>,
148148
_ oflag: Int32,
149-
_ mode: mode_t
149+
_ mode: Int32
150150
) -> Int32
151151
#else
152152
@_silgen_name("_swift_Platform_open")
153153
func _swift_Platform_open(
154154
_ path: UnsafePointer<CChar>,
155155
_ oflag: Int32,
156-
_ mode: Int32
156+
_ mode: mode_t
157157
) -> Int32
158158
#endif
159159

160-
#if !os(Windows) || CYGWIN
160+
#if !os(Windows)
161161
@_silgen_name("_swift_Platform_openat")
162162
func _swift_Platform_openat(
163163
_ fd: Int32,
@@ -174,7 +174,15 @@ public func open(
174174
return _swift_Platform_open(path, oflag, 0)
175175
}
176176

177-
#if !os(Windows) || CYGWIN
177+
#if os(Windows)
178+
public func open(
179+
_ path: UnsafePointer<CChar>,
180+
_ oflag: Int32,
181+
_ mode: Int32
182+
) -> Int32 {
183+
return _swift_Platform_open(path, oflag, mode)
184+
}
185+
#else
178186
public func open(
179187
_ path: UnsafePointer<CChar>,
180188
_ oflag: Int32,
@@ -199,17 +207,9 @@ public func openat(
199207
) -> Int32 {
200208
return _swift_Platform_openat(fd, path, oflag, mode)
201209
}
202-
#else
203-
public func open(
204-
_ path: UnsafePointer<CChar>,
205-
_ oflag: Int32,
206-
_ mode: Int32
207-
) -> Int32 {
208-
return _swift_Platform_open(path, oflag, mode)
209-
}
210210
#endif
211211

212-
#if !os(Windows) || CYGWIN
212+
#if !os(Windows)
213213
@_silgen_name("_swift_Platform_fcntl")
214214
internal func _swift_Platform_fcntl(
215215
_ fd: Int32,
@@ -248,7 +248,18 @@ public func fcntl(
248248
}
249249
#endif
250250

251-
#if !os(Windows) || CYGWIN
251+
#if os(Windows)
252+
public var S_IFMT: Int32 { return Int32(0xf000) }
253+
254+
public var S_IFREG: Int32 { return Int32(0x8000) }
255+
public var S_IFDIR: Int32 { return Int32(0x4000) }
256+
public var S_IFCHR: Int32 { return Int32(0x2000) }
257+
public var S_IFIFO: Int32 { return Int32(0x1000) }
258+
259+
public var S_IREAD: Int32 { return Int32(0x0100) }
260+
public var S_IWRITE: Int32 { return Int32(0x0080) }
261+
public var S_IEXEC: Int32 { return Int32(0x0040) }
262+
#else
252263
public var S_IFMT: mode_t { return mode_t(0o170000) }
253264
public var S_IFIFO: mode_t { return mode_t(0o010000) }
254265
public var S_IFCHR: mode_t { return mode_t(0o020000) }
@@ -286,24 +297,13 @@ public var S_IREAD: mode_t { return S_IRUSR }
286297
public var S_IWRITE: mode_t { return S_IWUSR }
287298
public var S_IEXEC: mode_t { return S_IXUSR }
288299
#endif
289-
#else
290-
public var S_IFMT: Int32 { return Int32(0xf000) }
291-
292-
public var S_IFREG: Int32 { return Int32(0x8000) }
293-
public var S_IFDIR: Int32 { return Int32(0x4000) }
294-
public var S_IFCHR: Int32 { return Int32(0x2000) }
295-
public var S_IFIFO: Int32 { return Int32(0x1000) }
296-
297-
public var S_IREAD: Int32 { return Int32(0x0100) }
298-
public var S_IWRITE: Int32 { return Int32(0x0080) }
299-
public var S_IEXEC: Int32 { return Int32(0x0040) }
300300
#endif
301301

302302
//===----------------------------------------------------------------------===//
303303
// ioctl.h
304304
//===----------------------------------------------------------------------===//
305305

306-
#if !os(Windows) || CYGWIN
306+
#if !os(Windows)
307307
@_silgen_name("_swift_Platform_ioctl")
308308
internal func _swift_Platform_ioctl(
309309
_ fd: CInt,
@@ -380,8 +380,7 @@ public var SIG_ERR: sighandler_t {
380380
public var SIG_HOLD: sighandler_t {
381381
return unsafeBitCast(2, to: sighandler_t.self)
382382
}
383-
#elseif os(Windows)
384-
#if CYGWIN
383+
#elseif os(Cygwin)
385384
public typealias sighandler_t = _sig_func_ptr
386385

387386
public var SIG_DFL: sighandler_t? { return nil }
@@ -394,15 +393,14 @@ public var SIG_ERR: sighandler_t {
394393
public var SIG_HOLD: sighandler_t {
395394
return unsafeBitCast(2, to: sighandler_t.self)
396395
}
397-
#else
396+
#elseif os(Windows)
398397
public var SIG_DFL: _crt_signal_t? { return nil }
399398
public var SIG_IGN: _crt_signal_t {
400399
return unsafeBitCast(1, to: _crt_signal_t.self)
401400
}
402401
public var SIG_ERR: _crt_signal_t {
403402
return unsafeBitCast(-1, to: _crt_signal_t.self)
404403
}
405-
#endif
406404
#else
407405
internal var _ignore = _UnsupportedPlatformError()
408406
#endif
@@ -411,13 +409,13 @@ internal var _ignore = _UnsupportedPlatformError()
411409
// semaphore.h
412410
//===----------------------------------------------------------------------===//
413411

414-
#if !os(Windows) || CYGWIN
412+
#if !os(Windows)
415413
/// The value returned by `sem_open()` in the case of failure.
416414
public var SEM_FAILED: UnsafeMutablePointer<sem_t>? {
417415
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
418416
// The value is ABI. Value verified to be correct for OS X, iOS, watchOS, tvOS.
419417
return UnsafeMutablePointer<sem_t>(bitPattern: -1)
420-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || CYGWIN
418+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
421419
// The value is ABI. Value verified to be correct on Glibc.
422420
return UnsafeMutablePointer<sem_t>(bitPattern: 0)
423421
#else

0 commit comments

Comments
 (0)