Repository navigation
Description
CMP0157 controls how CMake's Ninja generator builds Swift. With the old behavior, each Swift target is one step that compiles and links, and outputs the compiler leaves untouched keep a target and everything depending on it dirty (AddPureSwift.cmake works around this for swift-syntax). With the new behavior, each module compiles in its own step, separate from the link. swift-syntax, swiftpm, swift-build, Foundation, swift-testing and libdispatch already use it; the PRs below switch the remaining projects by requiring CMake 3.29, which the toolchain build already needs for swift-syntax.
Gains
- A rebuild that leaves a module's outputs unchanged no longer cascades into its dependents.
compile_commands.jsonlists the Swift sources.- One build model across the toolchain.
- Clean builds take the same time. Optimized configurations keep
-wmo, which the old behavior added and the new one doesn't: build.ps1 and build-script now passCMAKE_Swift_COMPILATION_MODE([build] Pass CMAKE_Swift_COMPILATION_MODE to the CMP0157 projects #94066, which should land first). On Windows, incremental Release built the tools 21% faster but madeswift-format lint34% slower.
Tested on Windows x64 with a full toolchain build and the lld, check-swift, check-lldb-swift, XCTest, Foundation, swift-format and SourceKit-LSP tests.
PRs
- [build] Pass CMAKE_Swift_COMPILATION_MODE to the CMP0157 projects #94066
- [CMake] Require CMake 3.29 for the compiler #93996
- [CMake] Require CMake 3.29 for swift-inspect #93997
- [update-checkout] Bump swift-crypto to 3.15.1 on main #93998
- [CMake] Require CMake 3.29 to enable CMP0157 swift-driver#2252
- [CMake] Require CMake 3.29 to enable CMP0157 sourcekit-lsp#2836
- [CMake] Require CMake 3.29 to enable CMP0157 swift-tools-support-core#584
- [CMake] Require CMake 3.29 to enable CMP0157 swift-llbuild#1065
- [CMake] Require CMake 3.29 to enable CMP0157 swift-format#1325
- [CMake] Require CMake 3.29 to enable CMP0157 swift-tools-protocols#93
- [CMake] Require CMake 3.29 to enable CMP0157 indexstore-db#307
- [CMake] Require CMake 3.29 to enable CMP0157 swift-corelibs-xctest#562
- [CMake] Require CMake 3.29 to enable CMP0157 swift-docc#1725
- [CMake] Require CMake 3.29 to enable CMP0157 swift-llvm-bindings#42
- [CMake] Require CMake 3.29 to enable CMP0157 apple/swift-argument-parser#1001
- [CMake] Enable CMP0157 and keep whole-module builds for optimized configs apple/swift-collections#826
- [CMake] Require CMake 3.29 and drop the CMP0157 checks apple/swift-collections#842
- [CMake] Require CMake 3.29 to enable CMP0157 apple/swift-system#417
- [CMake] Enable CMP0157 and keep whole-module builds for optimized configs apple/swift-asn1#139
- [CMake] Require CMake 3.29 and drop the CMP0157 checks apple/swift-asn1#140
- [CMake] Enable CMP0157 and keep whole-module builds for optimized configs apple/swift-certificates#324
- [CMake] Require CMake 3.29 and drop the CMP0157 checks apple/swift-certificates#325
- [CMake] Require CMake 3.29 to enable CMP0157 apple/swift-numerics#362
- [CMake] Require CMake 3.29 to enable CMP0157 apple/swift-atomics#137
- [CMake] Enable CMP0157 swiftwasm/WasmKit#519
- [CMake] Require CMake 3.29 and drop the CMP0157 checks swiftwasm/WasmKit#521
The toolchain pins swift-argument-parser, swift-collections, swift-system, swift-asn1, swift-certificates, swift-numerics, swift-atomics and WasmKit to tags, so those changes take effect after a release and an update-checkout bump.
CMP0195 (CMake 4.1) would let the projects drop their hand-written -emit-module-path and swiftmodule install code; that needs a 4.1 minimum and is left for later.
assisted by Claude
Activity
finagolfin commentedon Nov 5, 2026
Would it be possible to update all these to a minimum of CMake 3.29 instead, @etcwilde and @speednoisemovement?
etcwilde commentedon Nov 5, 2026
Yes please. I've commented on a few of them. When doing bumps like this, please look through the repository and see if there are opportunities to leverage the new behavior to improve the code. Things like folks using flags to add
-emit-module-path <module name>.swiftmodule/<module triple>.swiftmoduleto get the nested module structure should enable CMP0195 and stop passing the explicit flags, which lead to the individual files not being tracked in the build graph properly.[CMake] Enable CMP0157 and keep whole-module builds for optimized con…
[CMake] Enable CMP0157 and keep whole-module builds for optimized con…
compnerd commentedon Nov 5, 2026
Yeah, this definitely should be handled by bumping the CMake minimum version. Additionally, the
CMAKE_Swift_COMPILATION_MODEshould be pushed to the configuration layer, not into CMake.charles-zablit commentedon Nov 6, 2026
I'm testing the new changes locally and updating all the patches. Should be done in ~2h.
finagolfin commentedon Nov 6, 2026
Some repos may break for Android because of #92684, I wonder if setting those few to a minimum of 3.28 would be a workaround for now? Unclear on how exactly these CMake policies are chosen and if we can thread the needle on that regression...
charles-zablit commentedon Nov 6, 2026
Let's wait before updating xctest then.
etcwilde commentedon Nov 6, 2026
3.29 introduced the new build model and should still work (though you have to remember to explicitly pass the link flags to the Swift compiler), but it should avoid #92684. If we can bump to at least 3.29, that would be great.