@@ -25,6 +25,8 @@ Windows.
25
25
- Using the latest Visual Studio version is recommended (tested with Visual
26
26
Studio 2017 - Version 15.5.5). Swift may fail to build with older C++
27
27
compilers.
28
+ - Note that the release version of Swift on Windows may crash when you try to compile a
29
+ Swift program. See bug report [ SR-7867] ( https://bugs.swift.org/browse/SR-7867 ) .
28
30
29
31
### 1. Install dependencies
30
32
1 . Latest version (2.7.12 tested) of [ Python
@@ -44,14 +46,15 @@ Windows.
44
46
1 . Clone ` apple/swift-cmark ` into a folder named ` cmark `
45
47
1 . Clone ` apple/swift-clang ` into a folder named ` clang `
46
48
1 . Clone ` apple/swift-llvm ` into a folder named ` llvm `
49
+ 1 . Clone ` apple/swift-compiler-rt ` into a folder named ` compiler-rt `
47
50
1 . Clone ` apple/swift ` into a folder named ` swift `
48
51
- Currently, other repositories in the Swift project have not been tested and
49
52
may not be supported.
50
53
51
54
### 3. Build ICU
52
55
1 . Download and extract the [ ICU source
53
56
code] ( http://site.icu-project.org/download ) to a folder named ` icu ` in the same
54
- directory as the other Swift project repositories.
57
+ directory as the other Swift project repositories (tested with ICU versions 55.1 and 59.1) .
55
58
1 . Open ` src/win32/allinone.sln ` in Visual Studio.
56
59
1 . Make sure to select the correct architecture from the drop-down in Visual
57
60
Studio.
@@ -81,32 +84,37 @@ VsDevCmd -arch=x86
81
84
set swift_source_dir=path-to-directory-containing-all-cloned-repositories
82
85
```
83
86
87
+ - Decide whether you want to build a release or debug version of Swift on Windows and
88
+ replace the ` CMAKE_BUILD_TYPE ` parameter in the build steps below with the correct value
89
+ (` Debug ` , ` RelWithDebInfoAssert ` or ` Release ` ) to avoid conflicts between the debug and
90
+ non-debug version of the MSCRT library.
91
+
84
92
### 5. Build CMark
85
93
- This must be done from within a developer command prompt. CMark is a fairly
86
94
small project and should only take a few minutes to build.
87
95
``` cmd
88
- mkdir "%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /cmark-windows-amd64"
89
- pushd "%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /cmark-windows-amd64"
90
- cmake -G "Ninja" "%swift_source_dir%/cmark"
96
+ mkdir "%swift_source_dir%/build/Ninja-DebugAssert /cmark-windows-amd64"
97
+ pushd "%swift_source_dir%/build/Ninja-DebugAssert /cmark-windows-amd64"
98
+ cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug "%swift_source_dir%/cmark"
91
99
popd
92
- cmake --build "%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /cmark-windows-amd64/"
100
+ cmake --build "%swift_source_dir%/build/Ninja-DebugAssert /cmark-windows-amd64/"
93
101
```
94
102
95
103
### 6. Build LLVM/Clang/Compiler-RT
96
104
- This must be done from within a developer command prompt. LLVM and Clang are
97
105
large projects, so building might take a few hours. Make sure that the build
98
- type (e.g. Debug, Release, RelWithDebInfoAssert) for LLVM/Clang matches the
106
+ type (e.g. ` Debug ` , ` Release ` , ` RelWithDebInfoAssert ` ) for LLVM/Clang matches the
99
107
build type for Swift.
100
108
- Optionally, you can omit building compiler-rt by removing all lines referring
101
109
to ` compiler-rt ` below, which should give faster build times.
102
110
``` cmd
103
111
mklink /J "%swift_source_dir%/llvm/tools/clang" "%swift_source_dir%/clang"
104
112
mklink /J "%swift_source_dir%/llvm/tools/compiler-rt" "%swift_source_dir%/compiler-rt"
105
- mkdir "%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /llvm-windows-amd64"
106
- pushd "%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /llvm-windows-amd64"
113
+ mkdir "%swift_source_dir%/build/Ninja-DebugAssert /llvm-windows-amd64"
114
+ pushd "%swift_source_dir%/build/Ninja-DebugAssert /llvm-windows-amd64"
107
115
cmake -G "Ninja"^
108
116
-DLLVM_ENABLE_ASSERTIONS=TRUE^
109
- -DCMAKE_BUILD_TYPE=RelWithDebInfo ^
117
+ -DCMAKE_BUILD_TYPE=Debug ^
110
118
-DLLVM_TOOL_SWIFT_BUILD=NO^
111
119
-DLLVM_INCLUDE_DOCS=TRUE^
112
120
-DLLVM_TOOL_COMPILER_RT_BUILD=TRUE^
@@ -115,14 +123,14 @@ cmake -G "Ninja"^
115
123
-DLLVM_TARGETS_TO_BUILD=X86^
116
124
"%swift_source_dir%/llvm"
117
125
popd
118
- cmake --build "%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /llvm-windows-amd64"
126
+ cmake --build "%swift_source_dir%/build/Ninja-DebugAssert /llvm-windows-amd64"
119
127
```
120
128
- Store the LLVM ` bin ` directory in an environment variable so it can be used
121
129
to build Swift. Assuming you followed the instructions exactly, the path
122
130
below is correct, but it may be different based on your build variant and
123
131
platform, so double check.
124
132
``` cmd
125
- set llvm_bin_dir="%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /llvm-windows-amd64/bin"
133
+ set llvm_bin_dir="%swift_source_dir%/build/Ninja-DebugAssert /llvm-windows-amd64/bin"
126
134
```
127
135
128
136
### 7. Build Swift
@@ -136,12 +144,12 @@ pushd "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"
136
144
cmake -G "Ninja" "%swift_source_dir%/swift"^
137
145
-DCMAKE_BUILD_TYPE=Debug^
138
146
-DSWIFT_PATH_TO_CMARK_SOURCE="%swift_source_dir%/cmark"^
139
- -DSWIFT_PATH_TO_CMARK_BUILD="%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /cmark-windows-amd64"^
140
- -DSWIFT_CMARK_LIBRARY_DIR="%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /cmark-windows-amd64/src"^
147
+ -DSWIFT_PATH_TO_CMARK_BUILD="%swift_source_dir%/build/Ninja-DebugAssert /cmark-windows-amd64"^
148
+ -DSWIFT_CMARK_LIBRARY_DIR="%swift_source_dir%/build/Ninja-DebugAssert /cmark-windows-amd64/src"^
141
149
-DSWIFT_PATH_TO_LLVM_SOURCE="%swift_source_dir%/llvm"^
142
- -DSWIFT_PATH_TO_LLVM_BUILD="%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /llvm-windows-amd64"^
150
+ -DSWIFT_PATH_TO_LLVM_BUILD="%swift_source_dir%/build/Ninja-DebugAssert /llvm-windows-amd64"^
143
151
-DSWIFT_PATH_TO_CLANG_SOURCE="%swift_source_dir%/llvm/tools/clang"^
144
- -DSWIFT_PATH_TO_CLANG_BUILD="%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /llvm-windows-amd64"^
152
+ -DSWIFT_PATH_TO_CLANG_BUILD="%swift_source_dir%/build/Ninja-DebugAssert /llvm-windows-amd64"^
145
153
-DICU_UC_INCLUDE_DIR="%swift_source_dir%/icu/include"^
146
154
-DICU_UC_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^
147
155
-DICU_I18N_INCLUDE_DIR="%swift_source_dir%/icu/include"^
@@ -153,7 +161,12 @@ cmake -G "Ninja" "%swift_source_dir%/swift"^
153
161
-DCMAKE_C_COMPILER="%llvm_bin_dir%/clang-cl.exe"^
154
162
-DCMAKE_CXX_COMPILER="%llvm_bin_dir%/clang-cl.exe"^
155
163
-DCMAKE_C_FLAGS="-fms-compatibility-version=19.00 /Z7"^
156
- -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.00 -Z7" ^
164
+ -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.00 -Z7"^
165
+ -DCMAKE_EXE_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^
166
+ -DCMAKE_MODULE_LINKER_FLAGS="/INCREMENTAL:NO"^
167
+ -DCMAKE_SHARED_LINKER_FLAGS="/INCREMENTAL:NO"^
168
+ -DCMAKE_STATIC_LINKER_FLAGS="/INCREMENTAL:NO"^
169
+ -DCMAKE_INSTALL_PREFIX="C:/Program Files (x86)/Swift"^
157
170
-DSWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER=FALSE
158
171
popd
159
172
cmake --build "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"
@@ -176,21 +189,40 @@ cmake -G "Visual Studio 15" "%swift_source_dir%/swift"^
176
189
- This must be done from within a developer command prompt and could take hours
177
190
depending on your system.
178
191
``` cmd
179
- mkdir "%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /lldb-windows-amd64"
180
- pushd "%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /lldb-windows-amd64"
192
+ mkdir "%swift_source_dir%/build/Ninja-DebugAssert /lldb-windows-amd64"
193
+ pushd "%swift_source_dir%/build/Ninja-DebugAssert /lldb-windows-amd64"
181
194
cmake -G "Ninja" "%swift_source_dir%/lldb"^
182
- -DCMAKE_BUILD_TYPE=RelWithDebInfo ^
195
+ -DCMAKE_BUILD_TYPE=Debug ^
183
196
-DLLDB_PATH_TO_CMARK_SOURCE="%swift_source_dir%/cmark"^
184
- -DLLDB_PATH_TO_CMARK_BUILD="%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /cmark-windows-amd64"^
197
+ -DLLDB_PATH_TO_CMARK_BUILD="%swift_source_dir%/build/Ninja-DebugAssert /cmark-windows-amd64"^
185
198
-DLLDB_PATH_TO_LLVM_SOURCE="%swift_source_dir%/llvm"^
186
- -DLLDB_PATH_TO_LLVM_BUILD="%swift_source_dir%/build/Ninja-RelWithDebInfoAssert /llvm-windows-amd64"^
199
+ -DLLDB_PATH_TO_LLVM_BUILD="%swift_source_dir%/build/Ninja-DebugAssert /llvm-windows-amd64"^
187
200
-DLLDB_PATH_TO_CLANG_SOURCE="%swift_source_dir%/clang"^
188
- -DLLDB_PATH_TO_CLANG_BUILD="%swift_source_dir%/build/Ninja-RelWithDebInfoAssert/llvm-windows-amd64"^
201
+ -DLLDB_PATH_TO_CLANG_BUILD="%swift_source_dir%/build/Ninja-DebugAssert/llvm-windows-amd64"^
202
+ -DLLDB_PATH_TO_SWIFT_SOURCE="%swift_source_dir%/swift"^
203
+ -DLLDB_PATH_TO_SWIFT_BUILD="%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"^
204
+ -DCMAKE_C_COMPILER="%llvm_bin_dir%/clang-cl.exe"^
205
+ -DCMAKE_CXX_COMPILER="%llvm_bin_dir%/clang-cl.exe"^
206
+ -DCMAKE_C_FLAGS="-fms-compatibility-version=19.00 /Z7"^
207
+ -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.00 -Z7 -Wno-c++98-compat"^
189
208
-DLLVM_ENABLE_ASSERTIONS=YES
190
209
popd
191
210
cmake --build "%swift_source_dir%/build/Ninja-RelWithDebInfoAssert/lldb-windows-amd64"
192
211
```
193
212
213
+ ### 9. Install Swift on Windows
214
+
215
+ - Run ninja install:
216
+ ``` cmd
217
+ pushd "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"
218
+ ninja install
219
+ popd
220
+ ```
221
+ - Add the Swift on Windows binaries path (` C:\Program Files (x86)\Swift\bin ` ) to the
222
+ ` Path ` environment variable.
223
+ - Add the Swift on Windows library path (` C:\Program Files (x86)\Swift\lib\swift\windows ` )
224
+ to the ` Path ` environment variable.
225
+
194
226
## MSVC
195
227
196
228
Follow instructions 1-6 for ` clang-cl ` , but run the following instead to build Swift
0 commit comments