@@ -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,27 @@ 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 "^
169
+ -DSWIFT_PATH_TO_LIBDISPATCH_SOURCE ="S:\swift-corelibs-libdispatch "^
162
170
-DSWIFT_WINDOWS_x86_64_ICU_UC_INCLUDE="S:\icu\include"^
163
171
-DSWIFT_WINDOWS_x86_64_ICU_UC="S:\icu\lib64\icuuc.lib"^
164
172
-DSWIFT_WINDOWS_x86_64_ICU_I18N_INCLUDE="S:\icu\include"^
165
173
-DSWIFT_WINDOWS_x86_64_ICU_I18N="S:\icu\lib64\icuin.lib"^
166
174
-DCMAKE_INSTALL_PREFIX="C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr"^
167
- "S:\ swift"
175
+ S:/ swift
168
176
popd
169
177
cmake --build "S:\build\Ninja-DebugAssert\swift-windows-amd64"
170
178
```
@@ -177,7 +185,7 @@ cmake --build "S:\build\Ninja-DebugAssert\swift-windows-amd64"
177
185
a file.
178
186
179
187
``` cmd
180
- cmake -G "Visual Studio 2017" -DCMAKE_GENERATOR_PLATFORM=" x64"^ ...
188
+ cmake -G "Visual Studio 2017" -A x64 -T "host= x64"^ ...
181
189
```
182
190
183
191
### 8. Build lldb
@@ -186,7 +194,7 @@ cmake -G "Visual Studio 2017" -DCMAKE_GENERATOR_PLATFORM="x64"^ ...
186
194
``` cmd
187
195
mkdir "S:/build/Ninja-DebugAssert/lldb-windows-amd64"
188
196
pushd "S:/build/Ninja-DebugAssert/lldb-windows-amd64"
189
- cmake -G " Ninja" "S:/lldb"^
197
+ cmake -G Ninja
190
198
-DCMAKE_BUILD_TYPE=Debug^
191
199
-DLLDB_PATH_TO_CMARK_SOURCE="S:/cmark"^
192
200
-DLLDB_PATH_TO_LLVM_SOURCE="S:/llvm"^
@@ -196,7 +204,8 @@ cmake -G "Ninja" "S:/lldb"^
196
204
-DLLDB_PATH_TO_CLANG_BUILD="S:/build/Ninja-DebugAssert/llvm-windows-amd64"^
197
205
-DLLDB_PATH_TO_LLVM_BUILD="S:/build/Ninja-DebugAssert/llvm-windows-amd64"^
198
206
-DLLDB_PATH_TO_SWIFT_BUILD="S:/build/Ninja-DebugAssert/swift-windows-amd64"^
199
- -DLLVM_ENABLE_ASSERTIONS=YES
207
+ -DLLVM_ENABLE_ASSERTIONS=ON^
208
+ S:/lldb
200
209
popd
201
210
cmake --build "S:/build/Ninja-DebugAssert/lldb-windows-amd64"
202
211
```
@@ -221,36 +230,41 @@ ninja -C "S:/build/Ninja-DebugAssert/swift-windows-amd64" check-swift
221
230
``` cmd
222
231
mkdir "S:/build/Ninja-DebugAssert/swift-corelibs-libdispatch-windows-amd64"
223
232
pushd "S:/build/Ninja-DebugAssert/swift-corelibs-libdispatch-windows-amd64"
224
- cmake -G " Ninja" ^
233
+ cmake -G Ninja^
225
234
-DCMAKE_BUILD_TYPE=Debug^
226
235
-DCMAKE_C_COMPILER="S:/build/Ninja-DebugAssert/llvm-windows-amd64/bin/clang-cl.exe"^
227
236
-DCMAKE_CXX_COMPILER="S:/build/Ninja-DebugAssert/llvm-windows-amd64/bin/clang-cl.exe"^
228
237
-DCMAKE_SWIFT_COMPILER="S:/build/Ninja-DebugAssert/swift-windows-amd64/bin/swiftc.exe"^
229
238
-DSwift_DIR="S:/build/Ninja-DebugAssert/swift-windows-amd64/lib/cmake/swift"^
230
- -DENABLE_SWIFT=YES ^
231
- -DENABLE_TESTING=NO ^
239
+ -DENABLE_SWIFT=ON ^
240
+ -DENABLE_TESTING=OFF ^
232
241
S:/swift-corelibs-libdispatch
233
242
popd
234
243
cmake --build
235
244
```
236
245
237
246
### 11. Build swift-corelibs-foundation
238
247
248
+ To build Foundation you will need builds of:
249
+
250
+ - ` libxml2 ` (http://xmlsoft.org , download and unzip the Windows prebuilt or build your own)
251
+ - ` libcurl ` (https://curl.haxx.se , download the source, ` cd ` into ` winbuild ` , and run ` nmake /f Makefile.vc mode=static VC=15 MACHINE=x64 ` )
252
+
239
253
``` cmd
240
254
mkdir "S:/build/Ninja-DebugAssert/swift-corelibs-foundation-windows-amd64"
241
255
pushd "S:/build/Ninja-DebugAssert/swift-corelibs-foundation-windows-amd64"
242
- cmake -G " Ninja" ^
256
+ cmake -G Ninja^
243
257
-DCMAKE_BUILD_TYPE=Debug^
244
258
-DCMAKE_C_COMPILER="S:/build/Ninja-DebugAssert/llvm-windows-amd64/bin/clang-cl.exe"^
245
259
-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"^
260
+ -DCURL_LIBRARY="S:/curl/builds/libcurl-vc15 -x64-release-static-ipv6-sspi-winssl/lib/libcurl_a.lib"^
261
+ -DCURL_INCLUDE_DIR="S:/curl/builds/libcurl-vc15 -x64-release-static-ipv6-sspi-winssl/include"^
248
262
-DICU_ROOT="S:/thirdparty/icu4c-63_1-Win64-MSVC2017"^
249
263
-DLIBXML2_LIBRARY="S:/libxml2/win32/bin.msvc/libxml2_a.lib"^
250
264
-DLIBXML2_INCLUDE_DIR="S:/libxml2/include"^
251
265
-DFOUNDATION_PATH_TO_LIBDISPATCH_SOURCE="S:/swift-corelibs-libdispatch"^
252
266
-DFOUNDATION_PATH_TO_LIBDISPATCH_BUILD="S:/build/Ninja-DebugAssert/swift-corelibs-libdispatch-windows-amd64"^
253
- " S:/swift-corelibs-foundation"
267
+ S:/swift-corelibs-foundation
254
268
cmake --build "S:/build/Ninja-DebugAssert/swift-corelibs-foundation-windows-amd64"
255
269
256
270
```
0 commit comments