Skip to content

Commit 62b7310

Browse files
authored
Merge pull request #17309 from dplanitzer/windows_docu_update_1
Updated the Windows build documentation:
2 parents a65105c + 47d30ee commit 62b7310

File tree

1 file changed

+54
-22
lines changed

1 file changed

+54
-22
lines changed

docs/WindowsBuild.md

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Windows.
2525
- Using the latest Visual Studio version is recommended (tested with Visual
2626
Studio 2017 - Version 15.5.5). Swift may fail to build with older C++
2727
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).
2830

2931
### 1. Install dependencies
3032
1. Latest version (2.7.12 tested) of [Python
@@ -44,14 +46,15 @@ Windows.
4446
1. Clone `apple/swift-cmark` into a folder named `cmark`
4547
1. Clone `apple/swift-clang` into a folder named `clang`
4648
1. Clone `apple/swift-llvm` into a folder named `llvm`
49+
1. Clone `apple/swift-compiler-rt` into a folder named `compiler-rt`
4750
1. Clone `apple/swift` into a folder named `swift`
4851
- Currently, other repositories in the Swift project have not been tested and
4952
may not be supported.
5053

5154
### 3. Build ICU
5255
1. Download and extract the [ICU source
5356
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).
5558
1. Open `src/win32/allinone.sln` in Visual Studio.
5659
1. Make sure to select the correct architecture from the drop-down in Visual
5760
Studio.
@@ -81,32 +84,37 @@ VsDevCmd -arch=x86
8184
set swift_source_dir=path-to-directory-containing-all-cloned-repositories
8285
```
8386

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+
8492
### 5. Build CMark
8593
- This must be done from within a developer command prompt. CMark is a fairly
8694
small project and should only take a few minutes to build.
8795
```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"
9199
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/"
93101
```
94102

95103
### 6. Build LLVM/Clang/Compiler-RT
96104
- This must be done from within a developer command prompt. LLVM and Clang are
97105
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
99107
build type for Swift.
100108
- Optionally, you can omit building compiler-rt by removing all lines referring
101109
to `compiler-rt` below, which should give faster build times.
102110
```cmd
103111
mklink /J "%swift_source_dir%/llvm/tools/clang" "%swift_source_dir%/clang"
104112
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"
107115
cmake -G "Ninja"^
108116
-DLLVM_ENABLE_ASSERTIONS=TRUE^
109-
-DCMAKE_BUILD_TYPE=RelWithDebInfo^
117+
-DCMAKE_BUILD_TYPE=Debug^
110118
-DLLVM_TOOL_SWIFT_BUILD=NO^
111119
-DLLVM_INCLUDE_DOCS=TRUE^
112120
-DLLVM_TOOL_COMPILER_RT_BUILD=TRUE^
@@ -115,14 +123,14 @@ cmake -G "Ninja"^
115123
-DLLVM_TARGETS_TO_BUILD=X86^
116124
"%swift_source_dir%/llvm"
117125
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"
119127
```
120128
- Store the LLVM `bin` directory in an environment variable so it can be used
121129
to build Swift. Assuming you followed the instructions exactly, the path
122130
below is correct, but it may be different based on your build variant and
123131
platform, so double check.
124132
```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"
126134
```
127135

128136
### 7. Build Swift
@@ -136,12 +144,12 @@ pushd "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"
136144
cmake -G "Ninja" "%swift_source_dir%/swift"^
137145
-DCMAKE_BUILD_TYPE=Debug^
138146
-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"^
141149
-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"^
143151
-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"^
145153
-DICU_UC_INCLUDE_DIR="%swift_source_dir%/icu/include"^
146154
-DICU_UC_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^
147155
-DICU_I18N_INCLUDE_DIR="%swift_source_dir%/icu/include"^
@@ -153,7 +161,12 @@ cmake -G "Ninja" "%swift_source_dir%/swift"^
153161
-DCMAKE_C_COMPILER="%llvm_bin_dir%/clang-cl.exe"^
154162
-DCMAKE_CXX_COMPILER="%llvm_bin_dir%/clang-cl.exe"^
155163
-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"^
157170
-DSWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER=FALSE
158171
popd
159172
cmake --build "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"
@@ -176,21 +189,40 @@ cmake -G "Visual Studio 15" "%swift_source_dir%/swift"^
176189
- This must be done from within a developer command prompt and could take hours
177190
depending on your system.
178191
```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"
181194
cmake -G "Ninja" "%swift_source_dir%/lldb"^
182-
-DCMAKE_BUILD_TYPE=RelWithDebInfo^
195+
-DCMAKE_BUILD_TYPE=Debug^
183196
-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"^
185198
-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"^
187200
-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"^
189208
-DLLVM_ENABLE_ASSERTIONS=YES
190209
popd
191210
cmake --build "%swift_source_dir%/build/Ninja-RelWithDebInfoAssert/lldb-windows-amd64"
192211
```
193212

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+
194226
## MSVC
195227

196228
Follow instructions 1-6 for `clang-cl`, but run the following instead to build Swift

0 commit comments

Comments
 (0)