Skip to content

Commit 22bdce5

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 a1ff1e6 commit 22bdce5

File tree

13 files changed

+42
-21
lines changed

13 files changed

+42
-21
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
515515
set(SWIFT_PRIMARY_VARIANT_SDK_default "FREEBSD")
516516
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
517517
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN")
518-
configure_sdk_unix(CYGWIN "Cygwin" "windows" "cygwin" "x86_64" "x86_64-unknown-windows-cygnus")
518+
configure_sdk_unix(CYGWIN "Cygwin" "cygwin" "cygwin" "x86_64" "x86_64-unknown-windows-cygnus")
519519

520520
# set(CMAKE_EXECUTABLE_FORMAT "ELF")
521521

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[] = {
@@ -112,8 +113,10 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
112113
addPlatformConditionValue("os", "Linux");
113114
else if (triple.isOSFreeBSD())
114115
addPlatformConditionValue("os", "FreeBSD");
115-
else if (triple.isOSWindows())
116+
else if (triple.isWindowsMSVCEnvironment())
116117
addPlatformConditionValue("os", "Windows");
118+
else if (triple.isWindowsCygwinEnvironment())
119+
addPlatformConditionValue("os", "Cygwin");
117120
else {
118121
UnsupportedOS = true;
119122
}

lib/Basic/Platform.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ 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
}

stdlib/public/Platform/Platform.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ public var errno : Int32 {
103103
get {
104104
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD)
105105
return __error().pointee
106-
//FIXME: os(Windows) should be replaced, such as triple(Cygwin)
107-
#elseif os(Android) || os(Windows)
106+
#elseif os(Android) || os(Cygwin)
108107
return __errno().pointee
109108
#else
110109
return __errno_location().pointee
@@ -113,7 +112,7 @@ public var errno : Int32 {
113112
set(val) {
114113
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD)
115114
return __error().pointee = val
116-
#elseif os(Android) || os(Windows)
115+
#elseif os(Android) || os(Cygwin)
117116
return __errno().pointee = val
118117
#else
119118
return __errno_location().pointee = val
@@ -318,8 +317,8 @@ public var SIG_DFL: sig_t? { return nil }
318317
public var SIG_IGN: sig_t { return unsafeBitCast(1, to: sig_t.self) }
319318
public var SIG_ERR: sig_t { return unsafeBitCast(-1, to: sig_t.self) }
320319
public var SIG_HOLD: sig_t { return unsafeBitCast(5, to: sig_t.self) }
321-
#elseif os(Linux) || os(FreeBSD) || os(Android) || os(Windows)
322-
#if os(Windows)
320+
#elseif os(Linux) || os(FreeBSD) || os(Android) || os(Cygwin)
321+
#if os(Cygwin)
323322
// In Cygwin, the below SIG_* have the same value with Linux.
324323
// Verified with libstdc++6 v5.3.0 in Cygwin v2.4.1 64bit.
325324
public typealias sighandler_t = _sig_func_ptr
@@ -350,7 +349,7 @@ public var SEM_FAILED: UnsafeMutablePointer<sem_t>? {
350349
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
351350
// The value is ABI. Value verified to be correct for OS X, iOS, watchOS, tvOS.
352351
return UnsafeMutablePointer<sem_t>(bitPattern: -1)
353-
#elseif os(Linux) || os(FreeBSD) || os(Android) || os(Windows)
352+
#elseif os(Linux) || os(FreeBSD) || os(Android) || os(Cygwin)
354353
// The value is ABI. Value verified to be correct on Glibc.
355354
return UnsafeMutablePointer<sem_t>(bitPattern: 0)
356355
#else

stdlib/public/Platform/tgmath.swift.gyb

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

283283
% # This is AllFloatTypes not OverlayFloatTypes because of the tuple return.
284284
% for T, CT, f in AllFloatTypes():
285-
#if os(Linux) || os(FreeBSD) || os(Android) || os(Windows)
285+
#if os(Linux) || os(FreeBSD) || os(Android) || os(Cygwin)
286286
@_transparent
287287
@warn_unused_result
288288
public func lgamma(_ x: ${T}) -> (${T}, Int) {

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ else:
158158
raise ValueError('Unhandled float type.')
159159
}%
160160
% if bits == 80:
161-
#if !os(Windows) && (arch(i386) || arch(x86_64))
161+
#if !os(Windows) && !os(Cygwin) && (arch(i386) || arch(x86_64))
162162
% end
163163

164164
${SelfDocComment}
@@ -370,7 +370,7 @@ extension ${Self} : _BuiltinIntegerLiteralConvertible, IntegerLiteralConvertible
370370
}
371371
}
372372

373-
#if !os(Windows) && (arch(i386) || arch(x86_64))
373+
#if !os(Windows) && !os(Cygwin) && (arch(i386) || arch(x86_64))
374374

375375
% builtinFloatLiteralBits = 80
376376
@_transparent
@@ -539,7 +539,7 @@ extension ${Self} {
539539
% if Self != That:
540540

541541
% if srcBits == 80:
542-
#if !os(Windows) && (arch(i386) || arch(x86_64))
542+
#if !os(Windows) && !os(Cygwin) && (arch(i386) || arch(x86_64))
543543
% end
544544

545545
/// Construct an instance that approximates `other`.
@@ -646,7 +646,7 @@ extension ${Self} {
646646
% That = floatName(srcBits)
647647

648648
% if srcBits == 80:
649-
#if !os(Windows) && (arch(i386) || arch(x86_64))
649+
#if !os(Windows) && !os(Cygwin) && (arch(i386) || arch(x86_64))
650650
% end
651651

652652
/// Construct an instance that approximates `other`.

stdlib/public/core/FloatingPointParsing.swift.gyb

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

4141
% if bits == 80:
42-
#if !os(Windows) && (arch(i386) || arch(x86_64))
42+
#if !os(Windows) && !os(Cygwin) && (arch(i386) || arch(x86_64))
4343
% end
4444

4545
//===--- Parsing ----------------------------------------------------------===//

stdlib/public/core/Policy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public typealias StringLiteralType = String
6060
// IEEE Binary64, and we need 1 bit to represent the sign. Instead of using
6161
// 1025, we use the next round number -- 2048.
6262
public typealias _MaxBuiltinIntegerType = Builtin.Int2048
63-
#if !os(Windows) && (arch(i386) || arch(x86_64))
63+
#if !os(Windows) && !os(Cygwin) && (arch(i386) || arch(x86_64))
6464
public typealias _MaxBuiltinFloatType = Builtin.FPIEEE80
6565
#else
6666
public typealias _MaxBuiltinFloatType = Builtin.FPIEEE64

stdlib/public/core/Print.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public func print(
2828
separator: String = " ",
2929
terminator: String = "\n"
3030
) {
31-
#if os(Windows)
31+
#if os(Windows) || os(Cygwin)
3232
// FIXME: This fix is for 'crash at hook(output.left)' in cygwin.
3333
// Proper fix is needed. see: https://bugs.swift.org/browse/SR-612
3434
let _playgroundPrintHook: ((String) -> Void)? = nil

stdlib/public/core/Runtime.swift.gyb

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

351351
% if bits == 80:
352-
#if !os(Windows) && (arch(i386) || arch(x86_64))
352+
#if !os(Windows) && !os(Cygwin) && (arch(i386) || arch(x86_64))
353353
% end
354354

355355
@warn_unused_result
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

test/Parse/ConditionalCompilation/x64WindowsTarget.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
1+
// RUN: %swift -parse %s -verify -D FOO -D BAR -target x86_64-unknown-windows-msvc -disable-objc-interop -D FOO -parse-stdlib
2+
// RUN: %swift-ide-test -test-input-complete -source-filename=%s -target x86_64-unknown-windows-msvc
33

44
#if arch(x86_64) && os(Windows) && _runtime(_Native)
55
class C {}

0 commit comments

Comments
 (0)