Skip to content

Commit ba8a669

Browse files
committed
Porting to Cygwin
1 parent 51ee08e commit ba8a669

37 files changed

+482
-29
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
cmake_minimum_required(VERSION 2.8.12)
2+
cmake_policy(SET CMP0054 NEW)
23

34
# Add path for custom CMake modules.
45
list(APPEND CMAKE_MODULE_PATH
@@ -437,6 +438,19 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
437438

438439
set(SWIFT_PRIMARY_VARIANT_SDK_default "FREEBSD")
439440
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
441+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN")
442+
configure_sdk_unix(CYGWIN "Cygwin" "windows" "cygwin" "x86_64" "x86_64-unknown-windows-cygnus")
443+
444+
# set(CMAKE_EXECUTABLE_FORMAT "ELF")
445+
446+
set(SWIFT_HOST_VARIANT "windows" CACHE STRING
447+
"Deployment OS for Swift host tools (the compiler) [windows].")
448+
449+
set(SWIFT_HOST_VARIANT_SDK "CYGWIN")
450+
set(SWIFT_HOST_VARIANT_ARCH "x86_64")
451+
452+
set(SWIFT_PRIMARY_VARIANT_SDK_default "CYGWIN")
453+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
440454
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
441455
# Set defaults.
442456

cmake/modules/AddSwift.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ function(_add_variant_link_flags
176176
list(APPEND result "-lpthread" "-ldl" "-Wl,-Bsymbolic")
177177
elseif("${sdk}" STREQUAL "FREEBSD")
178178
list(APPEND result "-lpthread" "-Wl,-Bsymbolic")
179+
elseif("${sdk}" STREQUAL "CYGWIN")
180+
# No extra libraries required.
179181
else()
180182
list(APPEND result "-lobjc")
181183
endif()

include/swift/Basic/Dwarf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121

2222
namespace swift {
2323
/// The DWARF version emitted by the Swift compiler.
24+
#if defined(__CYGWIN__)
25+
const unsigned DWARFVersion = 4;
26+
#else
2427
const unsigned DWARFVersion = 3;
28+
#endif
2529
static const char MachOASTSegmentName[] = "__SWIFT";
2630
static const char MachOASTSectionName[] = "__ast";
2731
static const char ELFASTSectionName[] = ".swift_ast";

include/swift/Basic/LangOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ namespace swift {
173173
} else if (Target.isWatchOS()) {
174174
Target.getOSVersion(major, minor, revision);
175175
} else if (Target.isOSLinux() || Target.isOSFreeBSD() ||
176+
Target.isOSWindows() ||
176177
Target.getTriple().empty())
177178
{
178179
major = minor = revision = 0;

include/swift/Runtime/Once.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ namespace swift {
2727
// On OS X and iOS, swift_once_t matches dispatch_once_t.
2828
typedef long swift_once_t;
2929

30+
#elif defined(__CYGWIN__)
31+
32+
// On Cygwin, std::once_flag can not be used because it is larger than the
33+
// platform word.
34+
typedef unsigned long swift_once_t;
3035
#else
3136

3237
// On other platforms swift_once_t is std::once_flag

lib/Basic/Demangle.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/ADT/StringRef.h"
2424
#include <functional>
2525
#include <vector>
26+
#include <cstdio>
2627
#include <cstdlib>
2728

2829
using namespace swift;

lib/Basic/LangOptions.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const std::vector<std::string> LangOptions::SupportedOSBuildConfigArguments = {
2929
"watchOS",
3030
"iOS",
3131
"Linux",
32-
"FreeBSD"
32+
"FreeBSD",
33+
"Windows"
3334
};
3435

3536
const std::vector<std::string> LangOptions::SupportedArchBuildConfigArguments = {
@@ -103,6 +104,8 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
103104
addTargetConfigOption("os", "Linux");
104105
else if (triple.isOSFreeBSD())
105106
addTargetConfigOption("os", "FreeBSD");
107+
else if (triple.isOSWindows())
108+
addTargetConfigOption("os", "Windows");
106109
else {
107110
UnsupportedOS = true;
108111
}

lib/Basic/Platform.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
6666

6767
if (triple.isOSFreeBSD())
6868
return "freebsd";
69+
70+
if (triple.isOSWindows())
71+
return "windows";
6972

7073
return "";
7174
}

lib/Basic/Remangle.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/Strings.h"
2525
#include "llvm/ADT/StringRef.h"
2626
#include <vector>
27+
#include <cstdio>
2728
#include <cstdlib>
2829
#include <unordered_map>
2930

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
26+
#if LLVM_ON_UNIX && !defined(__CYGWIN__)
2727
#include "Unix/TaskQueue.inc"
2828
#else
2929
#include "Default/TaskQueue.inc"

0 commit comments

Comments
 (0)