Skip to content

Commit 5566c75

Browse files
committed
docs: describe how to use Xcode together with ninja
1 parent c9d9226 commit 5566c75

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/DevelopmentTips.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,27 @@ For example, to have `build-script` spawn only one link job at a time, we can in
6565
```
6666
build-script --llvm-cmake-options==-DLLVM_PARALLEL_LINK_JOBS=1 --swift-cmake-options=-DSWIFT_PARALLEL_LINK_JOBS=1
6767
```
68+
69+
## Using ninja with Xcode
70+
71+
Although it's possible to build the swift compiler entirely with Xcode (`--xcode`), often it's better to build with _ninja_ and use Xcode for editing and debugging.
72+
This is very convenient because you get the benefits of the ninja build system and all the benefits of the Xcode IDE, like code completion, refactoring, debugging, etc.
73+
74+
To setup this environment a few steps are necessary:
75+
* Create a new workspace.
76+
* Create Xcode projects for LLVM and Swift with `utils/build-script --skip-build --xcode --skip-early-swift-driver`. Beside configuring, this needs to build a few LLVM files which are need to configure the swift project.
77+
* Add the generated LLVM and Swift projects to your workspace. They can be found in the build directories `build/Xcode-DebugAssert/llvm-macosx-x86_64/LLVM.xcodeproj` and `build/Xcode-DebugAssert/swift-macosx-x86_64/Swift.xcodeproj`.
78+
* Add the `swift/SwiftCompilerSources` package to the workspace.
79+
* Create a new empty project `build-targets` (or however you want to name it) in the workspace, using the "External Build System" template.
80+
* For each compiler tool you want to build (`swift-frontend`, `sil-opt`, etc.), add an "External Build System" target to the `build-targets` project.
81+
* In the "Info" section of the target configuration, set
82+
* the _Build Tool_ to the full path of the `ninja` command
83+
* the _Argument_ to the tool name (e.g. `swift-frontend`)
84+
* the _Directory_ to the ninja swift build directory, e.g. `/absolute/path/to/build/Ninja-DebugAssert/swift-macosx-x86_64`. For debugging to work, this has to be a debug build of course.
85+
* For each target, create a new scheme:
86+
* In the _Build_ section add the corresponding build target what you created before.
87+
* In the _Run/Info_ section select the built _Executable_ in the build directory (e.g. `/absolute/path/to/build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swift-frontend`).
88+
* In the _Run/Arguments_ section you can set the command line arguments with which you want to run the compiler tool.
89+
* In the _Run/Options_ section you can set the working directory for debugging.
90+
91+
Now you are all set. You can build and debug like with a native Xcode project.

0 commit comments

Comments
 (0)