Skip to content

Instantly share code, notes, and snippets.

@heckj
Created July 22, 2024 21:05
Show Gist options
  • Save heckj/daa539cb48f816e2866e5119880b68dd to your computer and use it in GitHub Desktop.
Save heckj/daa539cb48f816e2866e5119880b68dd to your computer and use it in GitHub Desktop.

Swift Project

cd ~/src/swift-project/swift
./utils/update-checkout --clone-with-ssh --clean

Base build

sccache --start-server
utils/build-script --skip-build-benchmarks \
    --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
    --sccache --release-debuginfo --swift-disable-dead-stripping \
    --bootstrapping=hosttools --clean

^^ give this 60+ minutes for a from-start build on an M1 Macbook Pro:

Build Percentage 	 Build Duration (sec) 	 Build Phase
================ 	 ==================== 	 ===========
60.1%             	 2297.32               	 Building llvm
37.4%             	 1429.24               	 macosx-arm64-swift-build
2.2%              	 85.63                 	 Building earlyswiftdriver
0.2%              	 8.33                  	 Building cmark
0.0%              	 0.07                  	 macosx-arm64-swift-test
0.0%              	 0.06                  	 macosx-arm64-swift-install
0.0%              	 0.04                  	 merged-hosts-lipo-core
0.0%              	 0.04                  	 macosx-arm64-extractsymbols
0.0%              	 0.04                  	 macosx-arm64-package
0.0%              	 0.04                  	 merged-hosts-lipo

incremental compiler rebuild (for swift-frontend)

cd ~/src/swift-project
export platform=$([[ $(uname) == Darwin ]] && echo macosx || echo linux)
ninja -C build/Ninja-RelWithDebInfoAssert/swift-${platform}-$(uname -m) bin/swift-frontend

incremental rebuild (all)

cd ~/src/swift-project
export platform=$([[ $(uname) == Darwin ]] && echo macosx || echo linux)
ninja -C build/Ninja-RelWithDebInfoAssert/swift-${platform}-$(uname -m)

Set up Xcode project for development

  1. Clone and run update-checkout.
  2. Run swift/utils/build-script --release-debuginfo --xcode. [Add a --debug-swift to get better debugging info for the compiler itself. Other dependencies like LLVM will have debug info but will have more optimizations applied with --release-debuginfo.]. This will create an xcodeproj under build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64.
  3. Open the Xcode project and under schemes, do "Manually manage schemes" and select ALL_BUILD as well as swift (this list is very long so you'll have to scroll a bit).
  4. Build normal using Cmd+B inside Xcode to double-check that it works.
  5. Check out a new branch and make your changes.
  6. Run tests using lit on the commandline. I recommend using something like
llvm-project/llvm/utils/lit/lit.py -s -vv build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/test-macosx-x86_64 --filter "myTestName". There are some test targets which you can run from inside Xcode, but I usually use lit because you can change the flags. I highly recommend using -vv, regardless of what you do, so that you get to see which line in a multi-line test failed.
  7. Your test passes yay! Now remove the --filter and make sure you didn't break anything else.
  8. Submit a PR and @ someone, probably someone who is helping you make the change.
utils/build-script --skip-build-benchmarks \
    --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
    --sccache --release-debuginfo --swift-disable-dead-stripping \
    --bootstrapping=hosttools --clean

^^ roughly 10 minutes of setup time to enable this (with sccache enabled)

project at: ~/src/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-arm64/Swift.xcodeproj https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md#using-ninja-with-xcode

Reset with a new first step:

cd ~/src/swift-project/swift
utils/build-script --skip-build-benchmarks \
--skip-ios --skip-watchos --skip-tvos \
--swift-darwin-supported-archs "$(uname -m)" \
--sccache --release-debuginfo \
--swift-disable-dead-stripping \
--xcode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment