Skip to content

Commit 7c84923

Browse files
committed
[docs] Move instructions for using Ninja with Xcode to GettingStarted.md
1 parent 7532e1d commit 7c84923

File tree

2 files changed

+77
-79
lines changed

2 files changed

+77
-79
lines changed

docs/DevelopmentTips.md

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -99,79 +99,3 @@ For example, to have `build-script` spawn only one link job at a time, we can in
9999
```
100100
build-script --llvm-cmake-options=-DLLVM_PARALLEL_LINK_JOBS=1 --swift-cmake-options=-DSWIFT_PARALLEL_LINK_JOBS=1
101101
```
102-
103-
## Using Ninja with Xcode
104-
105-
Although it's possible to build the toolchain entirely with Xcode via `--xcode`,
106-
a more efficient and robust option is to integrate a Ninja build with Xcode.
107-
This is also convenient in that you can navigate, build, run, edit, and debug in
108-
Xcode while retaining the option of using Ninja on the command line.
109-
110-
Assuming that you have already [built the toolchain via Ninja](#the-actual-build),
111-
several more steps are necessary to set up this environment:
112-
* Generate Xcode projects with `utils/build-script --skip-build --xcode --skip-early-swift-driver`.
113-
This will first build a few LLVM files that are needed to configure the
114-
projects.
115-
* Create a new Xcode workspace.
116-
* Add the generated Xcode projects or Swift packages that are relevant to your
117-
tasks to your workspace. All the Xcode projects can be found among the
118-
build artifacts in `build/Xcode-DebugAssert`. For example:
119-
* If you are aiming for the compiler, add `build/Xcode-DebugAssert/swift-macosx-*/Swift.xcodeproj`.
120-
This project also includes the standard library and runtime sources. If you
121-
need the parts of the compiler that are implemented in Swift itself, add the
122-
`swift/SwiftCompilerSources/Package.swift` package as well.
123-
* If you are aiming for just the standard library or runtime, add
124-
`build/Xcode-DebugAssert/swift-macosx-*/stdlib/Swift-stdlib.xcodeproj`.
125-
<!-- FIXME: Without this "hard" line break, the note doesn’t get properly spaced from the bullet -->
126-
<br />
127-
128-
> **Warning**
129-
> Adding both `Swift.xcodeproj` and `LLVM.xcodeproj` *might* slow down the IDE
130-
and is not recommended unless you know what you're doing.
131-
132-
In general, we encourage you to add only what you need. Keep in mind that none
133-
of the generated Xcode projects are required to build or run with this setup
134-
because we are using Ninja—an *external* build system; rather, they should be
135-
viewed as a means of leveraging the navigation, editing and debugging features
136-
of the IDE in relation to the source code they wrap.
137-
138-
* Create an empty Xcode project in the workspace, using the
139-
_External Build System_ template.
140-
* For a Ninja target that you want to build (e.g. `swift-frontend`), add a
141-
target to the empty project, using the _External Build System_ template.
142-
* In the _Info_ pane of the target settings, set
143-
* _Build Tool_ to the path of the `ninja` executable (the output of
144-
`which ninja` on the command line)
145-
* _Arguments_ to the Ninja target name (e.g. `swift-frontend`)
146-
* _Directory_ to the path of the build directory associated with the Ninja
147-
target. For Swift targets, including the standard library and runtime, you
148-
want `path/to/swift-project/build/Ninja-*/swift-macosx-*`
149-
* Add a scheme for the target. Be sure not to select a target from one the
150-
generated Xcode projects.
151-
* > **Note**
152-
> Ignore this step if the target associates to a non-executable Ninja target
153-
like `swift-stdlib`.
154-
155-
Adjust the _Run_ action settings of the scheme:
156-
* In the _Info_ pane, select the _Executable_ built by the Ninja target from
157-
the appropriate `bin` directory (e.g. `build/Ninja-*/swift-macosx-*/bin/swift-frontend`).
158-
* In the _Arguments_ pane, add the command line arguments that you want to
159-
pass to the executable on launch (e.g. `path/to/file.swift -typecheck` for
160-
`swift-frontend`).
161-
* You can optionally set the working directory for debugging in the
162-
_Options_ pane.
163-
* Configure as many more target-scheme pairs as you need.
164-
165-
Now you are all set! You can build, run and debug as with a native Xcode
166-
project. If an `update-checkout` routine or a structural change—such as when
167-
source files are added or deleted—happens to impact your editing experience,
168-
simply regenerate the Xcode projects.
169-
170-
> **Note**
171-
> * For debugging to *fully* work for a given component—say, the compiler—the
172-
`build-script` invocation for the Ninja build must be arranged to
173-
[build a debug variant of that component](#debugging-issues).
174-
> * Xcode's indexing can occasionally start slipping after switching to and back
175-
from a distant branch, resulting in a noticeable slowdown. To sort things
176-
out, close the workspace and delete the _Index_ directory from the
177-
workspace's derived data before reopening.

docs/HowToGuides/GettingStarted.md

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ toolchain as a one-off, there are a couple of differences:
2525
- [Editing code](#editing-code)
2626
- [Setting up your fork](#setting-up-your-fork)
2727
- [First time Xcode setup](#first-time-xcode-setup)
28+
- [Using Ninja with Xcode](#using-ninja-with-xcode)
2829
- [Other IDEs setup](#other-ides-setup)
2930
- [Editing](#editing)
3031
- [Incremental builds with Ninja](#incremental-builds-with-ninja)
@@ -285,9 +286,6 @@ The additional flexibility comes with two issues: (1) consuming much more disk
285286
space and (2) you need to maintain the two builds in sync, which needs extra
286287
care when moving across branches.
287288

288-
### Integrate a Ninja build with Xcode
289-
It is possible to integrate the Ninja build into Xcode. For details on how to set this up see [Using Ninja with Xcode in DevelopmentTips.md](/docs/DevelopmentTips.md#using-ninja-with-xcode).
290-
291289
### Troubleshooting build issues
292290

293291
- Double-check that all projects are checked out at the right branches.
@@ -368,6 +366,82 @@ select the following schemes:
368366
run.
369367
<!-- TODO: Insert SourceKit/stdlib specific instructions? -->
370368
369+
### Using Ninja with Xcode
370+
371+
Although it's possible to build the toolchain entirely with Xcode via `--xcode`,
372+
a more efficient and robust option is to integrate a Ninja build with Xcode.
373+
This is also convenient in that you can navigate, build, run, edit, and debug in
374+
Xcode while retaining the option of using Ninja on the command line.
375+
376+
Assuming that you have already [built the toolchain via Ninja](#the-actual-build),
377+
several more steps are necessary to set up this environment:
378+
* Generate Xcode projects with `utils/build-script --skip-build --xcode --skip-early-swift-driver`.
379+
This will first build a few LLVM files that are needed to configure the
380+
projects.
381+
* Create a new Xcode workspace.
382+
* Add the generated Xcode projects or Swift packages that are relevant to your
383+
tasks to your workspace. All the Xcode projects can be found among the
384+
build artifacts in `build/Xcode-DebugAssert`. For example:
385+
* If you are aiming for the compiler, add `build/Xcode-DebugAssert/swift-macosx-*/Swift.xcodeproj`.
386+
This project also includes the standard library and runtime sources. If you
387+
need the parts of the compiler that are implemented in Swift itself, add the
388+
`swift/SwiftCompilerSources/Package.swift` package as well.
389+
* If you are aiming for just the standard library or runtime, add
390+
`build/Xcode-DebugAssert/swift-macosx-*/stdlib/Swift-stdlib.xcodeproj`.
391+
<!-- FIXME: Without this "hard" line break, the note doesn’t get properly spaced from the bullet -->
392+
<br />
393+
394+
> **Warning**
395+
> Adding both `Swift.xcodeproj` and `LLVM.xcodeproj` *might* slow down the IDE
396+
and is not recommended unless you know what you're doing.
397+
398+
In general, we encourage you to add only what you need. Keep in mind that none
399+
of the generated Xcode projects are required to build or run with this setup
400+
because we are using Ninja—an *external* build system; rather, they should be
401+
viewed as a means of leveraging the navigation, editing and debugging features
402+
of the IDE in relation to the source code they wrap.
403+
404+
* Create an empty Xcode project in the workspace, using the
405+
_External Build System_ template.
406+
* For a Ninja target that you want to build (e.g. `swift-frontend`), add a
407+
target to the empty project, using the _External Build System_ template.
408+
* In the _Info_ pane of the target settings, set
409+
* _Build Tool_ to the path of the `ninja` executable (the output of
410+
`which ninja` on the command line)
411+
* _Arguments_ to the Ninja target name (e.g. `swift-frontend`)
412+
* _Directory_ to the path of the build directory associated with the Ninja
413+
target. For Swift targets, including the standard library and runtime, you
414+
want `path/to/swift-project/build/Ninja-*/swift-macosx-*`
415+
* Add a scheme for the target. Be sure not to select a target from one the
416+
generated Xcode projects.
417+
* > **Note**
418+
> Ignore this step if the target associates to a non-executable Ninja target
419+
like `swift-stdlib`.
420+
421+
Adjust the _Run_ action settings of the scheme:
422+
* In the _Info_ pane, select the _Executable_ built by the Ninja target from
423+
the appropriate `bin` directory (e.g. `build/Ninja-*/swift-macosx-*/bin/swift-frontend`).
424+
* In the _Arguments_ pane, add the command line arguments that you want to
425+
pass to the executable on launch (e.g. `path/to/file.swift -typecheck` for
426+
`swift-frontend`).
427+
* You can optionally set the working directory for debugging in the
428+
_Options_ pane.
429+
* Configure as many more target-scheme pairs as you need.
430+
431+
Now you are all set! You can build, run and debug as with a native Xcode
432+
project. If an `update-checkout` routine or a structural change—such as when
433+
source files are added or deleted—happens to impact your editing experience,
434+
simply regenerate the Xcode projects.
435+
436+
> **Note**
437+
> * For debugging to *fully* work for a given component—say, the compiler—the
438+
`build-script` invocation for the Ninja build must be arranged to
439+
[build a debug variant of that component](#debugging-issues).
440+
> * Xcode's indexing can occasionally start slipping after switching to and back
441+
from a distant branch, resulting in a noticeable slowdown. To sort things
442+
out, close the workspace and delete the _Index_ directory from the
443+
workspace's derived data before reopening.
444+
371445
### Other IDEs setup
372446
373447
You can also use other editors and IDEs to work on Swift.

0 commit comments

Comments
 (0)