The current CMake Xcode project generation for the Swift repo (build-script --xcode) leaves a lot to be desired. It’s not entirely trivial to setup properly, has a cumbersome project layout, and is quite fragile because it’s so different from the Ninja builds tested via CI. It can be a pretty big barrier to working on the Swift compiler itself.
To make it easier to use Xcode to develop the Swift compiler, I wrote a tool (swift-xcodegen) that generates Xcode projects for the Swift repo, as well as a couple of adjacent repos such as LLVM and Clang. This uses an existing Ninja build of Swift to quickly generate an Xcode project that is fully setup for editing/debugging, and automatically includes compiler libraries written in Swift such as ASTGen and SwiftCompilerSources. For more information, check out the updated Getting Started guide, as well as the swift-xcodegen documentation.
Please give it a try and let me know how you get on!
this is very exciting! personally i've found the code editing experience differences between 'vanilla' iOS development and Swift compiler development to be a fairly significant barrier to contributing, so improvements to the Xcode-based development experience are very welcome. i'm looking forward to trying out the new tool, and thank you for working on this!
I have not had a chance to try this yet, but thank you for this effort @hamishknight!
Ever since Swift has become open source I have periodically tried following the published directions of developing Swift using Xcode and I have never had success doing so.
Having a reliable solution for editing and debugging these projects in Xcode will be a significant improvement in the contributor experience.
having had a chance now to try this, i'll share some initial thoughts:
wow is it fast! overall, the setup was straightforward and everything seemed to basically 'just work'. indexing did seem to take a while to finish after project generation, but maybe that's inevitable.
after i first generated a project i immediately started trying to find some swift stdlib types, and was confused why 'open quickly' wasn't able to locate them. after inspecting the --help a bit more, it appeared it was because the --stdlib-swift option isn't enabled by default. the help text for that option currently says:
Generate targets for Swift files in the standard library. This requires using Xcode with a main development snapshot (and as such is disabled by default). (default: --no-stdlib-swift)
which i find confusing as i don't believe i have a main development snapshot, and when i re-ran the tool with that flag set, the swift sources appeared to show up.
i'm curious to better understand what the requirements/limitations there are, as i would assume potential contributors may often be interested in the swift stdlib components in particular.
There are quite a lot of source files in the project (~1900 excluding --swift-stdlib, ~2400 including), so this isn't entirely surprising unfortunately. IIRC last time I timed it, the initial index took ~6-7 minutes to build. Are you seeing a significantly longer indexing time?
The files will show up, but may not build correctly (i.e you may get spurious live issues and build errors). This is because in the CMake build, the stdlib is built using the just-built Swift compiler, so it is able to use Swift features that may not yet be available in the Swift toolchain in Xcode. As such, it's advisable to use Xcode with a main development Swift snapshot, since that'll more closely match the Swift version the stdlib is normally built with. I can update the help text to clarify this.