How to use SourceKit-LSP to develop the Swift compiler repo?

Since it's getting hearts, here's an update since the post above: CMake 3.29 and newer knows how to generate the compile commands for Swift now.
Verify that either

  • The cmake_minimum_required is 3.29 or newer
  • Or that you have set CMP0157 to NEW when it's available after the cmake_minimum_required call.
    e.g.
cmake_minimum_required(VERSION 3.26)
...
if(POLICY CMP0157)
  cmake_policy(SET CMP0157 NEW)
endif()

Just like with C/C++, CMake will generate a compile_commands.json file that you can symlink into your workspace and SourceKit-LSP should pick it up.

This mode did involve re-writing how CMake models Swift builds, so there are some things to check. Namely that you're using the CMAKE_Swift_COMPILATION_MODE to make a target use whole-module optimizations instead of passing the -wmo flag independently. Otherwise, it should mostly just work.

For more info on improvements for Swift in 3.29: Updates for Swift in the upcoming CMake 3.29

Now just need to update the compiler repo to actually take advantage of the new features. :)

2 Likes