@@ -25,6 +25,8 @@ 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 - [ Using Ninja with Xcode] ( #using-ninja-with-xcode )
28+ - [ Regenerating the Xcode project] ( #regenerating-the-xcode-project )
29+ - [ Troubleshooting editing issues in Xcode] ( #troubleshooting-editing-issues-in-xcode )
2830 - [ Other IDEs setup] ( #other-ides-setup )
2931 - [ Editing] ( #editing )
3032 - [ Incremental builds with Ninja] ( #incremental-builds-with-ninja )
@@ -280,7 +282,7 @@ Phew, that's a lot to digest! Now let's proceed to the actual build itself!
280282 > **Note**
281283 > `--release-debuginfo` means that although debug information will be produced, all targets will
282284 > be compiled in release mode, meaning optimized code, which can affect your debugging experience.
283- > Consider [`--debug-swift` to build a debug variant of the compiler](#debugging-issues) and have
285+ > Consider [`--debug-swift` to build a debug variant of the compiler](#debugging-issues) and have
284286 > the swift targets (including `swift-frontend`) built in debug mode.
285287
286288 If you would like to additionally build the Swift corelibs,
@@ -365,78 +367,77 @@ whenever the heading is modified.
365367-->
366368# ## Using Ninja with Xcode
367369
368- This workflow enables you to navigate, edit, build, run, and debug in Xcode
369- while retaining the option of building with Ninja on the command line.
370-
371- Assuming that you have already [built the toolchain via Ninja](# the-actual-build),
372- several more steps are necessary to set up this environment:
373- * Generate Xcode projects with ` utils/build-script --swift-darwin-supported-archs " $( uname -m) " --xcode --clean` .
374- This will first build a few LLVM files that are needed to configure the
375- projects.
376- * Create a new Xcode workspace.
377- * Add the generated Xcode projects or Swift packages that are relevant to your
378- tasks to your workspace. All the Xcode projects can be found among the
379- build artifacts under ` build/Xcode-* /` . For example:
380- * If you are aiming for the compiler, add ` build/Xcode-* /swift-macosx-* /Swift.xcodeproj` .
381- This project also includes the standard library and runtime sources. If you
382- need the parts of the compiler that are implemented in Swift itself, add the
383- ` swift/SwiftCompilerSources/Package.swift` package as well.
384- * If you are aiming for just the standard library or runtime, add
385- ` build/Xcode-* /swift-macosx-* /stdlib/Swift-stdlib.xcodeproj` .
386- < ! -- FIXME: Without this " hard" line break, the note doesn’t get properly spaced from the bullet -->
387- < br />
388-
389- > ** Warning**
390- > Adding both ` Swift.xcodeproj` and ` LLVM.xcodeproj` * might* slow down the IDE
391- and is not recommended unless you know what you' re doing.
392-
393- In general, we encourage you to add only what you need. Keep in mind that none
394- of the generated Xcode projects are required to build or run with this setup
395- because we are using Ninja—an *external* build system; rather, they should be
396- viewed as a means of leveraging the navigation, editing and debugging features
397- of the IDE in relation to the source code they wrap.
398-
399- * Create an empty Xcode project in the workspace, using the
400- _External Build System_ template.
401- * Add a target to the empty project, using the _External Build System_ template,
402- and name it after the Ninja target that you want to build (e.g. `swift-frontend`
403- is the compiler).
370+ This workflow enables you to edit, build, run, and debug in Xcode. The
371+ following steps assume that you have already [built the toolchain with Ninja](# the-actual-build).
372+
373+ > ** Note**
374+ > A seamless LLDB debugging experience requires that your ` build-script`
375+ invocation for Ninja is tuned to produce build rules for the
376+ [debug variant](# debugging-issues) of the component you intend to debug.
377+
378+ * < p id=" generate-xcode" >
379+ Generate the Xcode project with
380+
381+ ` ` ` sh
382+ utils/build-script --swift-darwin-supported-archs " $( uname -m) " --xcode --clean` .
383+ ` ` `
384+
385+ This can take a few minutes due to metaprogrammed sources that depend on LLVM
386+ tools that are built from source.
387+ < /p>
388+ * Create an empty Xcode workspace.
389+ * Add ` build/Xcode-* /swift-macosx-* /Swift.xcodeproj` to the workspace. If Xcode
390+ prompts to autocreate schemes, select *Manually Manage Schemes* and don' t
391+ create any schemes just yet.
392+
393+ This project includes the sources for almost everything in the repository,
394+ including the compiler, standard library and runtime. If you intend to work on
395+ a compiler subcomponent that is written in Swift and has a `Package.swift`
396+ file (e.g. `lib/ASTGen`), first choose *Product > Scheme > Manage Schemes...*
397+ and select the *Autocreate schemes* checkbox, then add the package directory
398+ to the workspace by choosing *File > Add Files to "\<workspace name>"*. Xcode
399+ will automatically create schemes for package manifest.
400+ * Create an Xcode project using the _External Build System_ template, and add
401+ it to the workspace.
402+ * Create a target in the new project, using the _External Build System_
403+ template.
404404* In the _Info_ pane of the target settings, set
405405 * _Build Tool_ to the absolute path of the `ninja` executable (the output of
406406 `which ninja` on the command line)
407- * _Arguments_ to the Ninja target (e.g. `bin/swift-frontend`)
408- * _Directory_ to the absolute path of the build directory where the Ninja
409- target lives. For Swift targets such as the compiler or standard library,
410- this is the `build/Ninja-*/swift-macosx-*` directory.
411- * Add a scheme for the target. In the drop-down menu, be careful not to mistake
412- your target for a similar one that belongs to a generated Xcode project.
413- * > **Note**
414- > Ignore this step if the target associates to a non-executable Ninja target
415- like `swift-stdlib`.
416-
417- Adjust the _Run_ action settings of the scheme:
418- * In the _Info_ pane, select the _Executable_ built by the Ninja target from
419- the appropriate `bin` directory (e.g. `build/Ninja-*/swift-macosx-*/bin/swift-frontend`).
420- * In the _Arguments_ pane, add the command line arguments that you want to
421- pass to the executable on launch (e.g. `path/to/file.swift -typecheck` for
407+ * _Arguments_ to a Ninja target (e.g. `bin/swift-frontend`, the compiler)
408+ * _Directory_ to the absolute path of the `build/Ninja-*/swift-macosx-*`
409+ directory
410+ * Create a scheme in the workspace, making sure to select the target you just
411+ created. Be *extra* careful not to choose a target from the generated Xcode
412+ project you added to the workspace.
413+ * Spot-check your target in the settings for the _Build_ scheme action.
414+ * If the target is executable, adjust the settings for the _Run_ scheme action:
415+ * In the _Info_ pane, select the _Executable_ produced by the Ninja target
416+ from `build/Ninja-*/swift-macosx-*/bin` (e.g. `swift-frontend`).
417+ * In the _Arguments_ pane, add command line arguments that you want to pass to
418+ the executable on launch (e.g. `path/to/file.swift -typecheck` for
422419 `bin/swift-frontend`).
423- * You can optionally set the working directory for debugging in the
424- _Options_ pane.
425- * Configure as many more target-scheme pairs as you need.
426-
427- Now you are all set! You can build, run and debug as with a native Xcode
428- project. If an `update-checkout` routine or a structural change—such as when
429- source files are added or deleted—happens to impact your editing experience,
430- simply regenerate the Xcode projects.
431-
432- > **Note**
433- > * For debugging to *fully* work for a given component—say, the compiler—the
434- `build-script` invocation for the Ninja build must be arranged to
435- [build a debug variant of that component](#debugging-issues).
436- > * Xcode' s indexing can occasionally start slipping after switching to and back
437- from a distant branch, resulting in a noticeable slowdown. To sort things
438- out, close the workspace and delete the _Index_ directory from the
439- workspace' s derived data before reopening.
420+ * Optionally set a custom working directory in the _Options_ pane.
421+ * Follow the previous steps to create more targets and schemes per your line
422+ of work.
423+
424+ #### Regenerating the Xcode project
425+
426+ The structure of the generated Xcode project is distinct from the underlying
427+ organization of the files on disk, and does not adapt to changes in the file
428+ system, such as file/directory additions/deletions/renames. Over the course of
429+ multiple `update-checkout` rounds, the resulting divergence is likely to begin
430+ affecting your editing experience. To fix this, regenerate the project by
431+ running the invocation from the <a href="#generate-xcode">first step</a>.
432+
433+ #### Troubleshooting editing issues in Xcode
434+
435+ * If a syntax highlighting or code action issue does not resolve itself after
436+ regenerating the Xcode project, select a scheme that covers the affected area
437+ and try *Product > Analyze*.
438+ * Xcode has been seen to sometimes get stuck on indexing after switching back
439+ and forth between distant branches. To sort things out, close the workspace
440+ and delete the _Index_ directory from its derived data.
440441
441442### Other IDEs setup
442443
0 commit comments