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?