-
Notifications
You must be signed in to change notification settings - Fork 124
Add some documentation on the Windows compiler flags #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jakepetroules
merged 1 commit into
swiftlang:main
from
jakepetroules:eng/PR-windows-docs
Aug 29, 2025
+56
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Windows Platform | ||
|
||
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. | ||
|
||
## System Requirements | ||
|
||
There are a number of components required for building for Windows... | ||
|
||
### Visual C++ | ||
|
||
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. | ||
|
||
### Windows SDK | ||
|
||
The Windows SDK is also required for accessing the Windows API, and can also be installed via the Visual Studio installer. | ||
|
||
## Lookup Process | ||
|
||
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. | ||
|
||
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. | ||
|
||
| -Xmicrosoft-windows-sys-root | -Xmicrosoft-visualc-tools-version | -Xmicrosoft-visualc-tools-root | Value | | ||
| ---------------------------- | --------------------------------- | ------------------------------ | ---------------------------------------------------------- | | ||
| Yes | Yes | - | `%windows-sys-root%\VC\Tools\MSVC\%visualc-tools-version%` | | ||
| Yes | No | - | `%windows-sys-root%\VC\Tools\MSVC\<latest>` | | ||
| No | - | Yes | `%visualc-tools-root%` | | ||
| No | - | No | environment variable `VCToolsInstallDir` | | ||
|
||
### Examples | ||
|
||
Example values that can be given to various Swift compiler options: | ||
|
||
| Flag | Example value | | ||
| ---------------------- | ------------------------------------------------------------------------------------------- | | ||
| -sdk | `%LOCALAPPDATA%\Programs\Swift\Platforms\6.1.0\Windows.platform\Developer\SDKs\Windows.sdk` | | ||
| -windows-sdk-root | `%PROGRAMFILES(X86)%\Windows Kits\10\10.0.26100.0` | | ||
| -windows-sdk-version | `10.0.26100.0` | | ||
| -visualc-tools-root | `%PROGRAMFILES%\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207` | | ||
| -visualc-tools-version | `14.44.35207` | | ||
|
||
Example values that can be given to various clang compiler options: | ||
|
||
| Flag | Example value | | ||
| --------------------------------- | --------------------------------------------------------------------------------- | | ||
| -Xmicrosoft-windows-sdk-root | `%PROGRAMFILES(X86)%\Windows Kits\10\10.0.26100.0` | | ||
| -Xmicrosoft-windows-sdk-version | `10.0.26100.0` | | ||
| -Xmicrosoft-visualc-tools-root | `%PROGRAMFILES%\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207` | | ||
| -Xmicrosoft-visualc-tools-version | `14.44.35207` | | ||
| -Xmicrosoft-windows-sys-root | `%PROGRAMFILES%\Microsoft Visual Studio\2022\Community` | | ||
|
||
Example values for relevant environment variables: | ||
|
||
| Environment variable | Example value | | ||
| -------------------- | ----------------------------------------------------------------------------------- | | ||
| VCToolsInstallDir | `C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207` | |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.