Since SwiftSyntax relies on definitions in the main Swift repository to generate the layout of the syntax tree using gyb, a checkout of apple/swift is still required to build the latest development snapshot of SwiftSyntax.
To build the main branch of SwiftSyntax, follow the following instructions:
-
Check
swift-syntaxandswiftout side by side:- (enclosing directory) - swift - swift-syntax -
Make sure you have a recent Trunk Swift Toolchain installed.
-
Define the
TOOLCHAINSenvironment variable as below to have theswiftcommand point inside the toolchain:$ export TOOLCHAINS=swift -
To make sure everything is set up correctly, check the return statement of
xcrun --find swift. It should point inside the latest installed trunk development toolchain. If it points inside an Xcode toolchain, check that you exported theTOOLCHAINSenvironment variable correctly. If it points inside a version-specific toolchain (like Swift 5.0-dev), you'll need to remove that toolchain. -
Run
swift-syntax/build-script.py build --toolchain /path/to/recent/swift/development/snapshot.xctoolchain/usr. If despite following those instructions, you get compiler errors, the Swift toolchain might be too old to contain recent changes in Swift's SwiftSyntaxParser C library. In that case, you'll have to build the compiler and SwiftSyntax together with the following command:$ swift/utils/build-script --swiftsyntax --swiftpm --llbuild
Swift-CI will automatically run the code generation step whenever a new toolchain (development snapshot or release) is published. It should thus almost never be necessary to perform the above build yourself.
Afterward, SwiftPM can also generate an Xcode project to develop SwiftSyntax by running swift package generate-xcodeproj.
If you also want to run tests locally, read the section below as testing has additional requirements.
SwiftSyntax uses some test utilities that need to be built as part of the Swift compiler project. To build the most recent version of SwiftSyntax and test it, follow the steps in swift/README.md and pass --llbuild --swiftpm --swiftsyntax to the build script invocation to build SwiftSyntax and all its dependencies using the current trunk (main) compiler.
SwiftSyntax can then be tested using the build script in apple/swift by running
swift/utils/build-script --swiftsyntax --swiftpm --llbuild -t --skip-test-cmark --skip-test-swift --skip-test-llbuild --skip-test-swiftpmThis command will build SwiftSyntax and all its dependencies, tell the build script to run tests, but skip all tests but the SwiftSyntax tests.
Note that it is not currently supported by SwiftSyntax while building the Swift compiler using Xcode.
Running @swift-ci Please test on the main Swift repository will also test the most recent version of SwiftSyntax.
Testing SwiftSyntax from its own repository is now available by commenting @swift-ci Please test macOS platform.