Building Swift 6.3 on Windows

I’m attempting to build the Swift compiler on Windows to investigate some slow compilation times. -stats-output-dir has led me to discover that the slow compilation I’m facing is due to slow import resolution times of a large C header module (CWinRT), but I don’t think I can get much further without compiling a custom Swift compiler with a bit more logging.


I’ve followed the Windows build instructions in WindowsBuild.md with release/6.3 as my target, and I’ve hit the following error;

> S:\SourceCache\swift\utils\build.cmd -Windows

... (omitted)

C:\Program Files\CMake\bin\cmake.exe -B S:\b\x86_64-unknown-windows-msvc\BootstrapFoundationMacros -S S:\SourceCache\swift-foundation\Sources\FoundationMacros -G Ninja -D CMAKE_BUILD_TYPE=Release -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL:NO /OPT:REF /OPT:ICF -D CMAKE_FIND_PACKAGE_PREFER_CONFIG=YES -D CMAKE_MAKE_PROGRAM=C:/Users/rohan/AppData/Local/Microsoft/WinGet/Links/ninja.exe -D CMAKE_SHARED_LINKER_FLAGS=/INCREMENTAL:NO /OPT:REF /OPT:ICF -D CMAKE_Swift_COMPILER=S:/b/toolchains/DEVELOPMENT-SNAPSHOT-2025-12-01-a/LocalApp/Programs/Swift/Toolchains/0.0.0+Asserts/usr/bin/swiftc.exe -D CMAKE_Swift_COMPILER_TARGET=x86_64-unknown-windows-msvc -D CMAKE_Swift_FLAGS=-sdk S:/b/toolchains/DEVELOPMENT-SNAPSHOT-2025-12-01-a/LocalApp/Programs/Swift/Platforms/0.0.0/Windows.platform/Developer/SDKs/Windows.sdk -gnone -Xlinker /INCREMENTAL:NO -Xlinker /OPT:REF -Xlinker /OPT:ICF -D CMAKE_Swift_FLAGS_RELEASE=-O -D CMAKE_Swift_FLAGS_RELWITHDEBINFO=-O -D SwiftSyntax_DIR=S:/b/5/cmake/modules
-- The Swift compiler identification is Apple 6.3
-- Check for working Swift compiler: S:/b/toolchains/DEVELOPMENT-SNAPSHOT-2025-12-01-a/LocalApp/Programs/Swift/Toolchains/0.0.0+Asserts/usr/bin/swiftc.exe
-- Check for working Swift compiler: S:/b/toolchains/DEVELOPMENT-SNAPSHOT-2025-12-01-a/LocalApp/Programs/Swift/Toolchains/0.0.0+Asserts/usr/bin/swiftc.exe - works
-- SwiftSyntax_DIR provided, using swift-syntax from S:/b/5/cmake/modules
-- Configuring done (1.8s)
-- Generating done (0.0s)
-- Build files have been written to: S:/b/x86_64-unknown-windows-msvc/BootstrapFoundationMacros

... (omitted)

[2/2] Linking Swift shared library bin\FoundationMacros.dll
FAILED: [code=1] bin/FoundationMacros.dll lib/FoundationMacros.lib
C:\Windows\system32\cmd.exe /C "cd . && S:\b\toolchains\DEVELOPMENT-SNAPSHOT-2025-12-01-a\LocalApp\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swiftc.exe -target x86_64-unknown-windows-msvc -j 12 -num-threads 12 -emit-library -sdk S:/b/toolchains/DEVELOPMENT-SNAPSHOT-2025-12-01-a/LocalApp/Programs/Swift/Platforms/0.0.0/Windows.platform/Developer/SDKs/Windows.sdk -gnone -Xlinker /INCREMENTAL:NO -Xlinker /OPT:REF -Xlinker /OPT:ICF -O  /INCREMENTAL:NO /OPT:REF /OPT:ICF -Xlinker -implib:lib\FoundationMacros.lib   -o bin\FoundationMacros.dll CMakeFiles\FoundationMacros.dir\FoundationMacros.swift.obj CMakeFiles\FoundationMacros.dir\BundleMacro.swift.obj CMakeFiles\FoundationMacros.dir\PredicateMacro.swift.obj -L S:\b\5\lib\swift\host  -L S:\b\5\lib\swift\host  -L S:\b\5\lib\swift\host  -L S:\b\5\lib\swift\host  -L S:\b\5\lib\swift\host  -L S:\b\5\lib\swift\host  -L S:\b\5\lib\swift\host  -L S:\b\5\lib\swift\host  -L S:\b\5\lib\swift\host S:\b\5\lib\swift\host\SwiftSyntax.lib  S:\b\5\lib\swift\host\SwiftSyntaxMacros.lib  S:\b\5\lib\swift\host\SwiftDiagnostics.lib  S:\b\5\lib\swift\host\SwiftSyntaxBuilder.lib  S:\b\5\lib\swift\host\SwiftIfConfig.lib  S:\b\5\lib\swift\host\SwiftParserDiagnostics.lib  S:\b\5\lib\swift\host\SwiftBasicFormat.lib  S:\b\5\lib\swift\host\SwiftOperators.lib  S:\b\5\lib\swift\host\SwiftParser.lib && cd ."
clang: error: no such file or directory: '\INCREMENTAL:NO'
clang: error: no such file or directory: '\OPT:REF'
clang: error: no such file or directory: '\OPT:ICF'
ninja: build stopped: subcommand failed.
Error: Error: cmake.exe exited with code 1.
Invocation:
  C:\Program Files\CMake\bin\cmake.exe --build S:\b\x86_64-unknown-windows-msvc\BootstrapFoundationMacros
Call stack:
  at Invoke-Program, S:\SourceCache\swift\utils\build.ps1: line 1087
  at <ScriptBlock>, S:\SourceCache\swift\utils\build.ps1: line 1981
  at Invoke-IsolatingEnvVars, S:\SourceCache\swift\utils\build.ps1: line 1106
  at Build-CMakeProject, S:\SourceCache\swift\utils\build.ps1: line 1563
  at <ScriptBlock>, S:\SourceCache\swift\utils\build.ps1: line 4283

    at Invoke-Program, S:\SourceCache\swift\utils\build.ps1: line 1091
    at <ScriptBlock>, S:\SourceCache\swift\utils\build.ps1: line 1981
    at Invoke-IsolatingEnvVars, S:\SourceCache\swift\utils\build.ps1: line 1106
    at Build-CMakeProject, S:\SourceCache\swift\utils\build.ps1: line 1563
    at <ScriptBlock>, S:\SourceCache\swift\utils\build.ps1: line 4283
  From System.Management.Automation.RuntimeException: Error: cmake.exe exited with code 1.
  Invocation:
    C:\Program Files\CMake\bin\cmake.exe --build S:\b\x86_64-unknown-windows-msvc\BootstrapFoundationMacros
  Call stack:
    at Invoke-Program, S:\SourceCache\swift\utils\build.ps1: line 1087
    at <ScriptBlock>, S:\SourceCache\swift\utils\build.ps1: line 1981
    at Invoke-IsolatingEnvVars, S:\SourceCache\swift\utils\build.ps1: line 1106
    at Build-CMakeProject, S:\SourceCache\swift\utils\build.ps1: line 1563
    at <ScriptBlock>, S:\SourceCache\swift\utils\build.ps1: line 4283

The important part appears to be;

clang: error: no such file or directory: '\INCREMENTAL:NO'
clang: error: no such file or directory: '\OPT:REF'
clang: error: no such file or directory: '\OPT:ICF'

And those errors seem to be caused by something passing -D CMAKE_SHARED_LINKER_FLAGS=/INCREMENTAL:NO /OPT:REF /OPT:ICF to cmake (clearly expecting the Windows linker to be invoked instead of the clang).

Is this a known issue? I’m completely new to compiling the Swift toolchain, so I don’t really have a good intuition for what possible environment misconfigurations could be causing this. On top of that, I only touch Windows when I have to.


Alternative route

I do at least have the Swift compiler itself compiled by the time that error occurs during toolchain compilation, so if I can get that compiler working with my existing SwiftPM installation, I should be good to go. Unfortunately when I use SWIFT_EXEC=path/to/my/new/swiftc.exe along with my existing SwiftPM installation I get the following error;

error: InternalError(description: "Internal error. Please file a bug at https://github.com/swiftlang/swift-package-manager/issues with this info. Failed to parse target info (malformed(json: \"\", underlyingError: Error Domain=NSCocoaErrorDomain Code=3840 \"The data is not in the correct format.\"UserInfo={NSDebugDescription=Unexpected end of file during JSON parse.})).\nRaw compiler output: ")

That’s with -v as well, so it seems like SwiftPM doesn’t want to give up much more info than that.

My SwiftPM version is swift-6.3-DEVELOPMENT-SNAPSHOT-2026-01-16-a, and I’ve compiled the compiler off release/6.3.

Am I missing any steps to get a custom Swift compiler build working with an official SwiftPM build on Windows?

I have never built Swift on Windows, but have had occasion to tinker with the Windows CI. I suggest that you try the batch file invoked by the Windows trunk snapshot toolchain CI instead, which may be more up to date.

The batch file is not helpful - it’s just a wrapper.

The issue here is the CMake version. Please use CMake 3.28 I think? There’s a pending change that will unblock newer CMake versions.

2 Likes

utils: Support multiple CMake versions in build.ps1 by Steelskin · Pull Request #84631 · swiftlang/swift · GitHub is the pending PR BTW

1 Like

Thank you so much! That resolved the issue. I should’ve double checked my versions after running the winget commands :man_facepalming:

Now to find a parallelism value that doesn’t run out of my memory in my VM… (my desktop has 64gb of ram, but from other forums posts it seems like I’d need closer to 96gb with the default parallelism, we’ll see)

I build regularly with 64G of RAM. If you are building without DebugInfo, it should be much less constrained.

1 Like

Successfully built the full toolchain, thanks for your help!

For anyone coming across this in future, the full toolchain build took around 20gb of RAM max as far as I could tell by occasionally checking the task manager graph on my other screen, but I allocated 48gb RAM to my VM just in case, so it may have spiked higher than 20gb momentarily.

You're welcome!

Sounds like you did the default build (without Debug Info).

1 Like