Skip to content

Enable CMake policy CMP0157 in the toolchain's Swift projects #93995

Open

Description

@charles-zablit

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.json lists 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 pass CMAKE_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 made swift-format lint 34% 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

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

  1. finagolfin commented on Nov 5, 2026

    @finagolfin
    Member

    Would it be possible to update all these to a minimum of CMake 3.29 instead, @etcwilde and @speednoisemovement?

  2. etcwilde commented on Nov 5, 2026

    @etcwilde
    Member

    Would it be possible to update all these to a minimum of CMake 3.29 instead

    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>.swiftmodule to 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.

  3. compnerd commented on Nov 5, 2026

    @compnerd
    Member

    Yeah, this definitely should be handled by bumping the CMake minimum version. Additionally, the CMAKE_Swift_COMPILATION_MODE should be pushed to the configuration layer, not into CMake.

  4. charles-zablit commented on Nov 6, 2026

    @charles-zablit
    ContributorAuthor

    I'm testing the new changes locally and updating all the patches. Should be done in ~2h.

  5. finagolfin commented on Nov 6, 2026

    @finagolfin
    Member

    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...

  6. charles-zablit commented on Nov 6, 2026

    @charles-zablit
    ContributorAuthor

    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...

    Let's wait before updating xctest then.

  7. etcwilde commented on Nov 6, 2026

    @etcwilde
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions