Skip to content

Commit a4c1c10

Browse files
Merge pull request #61923 from AnthonyLatsis/ninjafication
build-script: Make `--xcode` imply `--skip-build --skip-early-swift-driver`
2 parents 11690ac + 98ced88 commit a4c1c10

File tree

4 files changed

+59
-61
lines changed

4 files changed

+59
-61
lines changed

docs/HowToGuides/GettingStarted.md

Lines changed: 26 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ toolchain as a one-off, there are a couple of differences:
2424
- [Troubleshooting build issues](#troubleshooting-build-issues)
2525
- [Editing code](#editing-code)
2626
- [Setting up your fork](#setting-up-your-fork)
27-
- [First time Xcode setup](#first-time-xcode-setup)
2827
- [Using Ninja with Xcode](#using-ninja-with-xcode)
2928
- [Other IDEs setup](#other-ides-setup)
3029
- [Editing](#editing)
3130
- [Incremental builds with Ninja](#incremental-builds-with-ninja)
32-
- [Incremental builds with Xcode](#incremental-builds-with-xcode)
3331
- [Spot checking an incremental build](#spot-checking-an-incremental-build)
3432
- [Reproducing an issue](#reproducing-an-issue)
3533
- [Running tests](#running-tests)
@@ -212,7 +210,7 @@ to understand what the different tools do:
212210
git repositories together, instead of manually cloning/updating each one.
213211
6. `utils/build-script` (we will introduce this shortly)
214212
is a high-level automation script that handles configuration (via CMake),
215-
building (via Ninja or Xcode), caching (via Sccache), running tests and more.
213+
building (via Ninja), caching (via Sccache), running tests and more.
216214
217215
> **Pro Tip**: Most tools support `--help` flags describing the options they
218216
> support. Additionally, both Clang and the Swift compiler have hidden flags
@@ -232,37 +230,20 @@ Phew, that's a lot to digest! Now let's proceed to the actual build itself!
232230
small compared to build artifacts. You can bump it up, say by setting
233231
`export SCCACHE_CACHE_SIZE="50G"` in your dotfile(s). For more details,
234232
see the [Sccache README][Sccache].
235-
2. Decide if you would like to build the toolchain using Ninja or using Xcode.
236-
- If you use an editor other than Xcode and/or you want somewhat faster builds,
237-
go with Ninja.
238-
- If you are comfortable with using Xcode and would prefer to use it,
239-
go with Xcode. If you run into issues building with Xcode, you can alternatively [integrate a Ninja build into Xcode](#integrate-a-ninja-build-with-xcode).
240-
There is also a third option, which is somewhat more involved:
241-
[using both Ninja and Xcode](#using-both-ninja-and-xcode).
242-
3. Build the toolchain with optimizations, debuginfo, and assertions and run
243-
the tests.
233+
2. Build the toolchain with optimizations, debuginfo, and assertions, using
234+
Ninja.
244235
- macOS:
245-
- Via Ninja:
246-
```sh
247-
utils/build-script --skip-build-benchmarks \
248-
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
249-
--sccache --release-debuginfo --swift-disable-dead-stripping
250-
```
251-
- Via Xcode:
252-
```sh
253-
utils/build-script --skip-build-benchmarks \
254-
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
255-
--sccache --release-debuginfo --swift-disable-dead-stripping \
256-
--xcode
257-
```
258-
- Linux (uses Ninja):
236+
```sh
237+
utils/build-script --skip-build-benchmarks \
238+
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
239+
--sccache --release-debuginfo --swift-disable-dead-stripping
240+
```
241+
- Linux:
259242
```sh
260243
utils/build-script --release-debuginfo --skip-early-swift-driver \
261244
--skip-early-swiftsyntax
262245
```
263-
This will create a directory
264-
`swift-project/build/Ninja-RelWithDebInfoAssert`
265-
(with `Xcode` instead of `Ninja` if you used `--xcode`)
246+
This will create a directory `swift-project/build/Ninja-RelWithDebInfoAssert`
266247
containing the Swift compiler and standard library and clang/LLVM build artifacts.
267248
If the build fails, see [Troubleshooting build issues](#troubleshooting-build-issues).
268249

@@ -340,31 +321,21 @@ git checkout -b my-branch
340321
git push --set-upstream my-remote my-branch
341322
```
342323
343-
### First time Xcode setup
344-
345-
If you used `--xcode` earlier, you will see an Xcode project generated under
346-
`../build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64` (or
347-
`../build/Xcode-RelWithDebInfoAssert/swift-macosx-arm64` on Apple Silicon Macs). When you open the
348-
project, Xcode might helpfully suggest "Automatically Create Schemes". Most of
349-
those schemes are not required in day-to-day work, so you can instead manually
350-
select the following schemes:
351-
- `swift-frontend`: If you will be working on the compiler.
352-
- `check-swift-all`: This can be used to run the tests. The test runner does
353-
not integrate with Xcode though, so it may be easier to run tests directly
354-
on the command line for more fine-grained control over which exact tests are
355-
run.
356-
<!-- TODO: Insert SourceKit/stdlib specific instructions? -->
324+
<!-- TODO: Insert paragraph about the main Ninja targets. -->
325+
357326
327+
<!--
328+
Note: utils/build-script contains a link to this heading that needs an update
329+
whenever the heading is modified.
330+
-->
358331
### Using Ninja with Xcode
359332
360-
Although it's possible to build the toolchain entirely with Xcode via `--xcode`,
361-
a more efficient and robust option is to integrate a Ninja build with Xcode.
362-
This is also convenient in that you can navigate, build, run, edit, and debug in
363-
Xcode while retaining the option of using Ninja on the command line.
333+
This workflow enables you to navigate, edit, build, run, and debug in Xcode
334+
while retaining the option of building with Ninja on the command line.
364335
365336
Assuming that you have already [built the toolchain via Ninja](#the-actual-build),
366337
several more steps are necessary to set up this environment:
367-
* Generate Xcode projects with `utils/build-script --skip-build --xcode --skip-early-swift-driver`.
338+
* Generate Xcode projects with `utils/build-script --xcode --swift-darwin-supported-archs "$(uname -m)"`.
368339
This will first build a few LLVM files that are needed to configure the
369340
projects.
370341
* Create a new Xcode workspace.
@@ -401,7 +372,7 @@ several more steps are necessary to set up this environment:
401372
* _Directory_ to the path of the build directory associated with the Ninja
402373
target. For Swift targets, including the standard library and runtime, you
403374
want `path/to/swift-project/build/Ninja-*/swift-macosx-*`
404-
* Add a scheme for the target. Be sure not to select a target from one the
375+
* Add a scheme for the target. Be careful not to select a target from one of the
405376
generated Xcode projects.
406377
* > **Note**
407378
> Ignore this step if the target associates to a non-executable Ninja target
@@ -477,11 +448,6 @@ To rebuild everything, including the standard library:
477448
ninja -C ../build/Ninja-RelWithDebInfoAssert/swift-macosx-$(uname -m)
478449
```
479450

480-
### Incremental builds with Xcode
481-
482-
Rebuilding works the same way as with any other Xcode project; you can use
483-
<kbd>⌘</kbd>+<kbd>B</kbd> or Product → Build.
484-
485451
### Spot checking an incremental build
486452

487453
As a quick test, go to `lib/Basic/Version.cpp` and tweak the version
@@ -556,13 +522,12 @@ There are two main ways to run tests:
556522

557523
If you are making small changes to the compiler or some other component, you'll
558524
likely want to [incrementally rebuild](#editing-code) only the relevant
559-
Ninja/Xcode target and use `lit.py` with `--filter`. One potential failure
560-
mode with this approach is accidental use of stale binaries. For example, say
561-
that you want to rerun a SourceKit test but you only incrementally rebuilt the
562-
compiler. Then your changes will not be reflected when the test runs because the
563-
`sourcekitd` binary was not rebuilt. Using `run-test` instead is the safer
564-
option, but it will lead to a longer feedback loop due to more things getting
565-
rebuilt.
525+
target and use `lit.py` with `--filter`. One potential failure mode with this
526+
approach is accidental use of stale binaries. For example, say that you want to
527+
rerun a SourceKit test but you only incrementally rebuilt the compiler. Then
528+
your changes will not be reflected when the test runs because the `sourcekitd`
529+
binary was not rebuilt. Using `run-test` instead is the safer option, but it
530+
will lead to a longer feedback loop due to more things getting rebuilt.
566531
567532
In the rare event that a local test failure happens to be unrelated to your
568533
changes (is not due to stale binaries and reproduces without your changes),

utils/build-script

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ def print_note(message, stream=sys.stdout):
5757
stream.flush()
5858

5959

60+
def print_warning(message, stream=sys.stdout):
61+
"""Writes a warning to the given stream. By default this function outputs
62+
to stdout.
63+
"""
64+
65+
warning = "[{}] WARNING: {}\n".format(sys.argv[0], message)
66+
magenta_warning = "\033[35m" + warning + "\033[0m"
67+
68+
stream.write(magenta_warning)
69+
stream.flush()
70+
71+
6072
def clean_delay():
6173
"""Provide a short delay so accidentally invoked clean builds can be
6274
canceled.
@@ -746,6 +758,17 @@ def main_normal():
746758
tar(source=prefix.lstrip('/'),
747759
destination=args.symbols_package)
748760

761+
if args.cmake_generator == "Xcode":
762+
print_warning(
763+
"The Xcode projects generated with '--xcode' can be used for "
764+
"navigation or editing purposes, but are not a recommended means "
765+
"to building, running or debugging. For a full-fledged Xcode "
766+
"workflow using these generated projects, see "
767+
"https://github.com/apple/swift/blob/main/docs/HowToGuides/"
768+
"GettingStarted.md#using-ninja-with-xcode"
769+
)
770+
print()
771+
749772
return 0
750773

751774

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ def _apply_default_arguments(args):
122122
# Set the default CMake generator.
123123
if args.cmake_generator is None:
124124
args.cmake_generator = 'Ninja'
125+
elif args.cmake_generator == 'Xcode':
126+
# Building with Xcode is deprecated.
127+
args.skip_build = True
128+
args.build_early_swift_driver = False
125129

126130
# --ios-all etc are not supported by open-source Swift.
127131
if args.ios_all:

utils/build_swift/tests/build_swift/test_driver_arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,3 +640,9 @@ def test_implied_defaults_host_test(self):
640640
def test_implied_defaults_swift_disable_dead_stripping(self):
641641
namespace = self.parse_default_args(['--swift-disable-dead-stripping'])
642642
self.assertTrue(namespace.swift_disable_dead_stripping)
643+
644+
def test_implied_defaults_xcode(self):
645+
namespace = self.parse_default_args(['--xcode'])
646+
self.assertEqual(namespace.cmake_generator, 'Xcode')
647+
self.assertTrue(namespace.skip_build)
648+
self.assertFalse(namespace.build_early_swift_driver)

0 commit comments

Comments
 (0)