Skip to content

Commit 4f106b2

Browse files
authored
Merge pull request #22165 from gwynne/winbuild-instructions-fixes
2 parents 5aebae0 + 060d2b5 commit 4f106b2

File tree

1 file changed

+44
-30
lines changed

1 file changed

+44
-30
lines changed

docs/WindowsBuild.md

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This document describes how to build Swift for Windows natively. See [the
44
Windows doc](./Windows.md) for more about what is possible with Swift on
55
Windows.
66

7-
There are two supported ways to build Swift on Windows, they are
7+
There are two supported ways to build Swift on Windows:
88

99
1. Using [`clang-cl`](https://clang.llvm.org/docs/UsersManual.html#clang-cl)
1010
1. Using the Microsoft Visual C++ compiler (MSVC)
@@ -38,12 +38,13 @@ it provides some of the needed headers and libraries.
3838
1. Clone `apple/swift-compiler-rt` into a folder named `compiler-rt`
3939
1. Clone `apple/swift` into a folder named `swift`
4040
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`
4243

4344
- Currently, other repositories in the Swift project have not been tested and
4445
may not be supported.
4546

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:
4748

4849
```cmd
4950
subst S: <path to sources>
@@ -59,12 +60,17 @@ git clone https://github.com/apple/swift-compiler-rt compiler-rt
5960
git clone https://github.com/apple/swift
6061
git clone https://github.com/apple/swift-corelibs-libdispatch
6162
git clone https://github.com/apple/swift-corelibs-foundation
63+
git clone https://github.com/apple/swift-lldb lldb
6264
```
6365

6466
### 3. Acquire ICU
6567
1. Download ICU from [ICU Project](http://site.icu-project.org) for Windows x64 and extract the binaries.
6668
1. Add the `bin64` folder to your `Path` environment variable.
6769

70+
```cmd
71+
PATH S:\icu\bin64;%PATH%
72+
```
73+
6874
### 4. Get ready
6975
- 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.
7076

@@ -89,22 +95,24 @@ VsDevCmd -arch=x86
8995

9096
```cmd
9197
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
9299
mklink "%VCToolsInstallDir%\include\module.modulemap" S:\swift\stdlib\public\Platform\visualc.modulemap
93100
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
95101
```
96102

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+
97105
### 5. Build CMark
98106
- This must be done from within a developer command prompt. CMark is a fairly
99107
small project and should only take a few minutes to build.
100108
```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"
103111
cmake -G Ninja^
104112
-DCMAKE_BUILD_TYPE=Debug^
105113
-DCMAKE_C_COMPILER=cl^
106114
-DCMAKE_CXX_COMPILER=cl^
107-
S:\cmark
115+
S:/cmark
108116
popd
109117
cmake --build "S:\build\Ninja-DebugAssert\cmark-windows-amd64"
110118
```
@@ -117,23 +125,23 @@ cmake --build "S:\build\Ninja-DebugAssert\cmark-windows-amd64"
117125
```cmd
118126
mkdir "S:\build\Ninja-DebugAssert\llvm-windows-amd64"
119127
pushd "S:\build\Ninja-DebugAssert\llvm-windows-amd64"
120-
cmake -G "Ninja"^
128+
cmake -G Ninja^
121129
-DCMAKE_BUILD_TYPE=Debug^
122130
-DCMAKE_C_COMPILER=cl^
123131
-DCMAKE_CXX_COMPILER=cl^
124132
-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-windows-msvc^
125-
-DLLVM_ENABLE_ASSERTIONS=TRUE^
133+
-DLLVM_ENABLE_ASSERTIONS=ON^
126134
-DLLVM_ENABLE_PROJECTS=clang^
127135
-DLLVM_TARGETS_TO_BUILD=X86^
128-
"S:\llvm"
136+
S:/llvm
129137
popd
130138
cmake --build "S:\build\Ninja-DebugAssert\llvm-windows-amd64"
131139
```
132140

133141
- Update your path to include the LLVM tools.
134142

135143
```cmd
136-
set PATH=S:\build\Ninja-DebugAssert\llvm-windows-amd64\bin;%PATH%
144+
PATH S:\build\Ninja-DebugAssert\llvm-windows-amd64\bin;%PATH%
137145
```
138146

139147
### 7. Build Swift
@@ -144,27 +152,27 @@ set PATH=S:\build\Ninja-DebugAssert\llvm-windows-amd64\bin;%PATH%
144152
```cmd
145153
mkdir "S:\build\Ninja-DebugAssert\swift-windows-amd64"
146154
pushd "S:\build\inja-DebugAssert\swift-windows-amd64"
147-
cmake -G "Ninja"^
155+
cmake -G Ninja^
148156
-DCMAKE_BUILD_TYPE=Debug^
149157
-DCMAKE_C_COMPILER=clang-cl^
150158
-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"^
153160
-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"^
156165
-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"^
159166
-DSWIFT_PATH_TO_LLVM_BUILD="S:\build\Ninja-DebugAssert\llvm-windows-amd64"^
167+
-DSWIFT_PATH_TO_CLANG_SOURCE="S:\clang"^
160168
-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"^
162170
-DSWIFT_WINDOWS_x86_64_ICU_UC_INCLUDE="S:\icu\include"^
163171
-DSWIFT_WINDOWS_x86_64_ICU_UC="S:\icu\lib64\icuuc.lib"^
164172
-DSWIFT_WINDOWS_x86_64_ICU_I18N_INCLUDE="S:\icu\include"^
165173
-DSWIFT_WINDOWS_x86_64_ICU_I18N="S:\icu\lib64\icuin.lib"^
166174
-DCMAKE_INSTALL_PREFIX="C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr"^
167-
"S:\swift"
175+
S:/swift
168176
popd
169177
cmake --build "S:\build\Ninja-DebugAssert\swift-windows-amd64"
170178
```
@@ -177,7 +185,7 @@ cmake --build "S:\build\Ninja-DebugAssert\swift-windows-amd64"
177185
a file.
178186

179187
```cmd
180-
cmake -G "Visual Studio 2017" -DCMAKE_GENERATOR_PLATFORM="x64"^ ...
188+
cmake -G "Visual Studio 2017" -A x64 -T "host=x64"^ ...
181189
```
182190

183191
### 8. Build lldb
@@ -186,7 +194,7 @@ cmake -G "Visual Studio 2017" -DCMAKE_GENERATOR_PLATFORM="x64"^ ...
186194
```cmd
187195
mkdir "S:/build/Ninja-DebugAssert/lldb-windows-amd64"
188196
pushd "S:/build/Ninja-DebugAssert/lldb-windows-amd64"
189-
cmake -G "Ninja" "S:/lldb"^
197+
cmake -G Ninja
190198
-DCMAKE_BUILD_TYPE=Debug^
191199
-DLLDB_PATH_TO_CMARK_SOURCE="S:/cmark"^
192200
-DLLDB_PATH_TO_LLVM_SOURCE="S:/llvm"^
@@ -196,7 +204,8 @@ cmake -G "Ninja" "S:/lldb"^
196204
-DLLDB_PATH_TO_CLANG_BUILD="S:/build/Ninja-DebugAssert/llvm-windows-amd64"^
197205
-DLLDB_PATH_TO_LLVM_BUILD="S:/build/Ninja-DebugAssert/llvm-windows-amd64"^
198206
-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
200209
popd
201210
cmake --build "S:/build/Ninja-DebugAssert/lldb-windows-amd64"
202211
```
@@ -221,36 +230,41 @@ ninja -C "S:/build/Ninja-DebugAssert/swift-windows-amd64" check-swift
221230
```cmd
222231
mkdir "S:/build/Ninja-DebugAssert/swift-corelibs-libdispatch-windows-amd64"
223232
pushd "S:/build/Ninja-DebugAssert/swift-corelibs-libdispatch-windows-amd64"
224-
cmake -G "Ninja"^
233+
cmake -G Ninja^
225234
-DCMAKE_BUILD_TYPE=Debug^
226235
-DCMAKE_C_COMPILER="S:/build/Ninja-DebugAssert/llvm-windows-amd64/bin/clang-cl.exe"^
227236
-DCMAKE_CXX_COMPILER="S:/build/Ninja-DebugAssert/llvm-windows-amd64/bin/clang-cl.exe"^
228237
-DCMAKE_SWIFT_COMPILER="S:/build/Ninja-DebugAssert/swift-windows-amd64/bin/swiftc.exe"^
229238
-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^
232241
S:/swift-corelibs-libdispatch
233242
popd
234243
cmake --build
235244
```
236245

237246
### 11. Build swift-corelibs-foundation
238247

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+
239253
```cmd
240254
mkdir "S:/build/Ninja-DebugAssert/swift-corelibs-foundation-windows-amd64"
241255
pushd "S:/build/Ninja-DebugAssert/swift-corelibs-foundation-windows-amd64"
242-
cmake -G "Ninja"^
256+
cmake -G Ninja^
243257
-DCMAKE_BUILD_TYPE=Debug^
244258
-DCMAKE_C_COMPILER="S:/build/Ninja-DebugAssert/llvm-windows-amd64/bin/clang-cl.exe"^
245259
-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"^
248262
-DICU_ROOT="S:/thirdparty/icu4c-63_1-Win64-MSVC2017"^
249263
-DLIBXML2_LIBRARY="S:/libxml2/win32/bin.msvc/libxml2_a.lib"^
250264
-DLIBXML2_INCLUDE_DIR="S:/libxml2/include"^
251265
-DFOUNDATION_PATH_TO_LIBDISPATCH_SOURCE="S:/swift-corelibs-libdispatch"^
252266
-DFOUNDATION_PATH_TO_LIBDISPATCH_BUILD="S:/build/Ninja-DebugAssert/swift-corelibs-libdispatch-windows-amd64"^
253-
"S:/swift-corelibs-foundation"
267+
S:/swift-corelibs-foundation
254268
cmake --build "S:/build/Ninja-DebugAssert/swift-corelibs-foundation-windows-amd64"
255269
256270
```

0 commit comments

Comments
 (0)