An unofficial guide to building the Swift toolchain on Windows (x64 and ARM64)

Introduction

This is an unofficial guide on how to build Swift on Windows (x64 and/or ARM64). Its main goal is to provide the exact versions for the tools used by the CI bots to build the Swift toolchain on Windows.

Windows configuration

Symbolic link creation permissions

Symbolic links are used in some of swift repositories. You need to grant permission to your user to create symbolic links in order to properly clone the repositories:

Using gpedit.msc add your user to the list of trusted user in Computer Configuration\Windows Settings\Security Settings\Local Policies\User Rights Assignment\Create Symbolic links.

Please make sure to consider the security risks listed here.

Requirements

The following are required to build the Swift toolchain on Windows. For each of the following, make sure to download the architecture which matches the system you are building on. See the Notes section for more details.

Visual Studio Community 2022

Download the Visual Studio Community 2022 installer from the Microsoft website. Once downloaded, run it and select the Desktop development with C++ workload. Then, select the following in the Individual Components tab (ensure that the versions match):

  • .NET 9.0 Runtime
  • MSVC v143 - VS 2022 C++ ARM build tools (v14.42-17.12)
  • MSVC v143 - VS 2022 C++ ARM Spectre-mitigated libs (v14.42-17.12)
  • MSVC v143 - VS 2022 C++ ARM64/ARM64EC build tools (v14.42-17.12)
  • MSVC v143 - VS 2022 C++ x64/x86 build tools (v14.42-17.12)
  • MSVC v143 - VS 2022 C++ x64/x86 Spectre-mitigated libs (v14.42-17.12)
  • C++ v14.42 (17.12) ATL for v143 build tools (ARM)
  • C++ v14.42 (17.12) ATL for v143 build tools (ARM64)
  • C++ v14.42 (17.12) ATL for v143 build tools (x86 & x64)
  • Windows 11 SDK (10.0.22621.0) If another version is installed, uninstall it

Note: You only need the x64/x86 components when building for x64/x86 and vice versa. You need everything if you are cross-compiling.

Cmake v3.29.2

Download and install Cmake v3.29.2 from the Github releases.

Ninja v1.13.1

Download and install Ninja v1.13.1 from the Github releases. Unzip the downloaded executable and add it to the PATH (you can do this by moving it to C:\Program Files\Cmake\bin.

Python v3.13.7

Python is only used to run update-checkout, which does not require any external module. If you have a version of Python installed on your system that is more recent than v3.7, you can skip this step.

Download and install Python v3.13.7 from the Python website. During the installation process, make sure to click on the option to add Python to the PATH.

Git v2.51.0

Any recent version of Git should work. Just make sure that symbolic links are enabled. If you already have Git on your system, run git config --global core.symlinks true to enable symbolic links globally.

Download and install Git v2.51.0 from the official website. During the installation process, make sure to click on the option to add Python to the PATH and to enable symbolic links.

Disable automatic line endings conversion to support all the test suite: git config --global --add core.autocrlf false

Starting the build

  1. Open a regular (non admin, not Visual Studio) Powershell shell.
  2. Create a directory named S at the root of the C:\ drive: mkdir C:\S.
  3. Navigate to that directory cd C:\S.
  4. Clone the Swift repository: git clone https://github.com/swiftlang/swift.git.
  5. Navigate into the repository: cd swift.
  6. Switch to the branch you want to build: git checkout release/6.2.
  7. Clone the rest of the repositories: .\utils\update-checkout --scheme release/6.2 --reset-to-remote --skip-repository swift.
  8. Set the SKIP_UPDATE_CHECKOUT environment variable to true to avoid cloning the repositories again: $env:SKIP_UPDATE_CHECKOUT="true".
  9. Start the build: .\utils\build-windows-toolchain.bat.

Notes

General

  • Building with -DebugInfo requires ~64GB of Ram with at least the same amount of swap space available. Lowering the value of SWIFT_PARALLEL_LINK_JOBS should help to bring that requirement down at the cost of an increase in build time.

When building on ARM64

  • Be careful when using package managers, as they might install the wrong architecture of the program. For instance choco install cmake.install --version=3.13.7 will install the x64 version of Cmake on your ARM64 VM, which will cause x64 MSVC to be picked and run through WOW64 emulation, causing build failures.

  • It is currently not possible to build the release/6.2 toolchain on ARM64 Windows without 82367 and 83421. Cross compiling from x64 works.

Other resources

  • This guide also has up to date instructions on how to build the toolchain on Windows.
  • You can refer to the versions of the tooling this bot is using for the most up to date tools that are used to build Swift on Windows.
6 Likes

This info would be more accessible on github or swift.org.

I would like to eventually update the official documentation on Github. I am waiting for some eventual feedback on this post to adjust the instructions before doing so.

2 Likes

I don’t think that this holds anymore. My last attempt at this with reduced SWIFT_PARALLEL_LINK_JOBS seems to indicate 96G as the water mark.

2 Likes

I should add that -CDebugFormat dwarf is currently pointless - LLDB makes debugging impossible as the binary is >4G which prevents us from linking. As such, if you wish to have debug info, you need to use CodeView. Given the increasing amount of Swift in the toolchain, this means that you would need to use -SwiftDebugFormat codeview and generate PDBs to get anything meaningful from debugging.

2 Likes