@@ -4,7 +4,7 @@ This document describes how to build Swift for Windows natively. See [the
4
4
Windows doc] ( ./Windows.md ) for more about what is possible with Swift on
5
5
Windows.
6
6
7
- There are two supported ways to build Swift on Windows, they are
7
+ There are two supported ways to build Swift on Windows:
8
8
9
9
1 . Using [ ` clang-cl ` ] ( https://clang.llvm.org/docs/UsersManual.html#clang-cl )
10
10
1 . Using the Microsoft Visual C++ compiler (MSVC)
@@ -38,12 +38,13 @@ it provides some of the needed headers and libraries.
38
38
1 . Clone ` apple/swift-compiler-rt ` into a folder named ` compiler-rt `
39
39
1 . Clone ` apple/swift ` into a folder named ` swift `
40
40
1 . Clone ` apple/swift-corelibs-libdispatch ` into a folder named ` swift-corelibs-libdispatch `
41
- 1 . Clone ` apple/swift-corelibs-foundation ` into a folder name ` swift-corelibs-foundation `
41
+ 1 . Clone ` apple/swift-corelibs-foundation ` into a folder named ` swift-corelibs-foundation `
42
+ 1 . Clone ` apple/swift-lldb ` into a folder named ` lldb `
42
43
43
44
- Currently, other repositories in the Swift project have not been tested and
44
45
may not be supported.
45
46
46
- If your sources live else where , you can create a substitution for this:
47
+ This guide assumes your sources live at the root of ` S: ` . If your sources live elsewhere , you can create a substitution for this:
47
48
48
49
``` cmd
49
50
subst S: <path to sources>
@@ -59,12 +60,17 @@ git clone https://github.com/apple/swift-compiler-rt compiler-rt
59
60
git clone https://github.com/apple/swift
60
61
git clone https://github.com/apple/swift-corelibs-libdispatch
61
62
git clone https://github.com/apple/swift-corelibs-foundation
63
+ git clone https://github.com/apple/swift-lldb lldb
62
64
```
63
65
64
66
### 3. Acquire ICU
65
67
1 . Download ICU from [ ICU Project] ( http://site.icu-project.org ) for Windows x64 and extract the binaries.
66
68
1 . Add the ` bin64 ` folder to your ` Path ` environment variable.
67
69
70
+ ``` cmd
71
+ PATH S:\icu\bin64;%PATH%
72
+ ```
73
+
68
74
### 4. Get ready
69
75
- From within a ** developer** command prompt (not PowerShell nor cmd, but the [ Visual Studio Developer Command Prompt] ( https://msdn.microsoft.com/en-us/library/f35ctcxw.aspx ) ), execute the following command if you have an x64 PC.
70
76
@@ -89,22 +95,24 @@ VsDevCmd -arch=x86
89
95
90
96
``` cmd
91
97
mklink "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap" S:\swift\stdlib\public\Platform\ucrt.modulemap
98
+ mklink "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap" S:\swift\stdlib\public\Platform\winsdk.modulemap
92
99
mklink "%VCToolsInstallDir%\include\module.modulemap" S:\swift\stdlib\public\Platform\visualc.modulemap
93
100
mklink "%VCToolsInstallDir%\include\visualc.apinotes" S:\swift\stdlib\public\Platform\visualc.apinotes
94
- mklink "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap" S:\swift\stdlib\public\Platform\winsdk.modulemap
95
101
```
96
102
103
+ Warning: Creating the above links usually requires adminstrator privileges. The quick and easy way to do this is to open a second developer prompt by right clicking whatever shortcut you used to open the first one, choosing Run As Administrator, and pasting the above commands into the resulting window. You can then close the privileged prompt; this is the only step which requires elevation.
104
+
97
105
### 5. Build CMark
98
106
- This must be done from within a developer command prompt. CMark is a fairly
99
107
small project and should only take a few minutes to build.
100
108
``` cmd
101
- mkdir S:\build\Ninja-DebugAssert\cmark-windows-amd64"
102
- pushd S:\build\Ninja-DebugAssert\cmark-windows-amd64" "S:\cmark "
109
+ mkdir " S:\build\Ninja-DebugAssert\cmark-windows-amd64"
110
+ pushd " S:\build\Ninja-DebugAssert\cmark-windows-amd64"
103
111
cmake -G Ninja^
104
112
-DCMAKE_BUILD_TYPE=Debug^
105
113
-DCMAKE_C_COMPILER=cl^
106
114
-DCMAKE_CXX_COMPILER=cl^
107
- S:\ cmark
115
+ S:/ cmark
108
116
popd
109
117
cmake --build "S:\build\Ninja-DebugAssert\cmark-windows-amd64"
110
118
```
@@ -117,23 +125,23 @@ cmake --build "S:\build\Ninja-DebugAssert\cmark-windows-amd64"
117
125
``` cmd
118
126
mkdir "S:\build\Ninja-DebugAssert\llvm-windows-amd64"
119
127
pushd "S:\build\Ninja-DebugAssert\llvm-windows-amd64"
120
- cmake -G " Ninja" ^
128
+ cmake -G Ninja^
121
129
-DCMAKE_BUILD_TYPE=Debug^
122
130
-DCMAKE_C_COMPILER=cl^
123
131
-DCMAKE_CXX_COMPILER=cl^
124
132
-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-windows-msvc^
125
- -DLLVM_ENABLE_ASSERTIONS=TRUE ^
133
+ -DLLVM_ENABLE_ASSERTIONS=ON ^
126
134
-DLLVM_ENABLE_PROJECTS=clang^
127
135
-DLLVM_TARGETS_TO_BUILD=X86^
128
- "S:\ llvm"
136
+ S:/ llvm
129
137
popd
130
138
cmake --build "S:\build\Ninja-DebugAssert\llvm-windows-amd64"
131
139
```
132
140
133
141
- Update your path to include the LLVM tools.
134
142
135
143
``` cmd
136
- set PATH= S:\build\Ninja-DebugAssert\llvm-windows-amd64\bin;%PATH%
144
+ PATH S:\build\Ninja-DebugAssert\llvm-windows-amd64\bin;%PATH%
137
145
```
138
146
139
147
### 7. Build Swift
@@ -144,27 +152,26 @@ set PATH=S:\build\Ninja-DebugAssert\llvm-windows-amd64\bin;%PATH%
144
152
``` cmd
145
153
mkdir "S:\build\Ninja-DebugAssert\swift-windows-amd64"
146
154
pushd "S:\build\inja-DebugAssert\swift-windows-amd64"
147
- cmake -G " Ninja" ^
155
+ cmake -G Ninja^
148
156
-DCMAKE_BUILD_TYPE=Debug^
149
157
-DCMAKE_C_COMPILER=clang-cl^
150
158
-DCMAKE_CXX_COMPILER=clang-cl^
151
- -DSWIFT_PATH_TO_CMARK_SOURCE="S:\cmark"^
152
- -DCMAKE_CXX_FLAGS="-Wno-c++98-compat -Wno-c++98-compat-pedantic"^
159
+ -DCMAKE_CXX_FLAGS:STRING="-Wno-c++98-compat -Wno-c++98-compat-pedantic"^
153
160
-DCMAKE_EXE_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^
154
- -DCMAKE_SHARED_LINKER_FLAGS="/INCREMENTAL:NO"^
155
- -DSWIFT_INCLUDE_DOCS=NO^
161
+ -DCMAKE_SHARED_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^
162
+ -DSWIFT_INCLUDE_DOCS=OFF^
163
+ -DSWIFT_PATH_TO_CMARK_SOURCE="S:\cmark"^
164
+ -DSWIFT_PATH_TO_CMARK_BUILD="S:\build\Ninja-DebugAssert\cmark-windows-amd64"^
156
165
-DSWIFT_PATH_TO_LLVM_SOURCE="S:\llvm"^
157
- -DSWIFT_PATH_TO_CLANG_SOURCE="S:\clang"^
158
- -DSWIFT_PATH_TO_LIBDISPATCH_SOURCE="S:\swift-corelibs-libdispatch"^
159
166
-DSWIFT_PATH_TO_LLVM_BUILD="S:\build\Ninja-DebugAssert\llvm-windows-amd64"^
167
+ -DSWIFT_PATH_TO_CLANG_SOURCE="S:\clang"^
160
168
-DSWIFT_PATH_TO_CLANG_BUILD="S:\build\Ninja-DebugAssert\llvm-windows-amd64"^
161
- -DSWIFT_PATH_TO_CMARK_BUILD="S:\build\Ninja-DebugAssert\cmark-windows-amd64"^
162
169
-DSWIFT_WINDOWS_x86_64_ICU_UC_INCLUDE="S:\icu\include"^
163
170
-DSWIFT_WINDOWS_x86_64_ICU_UC="S:\icu\lib64\icuuc.lib"^
164
171
-DSWIFT_WINDOWS_x86_64_ICU_I18N_INCLUDE="S:\icu\include"^
165
172
-DSWIFT_WINDOWS_x86_64_ICU_I18N="S:\icu\lib64\icuin.lib"^
166
173
-DCMAKE_INSTALL_PREFIX="C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr"^
167
- "S:\ swift"
174
+ S:/ swift
168
175
popd
169
176
cmake --build "S:\build\Ninja-DebugAssert\swift-windows-amd64"
170
177
```
@@ -177,7 +184,7 @@ cmake --build "S:\build\Ninja-DebugAssert\swift-windows-amd64"
177
184
a file.
178
185
179
186
``` cmd
180
- cmake -G "Visual Studio 2017" -DCMAKE_GENERATOR_PLATFORM=" x64"^ ...
187
+ cmake -G "Visual Studio 2017" -A x64 -T "host= x64"^ ...
181
188
```
182
189
183
190
### 8. Build lldb
@@ -186,7 +193,7 @@ cmake -G "Visual Studio 2017" -DCMAKE_GENERATOR_PLATFORM="x64"^ ...
186
193
``` cmd
187
194
mkdir "S:/build/Ninja-DebugAssert/lldb-windows-amd64"
188
195
pushd "S:/build/Ninja-DebugAssert/lldb-windows-amd64"
189
- cmake -G " Ninja" "S:/lldb"^
196
+ cmake -G Ninja
190
197
-DCMAKE_BUILD_TYPE=Debug^
191
198
-DLLDB_PATH_TO_CMARK_SOURCE="S:/cmark"^
192
199
-DLLDB_PATH_TO_LLVM_SOURCE="S:/llvm"^
@@ -196,7 +203,8 @@ cmake -G "Ninja" "S:/lldb"^
196
203
-DLLDB_PATH_TO_CLANG_BUILD="S:/build/Ninja-DebugAssert/llvm-windows-amd64"^
197
204
-DLLDB_PATH_TO_LLVM_BUILD="S:/build/Ninja-DebugAssert/llvm-windows-amd64"^
198
205
-DLLDB_PATH_TO_SWIFT_BUILD="S:/build/Ninja-DebugAssert/swift-windows-amd64"^
199
- -DLLVM_ENABLE_ASSERTIONS=YES
206
+ -DLLVM_ENABLE_ASSERTIONS=ON^
207
+ S:/lldb
200
208
popd
201
209
cmake --build "S:/build/Ninja-DebugAssert/lldb-windows-amd64"
202
210
```
@@ -221,36 +229,41 @@ ninja -C "S:/build/Ninja-DebugAssert/swift-windows-amd64" check-swift
221
229
``` cmd
222
230
mkdir "S:/build/Ninja-DebugAssert/swift-corelibs-libdispatch-windows-amd64"
223
231
pushd "S:/build/Ninja-DebugAssert/swift-corelibs-libdispatch-windows-amd64"
224
- cmake -G " Ninja" ^
232
+ cmake -G Ninja^
225
233
-DCMAKE_BUILD_TYPE=Debug^
226
234
-DCMAKE_C_COMPILER="S:/build/Ninja-DebugAssert/llvm-windows-amd64/bin/clang-cl.exe"^
227
235
-DCMAKE_CXX_COMPILER="S:/build/Ninja-DebugAssert/llvm-windows-amd64/bin/clang-cl.exe"^
228
236
-DCMAKE_SWIFT_COMPILER="S:/build/Ninja-DebugAssert/swift-windows-amd64/bin/swiftc.exe"^
229
237
-DSwift_DIR="S:/build/Ninja-DebugAssert/swift-windows-amd64/lib/cmake/swift"^
230
- -DENABLE_SWIFT=YES ^
231
- -DENABLE_TESTING=NO ^
238
+ -DENABLE_SWIFT=ON ^
239
+ -DENABLE_TESTING=OFF ^
232
240
S:/swift-corelibs-libdispatch
233
241
popd
234
242
cmake --build
235
243
```
236
244
237
245
### 11. Build swift-corelibs-foundation
238
246
247
+ To build Foundation you will need builds of:
248
+
249
+ - ` libxml2 ` (http://xmlsoft.org , download and unzip the Windows prebuilt or build your own)
250
+ - ` libcurl ` (https://curl.haxx.se , download the source, ` cd ` into ` winbuild ` , and run ` nmake /f Makefile.vc mode=static VC=15 MACHINE=x64 ` )
251
+
239
252
``` cmd
240
253
mkdir "S:/build/Ninja-DebugAssert/swift-corelibs-foundation-windows-amd64"
241
254
pushd "S:/build/Ninja-DebugAssert/swift-corelibs-foundation-windows-amd64"
242
- cmake -G " Ninja" ^
255
+ cmake -G Ninja^
243
256
-DCMAKE_BUILD_TYPE=Debug^
244
257
-DCMAKE_C_COMPILER="S:/build/Ninja-DebugAssert/llvm-windows-amd64/bin/clang-cl.exe"^
245
258
-DCMAKE_SWIFT_COMPILER="S:/build/Ninja-DebugAssert/swift-windows-amd64/bin/swiftc.exe"^
246
- -DCURL_LIBRARY="S:/curl/builds/libcurl-VS15 -x64-release-static-ipv6-sspi-winssl/lib/libcurl_a.lib"^
247
- -DCURL_INCLUDE_DIR="S:/curl/builds/libcurl-VS15 -x64-release-static-ipv6-sspi-winssl/include"^
259
+ -DCURL_LIBRARY="S:/curl/builds/libcurl-vc15 -x64-release-static-ipv6-sspi-winssl/lib/libcurl_a.lib"^
260
+ -DCURL_INCLUDE_DIR="S:/curl/builds/libcurl-vc15 -x64-release-static-ipv6-sspi-winssl/include"^
248
261
-DICU_ROOT="S:/thirdparty/icu4c-63_1-Win64-MSVC2017"^
249
262
-DLIBXML2_LIBRARY="S:/libxml2/win32/bin.msvc/libxml2_a.lib"^
250
263
-DLIBXML2_INCLUDE_DIR="S:/libxml2/include"^
251
264
-DFOUNDATION_PATH_TO_LIBDISPATCH_SOURCE="S:/swift-corelibs-libdispatch"^
252
265
-DFOUNDATION_PATH_TO_LIBDISPATCH_BUILD="S:/build/Ninja-DebugAssert/swift-corelibs-libdispatch-windows-amd64"^
253
- " S:/swift-corelibs-foundation"
266
+ S:/swift-corelibs-foundation
254
267
cmake --build "S:/build/Ninja-DebugAssert/swift-corelibs-foundation-windows-amd64"
255
268
256
269
```
0 commit comments