Build the Swift Toolchain Locally and Xcode Integration

Hi everyone,

I’m interested in contributing to Swift by working on the local refactoring functionality and need some guidance on building the Swift toolchain locally and integrating it with Xcode.

I’ve reviewed the Swift Contribution Guide, but I still have a couple of questions:

  1. What script should I use to build a local toolchain?
  2. How can I integrate the built toolchain with Xcode to test my changes?

Thank you!

Great to hear that you’re interested in contributing.

The way I recently tested a local toolchain build in Xcode is the following (there might be other ways, but this has worked for me):

  • Add the following parameters to my build-script invocation: --install-swift --install-llvm --install-destdir build/toolchain
  • Create an Info.plist in XcodeDefault.xctoolchain with contents like below
  • Copy XcodeDefault.xctoolchain to /Library/Developer/Toolchains (I don’t remember whether I needed to rename it from XcodeDefault.xctoolchain to eg. LocalToolchain.xctoolchain or not.
  • Relaunch Xcode
  • Select the local toolchain from Xcode -> Toolchains

During development, I usually find it easier to write test cases and develop against them instead of testing inside Xcode, though (see swift/test/refactoring at main · swiftlang/swift · GitHub for examples). And then only verify that everything works as expected once I’m happy with the test cases.

Info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Aliases</key>
	<array>
		<string>swift</string>
	</array>
	<key>CFBundleIdentifier</key>
	<string>org.swift.local</string>
	<key>CompatibilityVersion</key>
	<integer>2</integer>
	<key>CompatibilityVersionDisplayString</key>
	<string>Xcode 8.0</string>
	<key>CreatedDate</key>
	<date>2024-10-09T21:26:03Z</date>
	<key>DisplayName</key>
	<string>Swift Local</string>
	<key>OverrideBuildSettings</key>
	<dict>
		<key>ENABLE_BITCODE</key>
		<string>NO</string>
		<key>OTHER_SWIFT_FLAGS</key>
		<string>$(inherited) -plugin-path $(TOOLCHAIN_DIR)/usr/lib/swift/host/plugins</string>
		<key>SWIFT_DEVELOPMENT_TOOLCHAIN</key>
		<string>YES</string>
		<key>SWIFT_DISABLE_REQUIRED_ARCLITE</key>
		<string>YES</string>
		<key>SWIFT_LINK_OBJC_RUNTIME</key>
		<string>YES</string>
		<key>SWIFT_USE_DEVELOPMENT_TOOLCHAIN_RUNTIME</key>
		<string>YES</string>
	</dict>
	<key>ReportProblemURL</key>
	<string>https://bugs.swift.org/</string>
	<key>ShortDisplayName</key>
	<string>Swift Local</string>
	<key>Version</key>
	<string>6.1.9999</string>
</dict>
</plist>

2 Likes

If the goal is to test the changes in a Xcode project there's also the SWIFT_EXEC environment variable:

1 Like

Hey Alex and Mateus,

Thank you both for your responses! I’ll try out the approaches you’ve mentioned and follow up if I run into any issues. Appreciate the guidance and suggestions!