Skip to content

Commit 283367c

Browse files
Add some documentation on the Windows compiler flags (#755)
1 parent 1192385 commit 283367c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Windows Platform
2+
3+
In most cases, the clang and swift compilers will automatically detect the requisite components installed on the system by searching the environment and/or registry. However, Swift Build contains its own lookup logic and explicitly passes paths and versions of dependencies to the compiler in order to have more direct control over the build process and version selection.
4+
5+
## System Requirements
6+
7+
There are a number of components required for building for Windows...
8+
9+
### Visual C++
10+
11+
The most basic requirement is the Visual C++ compiler and runtime. To get this, you must install any edition of Visual Studio (Build Tools, Community, Professional, Enterprise). The Visual Studio installer also places a tool called vswhere at the fixed location of `%PROGRAMFILES(X86)%\Microsoft Visual Studio\Installer\vswhere.exe`, which Swift Build uses to look up the Visual Studio installations on the system, and their properties.
12+
13+
### Windows SDK
14+
15+
The Windows SDK is also required for accessing the Windows API, and can also be installed via the Visual Studio installer.
16+
17+
## Lookup Process
18+
19+
First the compiler must find the Visual C++ toolchain via a combination of environment variables and/or command line flags. Note that this documentation is only concerned with the "modern" toolchain layout in Visual Studio 2017 and later versions.
20+
21+
The following table is a state machine for clang's search path logic for the VC tools install dir. The environment variable fallback will also search the PATH, and then ISetupConfig, and then the registry, details of which are not covered here. See https://github.com/swiftlang/llvm-project/blob/next/clang/docs/UsersManual.rst#windows-system-headers-and-library-lookup for more.
22+
23+
| -Xmicrosoft-windows-sys-root | -Xmicrosoft-visualc-tools-version | -Xmicrosoft-visualc-tools-root | Value |
24+
| ---------------------------- | --------------------------------- | ------------------------------ | ---------------------------------------------------------- |
25+
| Yes | Yes | - | `%windows-sys-root%\VC\Tools\MSVC\%visualc-tools-version%` |
26+
| Yes | No | - | `%windows-sys-root%\VC\Tools\MSVC\<latest>` |
27+
| No | - | Yes | `%visualc-tools-root%` |
28+
| No | - | No | environment variable `VCToolsInstallDir` |
29+
30+
### Examples
31+
32+
Example values that can be given to various Swift compiler options:
33+
34+
| Flag | Example value |
35+
| ---------------------- | ------------------------------------------------------------------------------------------- |
36+
| -sdk | `%LOCALAPPDATA%\Programs\Swift\Platforms\6.1.0\Windows.platform\Developer\SDKs\Windows.sdk` |
37+
| -windows-sdk-root | `%PROGRAMFILES(X86)%\Windows Kits\10\10.0.26100.0` |
38+
| -windows-sdk-version | `10.0.26100.0` |
39+
| -visualc-tools-root | `%PROGRAMFILES%\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207` |
40+
| -visualc-tools-version | `14.44.35207` |
41+
42+
Example values that can be given to various clang compiler options:
43+
44+
| Flag | Example value |
45+
| --------------------------------- | --------------------------------------------------------------------------------- |
46+
| -Xmicrosoft-windows-sdk-root | `%PROGRAMFILES(X86)%\Windows Kits\10\10.0.26100.0` |
47+
| -Xmicrosoft-windows-sdk-version | `10.0.26100.0` |
48+
| -Xmicrosoft-visualc-tools-root | `%PROGRAMFILES%\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207` |
49+
| -Xmicrosoft-visualc-tools-version | `14.44.35207` |
50+
| -Xmicrosoft-windows-sys-root | `%PROGRAMFILES%\Microsoft Visual Studio\2022\Community` |
51+
52+
Example values for relevant environment variables:
53+
54+
| Environment variable | Example value |
55+
| -------------------- | ----------------------------------------------------------------------------------- |
56+
| VCToolsInstallDir | `C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207` |

0 commit comments

Comments
 (0)