Skip to content

Commit f87a65a

Browse files
committed
Compiler: Cygwin is identified by os(Cygwin) instead of os(Windows)
Since MinGW, Cygwin and MSVC are definitely vary greatly in ABI and C language level behavior, it is neccessary to distinguish each other in Swift. (In target name, MSVC is x86_64-*-windows-msvc, Cygwin is x86_64-*-windows-cygnus) Before change, os(Windows) was *-*-windows-*, and now, os(Cygwin) is for *-*-windows-cygnus, and os(Windows) is for *-*-windows-msvc. The platform name for Cygwin was also renamed to 'cygwin' from 'windows'.
1 parent cbd6573 commit f87a65a

File tree

11 files changed

+37
-16
lines changed

11 files changed

+37
-16
lines changed

lib/Basic/LangOptions.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ static const StringRef SupportedConditionalCompilationOSs[] = {
3131
"Linux",
3232
"FreeBSD",
3333
"Windows",
34-
"Android"
34+
"Android",
35+
"Cygwin"
3536
};
3637

3738
static const StringRef SupportedConditionalCompilationArches[] = {
@@ -126,8 +127,10 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
126127
addPlatformConditionValue("os", "Linux");
127128
else if (triple.isOSFreeBSD())
128129
addPlatformConditionValue("os", "FreeBSD");
129-
else if (triple.isOSWindows())
130+
else if (triple.isWindowsMSVCEnvironment())
130131
addPlatformConditionValue("os", "Windows");
132+
else if (triple.isWindowsCygwinEnvironment())
133+
addPlatformConditionValue("os", "Cygwin");
131134
else {
132135
UnsupportedOS = true;
133136
}

lib/Basic/Platform.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,12 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
9797
if (triple.isOSFreeBSD())
9898
return "freebsd";
9999

100-
if (triple.isOSWindows())
100+
if (triple.isKnownWindowsMSVCEnvironment())
101101
return "windows";
102102

103+
if (triple.isWindowsCygwinEnvironment())
104+
return "cygwin";
105+
103106
return "";
104107
}
105108

stdlib/public/Platform/Platform.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ public var errno : Int32 {
9898
get {
9999
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD)
100100
return __error().pointee
101-
// FIXME: os(Windows) should be replaced, such as triple(Cygwin)
102-
#elseif os(Android) || os(Windows)
101+
#elseif os(Android) || os(Cygwin)
103102
return __errno().pointee
104103
#else
105104
return __errno_location().pointee
@@ -108,7 +107,7 @@ public var errno : Int32 {
108107
set(val) {
109108
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD)
110109
return __error().pointee = val
111-
#elseif os(Android) || os(Windows)
110+
#elseif os(Android) || os(Cygwin)
112111
return __errno().pointee = val
113112
#else
114113
return __errno_location().pointee = val
@@ -302,8 +301,8 @@ public var SIG_DFL: sig_t? { return nil }
302301
public var SIG_IGN: sig_t { return unsafeBitCast(1, to: sig_t.self) }
303302
public var SIG_ERR: sig_t { return unsafeBitCast(-1, to: sig_t.self) }
304303
public var SIG_HOLD: sig_t { return unsafeBitCast(5, to: sig_t.self) }
305-
#elseif os(Linux) || os(FreeBSD) || os(Android) || os(Windows)
306-
#if os(Windows)
304+
#elseif os(Linux) || os(FreeBSD) || os(Android) || os(Cygwin)
305+
#if os(Cygwin)
307306
// In Cygwin, the below SIG_* have the same value with Linux.
308307
// Verified with libstdc++6 v5.3.0 in Cygwin v2.4.1 64bit.
309308
public typealias sighandler_t = _sig_func_ptr
@@ -334,7 +333,7 @@ public var SEM_FAILED: UnsafeMutablePointer<sem_t>? {
334333
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
335334
// The value is ABI. Value verified to be correct for OS X, iOS, watchOS, tvOS.
336335
return UnsafeMutablePointer<sem_t>(bitPattern: -1)
337-
#elseif os(Linux) || os(FreeBSD) || os(Android) || os(Windows)
336+
#elseif os(Linux) || os(FreeBSD) || os(Android) || os(Cygwin)
338337
// The value is ABI. Value verified to be correct on Glibc.
339338
return UnsafeMutablePointer<sem_t>(bitPattern: 0)
340339
#else

stdlib/public/Platform/tgmath.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public func scalbn(_ x: ${T}, _ n: Int) -> ${T} {
247247

248248
% # This is AllFloatTypes not OverlayFloatTypes because of the tuple return.
249249
% for T, CT, f in AllFloatTypes():
250-
#if os(Linux) || os(FreeBSD) || os(Android) || os(Windows)
250+
#if os(Linux) || os(FreeBSD) || os(Android) || os(Cygwin)
251251
@_transparent
252252
public func lgamma(_ x: ${T}) -> (${T}, Int) {
253253
var sign = CInt(0)

stdlib/public/core/CTypes.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,18 @@ public typealias CShort = Int16
4343
public typealias CInt = Int32
4444

4545
/// The C 'long' type.
46+
#if os(Windows) && arch(x86_64)
47+
public typealias CLong = Int32
48+
#else
4649
public typealias CLong = Int
50+
#endif
4751

4852
/// The C 'long long' type.
53+
#if os(Windows) && arch(x86_64)
54+
public typealias CLongLong = Int
55+
#else
4956
public typealias CLongLong = Int64
57+
#endif
5058

5159
/// The C 'float' type.
5260
public typealias CFloat = Float

stdlib/public/core/FloatingPoint.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ public protocol BinaryFloatingPoint: FloatingPoint, FloatLiteralConvertible {
583583
/// `value` rounded to the closest representable `Self`.
584584
init(_ value: Double)
585585

586-
#if !os(Windows) && (arch(i386) || arch(x86_64))
586+
#if !os(Windows) && !os(Cygwin) && (arch(i386) || arch(x86_64))
587587
/// `value` rounded to the closest representable `Self`.
588588
init(_ value: Float80)
589589
#endif

stdlib/public/core/FloatingPointParsing.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal func _isspace_clocale(_ u: UTF16.CodeUnit) -> Bool {
3838
% Self = floatName(bits)
3939

4040
% if bits == 80:
41-
#if !os(Windows) && (arch(i386) || arch(x86_64))
41+
#if !os(Windows) && !os(Cygwin) && (arch(i386) || arch(x86_64))
4242
% end
4343

4444
//===--- Parsing ----------------------------------------------------------===//

stdlib/public/core/Policy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public typealias StringLiteralType = String
8888
// IEEE Binary64, and we need 1 bit to represent the sign. Instead of using
8989
// 1025, we use the next round number -- 2048.
9090
public typealias _MaxBuiltinIntegerType = Builtin.Int2048
91-
#if !os(Windows) && (arch(i386) || arch(x86_64))
91+
#if !os(Windows) && !os(Cygwin) && (arch(i386) || arch(x86_64))
9292
public typealias _MaxBuiltinFloatType = Builtin.FPIEEE80
9393
#else
9494
public typealias _MaxBuiltinFloatType = Builtin.FPIEEE64

stdlib/public/core/Runtime.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ internal struct _Buffer72 {
338338
% for bits in [ 32, 64, 80 ]:
339339

340340
% if bits == 80:
341-
#if !os(Windows) && (arch(i386) || arch(x86_64))
341+
#if !os(Windows) && !os(Cygwin) && (arch(i386) || arch(x86_64))
342342
% end
343343

344344
@_silgen_name("swift_float${bits}ToString")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %swift -parse %s -verify -D FOO -D BAR -target x86_64-unknown-windows-cygnus -disable-objc-interop -D FOO -parse-stdlib
2+
// RUN: %swift-ide-test -test-input-complete -source-filename=%s -target x86_64-unknown-windows-cygnus
3+
4+
#if arch(x86_64) && os(Cygwin) && _runtime(_Native)
5+
class C {}
6+
var x = C()
7+
#endif
8+
var y = x

0 commit comments

Comments
 (0)