Skip to content

Commit 72cd23e

Browse files
authored
Merge pull request #6458 from hughbe/windows-instructions
Add instructions for building Swift on Windows using clang-cl/MSVC
2 parents 4a07d7f + 4196c3b commit 72cd23e

File tree

1 file changed

+108
-1
lines changed

1 file changed

+108
-1
lines changed

docs/Windows.md

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,114 @@ Additionally, the ICU headers and libraries need to be provided for the build.
3838
```
3939

4040
## MSVC
41-
To be filled in.
41+
- Windows doesn't currently have a build script. You'll need to run commands manually to build Swift on Windows.
42+
- Release/RelWithDebInfo modes have not been tested and may not be supported.
43+
- Windows support for Swift is very much a WIP, and may not work on your system.
44+
45+
### 1. Install dependencies
46+
- Make sure to add Python, CMake and Ninja to your `Path` environment variable
47+
1. Latest version (2.7.12 tested) of [Python 2](https://www.python.org/downloads/)
48+
2. Latest version (3.7.0-rc3 tested) of [CMake](https://cmake.org/download/)
49+
3. Latest version (1.7.1 tested) of [Ninja](https://github.com/ninja-build/ninja/releases/latest)
50+
4. Latest version (2015 Update 3 tested) of [Visual Studio](https://www.visualstudio.com/downloads/)
51+
- Make sure to include `Programming Languages|Visual C++`, and `Windows and Web Development|Universal Windows App Development|Windows SDK` in your installation.
52+
- Windows SDK 10.0.10240 was tested. Some later versions (e.g. 10.0.14393) are known not to work, as they are not supported by `compiler-rt`.
53+
54+
### 2. Clone the repositories
55+
1. Create a folder to contain all the Swift repositories
56+
2. `apple/swift-cmark` into a folder named `cmark`
57+
3. `apple/swift-clang` into a folder named `clang`
58+
5. `apple/swift-llvm` into a folder named `llvm`
59+
5. `apple/swift` into a folder named `swift`
60+
- Currently, other repositories in the Swift project have not been tested, and may not be supported.
61+
62+
### 3. Build ICU
63+
1. Download and extract the [ICU source code](http://site.icu-project.org/download) to a folder named `icu` in the same directory as the other Swift project repositories.
64+
2. Open `src/win32/allinone.sln` in Visual Studio.
65+
3. Make sure to select the correct architecture from the drop-down in Visual Studio.
66+
4. Right click on the solution in the Solution Explorer window and select `Build Solution`.
67+
5. When this is done, add the `<icu-source>/bin` folder to your `Path` environment variable.
68+
69+
### 4. Get ready
70+
- From within a **developer** command prompt, execute the following command if you have an x64 PC.
71+
```
72+
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/vcvarsall.bat" amd64
73+
```
74+
- Then adapt the following command, and run it.
75+
```
76+
set swift_source_dir=path-to-directory-containing-all-cloned-repositories
77+
```
78+
79+
### 5. Build CMark
80+
- This must be done from within a developer command prompt, and could take up to 10 minutes.
81+
```
82+
mkdir "%swift_source_dir%/build/Ninja-DebugAssert/cmark-windows-amd64"
83+
pushd "%swift_source_dir%/build/Ninja-DebugAssert/cmark-windows-amd64"
84+
cmake -G "Ninja" "%swift_source_dir%/cmark"
85+
popd
86+
cmake --build "%swift_source_dir%/build/Ninja-DebugAssert/cmark-windows-amd64/"
87+
```
88+
89+
### 6. Build LLVM/Clang/Compiler-RT
90+
- This must be done from within a developer command prompt, and could take up to 5 hours.
91+
```
92+
mklink /J "%swift_source_dir%/llvm/tools/clang" "%swift_source_dir%my-swift/clang"
93+
mklink /J "%swift_source_dir%/llvm/tools/compiler-rt" "%swift_source_dir%/compiler-rt"
94+
mkdir "%swift_source_dir%/build/Ninja-DebugAssert/llvm-windows-amd64"
95+
pushd "%swift_source_dir%/build/Ninja-DebugAssert/llvm-windows-amd64"
96+
cmake -G "Ninja"^
97+
-DLLVM_ENABLE_ASSERTIONS=TRUE^
98+
-DCMAKE_BUILD_TYPE=Debug^
99+
-DLLVM_TOOL_SWIFT_BUILD=NO^
100+
-DLLVM_INCLUDE_DOCS=TRUE^
101+
-DLLVM_TOOL_COMPILER_RT_BUILD=TRUE^
102+
-DLLVM_BUILD_EXTERNAL_COMPILER_RT=TRUE^
103+
-DLLVM_LIT_ARGS=-sv^
104+
"%swift_source_dir%/llvm"
105+
popd
106+
cmake --build "%swift_source_dir%/build/Ninja-DebugAssert/llvm-windows-amd64"
107+
```
108+
109+
### 7. Build Swift
110+
- This must be done from within a developer command prompt, and could take up to 2 hours.
111+
- You may need to adjust the SWIFT_WINDOWS_LIB_DIRECTORY parameter depending on your target platform or Windows SDK version.
112+
```
113+
mkdir "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64/ninja"
114+
pushd "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64/ninja"
115+
cmake -G "Ninja" "%swift_source_dir%/swift"^
116+
-DCMAKE_BUILD_TYPE=Debug^
117+
-DSWIFT_PATH_TO_CMARK_SOURCE="%swift_source_dir%/cmark"^
118+
-DSWIFT_PATH_TO_CMARK_BUILD="%swift_source_dir%/build/Ninja-DebugAssert/cmark-windows-amd64"^
119+
-DSWIFT_CMARK_LIBRARY_DIR="%swift_source_dir%/build/Ninja-DebugAssert/cmark-windows-amd64/src"^
120+
-DSWIFT_PATH_TO_LLVM_SOURCE="%swift_source_dir%/llvm"^
121+
-DSWIFT_PATH_TO_LLVM_BUILD="%swift_source_dir%/build/Ninja-DebugAssert/llvm-windows-amd64"^
122+
-DSWIFT_PATH_TO_CLANG_SOURCE="%swift_source_dir%/llvm/tools/clang"^
123+
-DSWIFT_PATH_TO_CLANG_BUILD="%swift_source_dir%/build/Ninja-DebugAssert/llvm-windows-amd64"^
124+
-DICU_UC_INCLUDE_DIRS="%swift_source_dir%/icu/include"^
125+
-DICU_UC_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^
126+
-DICU_I18N_INCLUDE_DIRS="%swift_source_dir%/icu/include"^
127+
-DICU_I18N_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^
128+
-DICU_UC_LIB_NAME="icuuc"^
129+
-DICU_I18N_LIB_NAME="icuin"^
130+
-DSWIFT_INCLUDE_DOCS=FALSE^
131+
-DSWIFT_INCLUDE_TESTS=FALSE^
132+
-DSWIFT_BUILD_SDK_OVERLAY=FALSE^
133+
-DSWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER=FALSE^
134+
-DPYTHON_EXECUTABLE="python"
135+
popd
136+
cmake --build "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64/ninja"
137+
```
138+
139+
## Clang-cl
140+
141+
Follow the instructions for MSVC, but add the following lines to each CMake configuration command. We need to use LLVM's `lld-link.exe` linker, as MSVC's `link.exe` crashes due to corrupt PDB files using `clang-cl`. `Clang-cl` 3.9.0 has been tested.
142+
143+
```
144+
-DCMAKE_C_COMPILER="<path-to-llvm-bin>/clang-cl.exe"^
145+
-DCMAKE_CXX_COMPILER="<path-to-llvm-bin>/bin/clang-cl.exe"^
146+
-DCMAKE_LINKER="<path-to-llvm-bin>/lld-link.exe"^
147+
```
148+
42149

43150
## Windows Subsystem for Linux (WSL)
44151
- Note that all compiled Swift binaries are only executable within Bash on Windows and are Ubuntu, not Windows, executables.

0 commit comments

Comments
 (0)