Skip to content

Commit 91c64f7

Browse files
authored
Merge pull request #59017 from eeckstein/docs
docs: add some build tips in DevelopmentTips.md
2 parents c9d9226 + eb51264 commit 91c64f7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/DevelopmentTips.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ Going further, for various reasons the standard library has lots of warnings. Th
2020

2121
Copy the invocation that has ` -o <build-path>/swift-macosx-x86_64/stdlib/public/core/iphonesimulator/i386/Swift.o`, so that we can perform the actual call to swiftc ourselves. Tack on `-suppress-warnings` at the end, and now we have the command to just build `Swift.o` for i386 while only displaying the actual errors.
2222

23+
### Choosing the bootstrapping mode
24+
By default, the compiler builds with the `boostrapping-with-hostlibs` (macOS) or `bootstrapping` (Linux) bootstrapping mode. To speed up local development it's recommended to build with the `hosttools` mode: `utils/build-script --bootstrapping=hosttools`.
25+
26+
It requires a recently new swift toolchain to be installed on your build machine. On macOS this comes with your Xcode installation.
27+
28+
Not that changing the bootstrapping mode needs a reconfiguration.
29+
30+
### Working with two build directories
31+
For developing and debugging you are probably building a debug configuration of swift. But it's often beneficial to also build a release-assert configuration in parallel (`utils/build-script -R`).
32+
33+
The standard library takes very long to build with a debug compiler. It's much faster to build everything (including the standard library) with a release compiler and only the swift-frontend (with `ninja swift-frontend`) in debug. Then copy the release-built standard library to the debug build:
34+
```
35+
src=/path/to/build/Ninja-ReleaseAssert/swift-macosx-x86_64
36+
dst=/path/to/build/Ninja-DebugAssert/swift-macosx-x86_64
37+
cp -r $src/stdlib $dst/
38+
cp -r $src/lib/swift/macosx $dst/lib/swift/
39+
cp -r $src/lib/swift/shims $dst/lib/swift/
40+
```
41+
2342
### Use sccache to cache build artifacts
2443

2544
Compilation times for the compiler and the standard library can be agonizing, especially for cold builds. This is particularly painful if
@@ -65,3 +84,27 @@ For example, to have `build-script` spawn only one link job at a time, we can in
6584
```
6685
build-script --llvm-cmake-options==-DLLVM_PARALLEL_LINK_JOBS=1 --swift-cmake-options=-DSWIFT_PARALLEL_LINK_JOBS=1
6786
```
87+
88+
## Using ninja with Xcode
89+
90+
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.
91+
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.
92+
93+
To setup this environment a few steps are necessary:
94+
* Create a new workspace.
95+
* 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.
96+
* 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`.
97+
* Add the `swift/SwiftCompilerSources` package to the workspace.
98+
* Create a new empty project `build-targets` (or however you want to name it) in the workspace, using the "External Build System" template.
99+
* For each compiler tool you want to build (`swift-frontend`, `sil-opt`, etc.), add an "External Build System" target to the `build-targets` project.
100+
* In the "Info" section of the target configuration, set
101+
* the _Build Tool_ to the full path of the `ninja` command
102+
* the _Argument_ to the tool name (e.g. `swift-frontend`)
103+
* 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.
104+
* For each target, create a new scheme:
105+
* In the _Build_ section add the corresponding build target what you created before.
106+
* 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`).
107+
* In the _Run/Arguments_ section you can set the command line arguments with which you want to run the compiler tool.
108+
* In the _Run/Options_ section you can set the working directory for debugging.
109+
110+
Now you are all set. You can build and debug like with a native Xcode project.

0 commit comments

Comments
 (0)