Skip to content

Commit 6a6efd9

Browse files
authored
Merge pull request #11463 from KingOfBrian/documentation/DeveloperOnboarding
Update README.md
2 parents 4db6bdf + bc4a167 commit 6a6efd9

File tree

3 files changed

+232
-135
lines changed

3 files changed

+232
-135
lines changed

README.md

+173-86
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,60 @@ features like flow control, data structures, and functions, with high-level
2121
constructs like objects, protocols, closures, and generics. Swift embraces
2222
modules, eliminating the need for headers and the code duplication they entail.
2323

24+
To learn more about the programming language, visit [swift.org](https://swift.org/documentation/).
2425

25-
## Documentation
26-
27-
To read the documentation, start by installing the
28-
[Sphinx](http://sphinx-doc.org) documentation generator tool by running the command:
29-
30-
`easy_install -U Sphinx`
31-
32-
Once complete, you can build the Swift documentation by changing directory into
33-
[docs](https://github.com/apple/swift/tree/master/docs) and typing `make`. This
34-
compiles the `.rst` files in the [docs](https://github.com/apple/swift/tree/master/docs)
35-
directory into HTML in the `docs/_build/html` directory.
26+
## Contributing to Swift
3627

37-
Many of the docs are out of date, but you can see some historical design
38-
documents in the `docs` directory.
28+
Contributions to Swift are welcomed and encouraged! Please see the
29+
[Contributing to Swift guide](https://swift.org/contributing/).
3930

40-
Another source of documentation is the standard library itself, located in
41-
`stdlib`. Much of the language is actually implemented in the library
42-
(including `Int`), and the standard library gives some examples of what can be
43-
expressed today.
31+
To be a truly great community, [Swift.org](https://swift.org/) needs to welcome
32+
developers from all walks of life, with different backgrounds, and with a wide
33+
range of experience. A diverse and friendly community will have more great
34+
ideas, more unique perspectives, and produce more great code. We will work
35+
diligently to make the Swift community welcoming to everyone.
4436

37+
To give clarity of what is expected of our members, Swift has adopted the
38+
code of conduct defined by the Contributor Covenant. This document is used
39+
across many open source communities, and we think it articulates our values
40+
well. For more, see the [Code of Conduct](https://swift.org/community/#code-of-conduct).
4541

4642
## Getting Started
4743

48-
These instructions give the most direct path to a working Swift
49-
development environment. Options for doing things differently are
50-
discussed below.
44+
These instructions give the most direct path to a working Swift development
45+
environment. To build from source you will need 2 GB of disk space for the
46+
source code and over 20 GB of disk space for the build artifacts. A clean
47+
build can take multiple hours, but incremental builds will finish much faster.
5148

5249

5350
### System Requirements
5451

5552
macOS, Ubuntu Linux LTS, and the latest Ubuntu Linux release are the current
5653
supported host development operating systems.
5754

58-
For macOS, you need [Xcode 9.0 beta 4](https://developer.apple.com/xcode/downloads/).
55+
#### macOS
56+
57+
To build for macOS, you need [Xcode 9.0 beta 4](https://developer.apple.com/xcode/downloads/).
58+
The required version of Xcode changes frequently, and is often a beta release.
59+
Check this document or the host information on <https://ci.swift.org> for the
60+
current required version.
61+
62+
You will also need [CMake](https://cmake.org) and [Ninja](https://ninja-build.org),
63+
which can be installed via a package manager:
64+
65+
**[Homebrew](https://brew.sh/)**
66+
67+
brew install cmake ninja
68+
69+
**[MacPorts](https://macports.org)**
70+
71+
sudo port install cmake ninja
72+
73+
Instructions for installing CMake and Ninja directly can be found [below](#build-dependencies)
74+
75+
#### Linux
5976

60-
<a name="linux-dependencies"></a>For Ubuntu, you'll need the following
61-
development dependencies:
77+
For Ubuntu, you'll need the following development dependencies:
6278

6379
sudo apt-get install git cmake ninja-build clang python uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev autoconf libtool systemtap-sdt-dev tzdata
6480

@@ -91,97 +107,168 @@ cloning over SSH may provide a better experience (which requires
91107
git clone git@github.com:apple/swift.git
92108
./swift/utils/update-checkout --clone-with-ssh
93109

94-
#### CMake
95-
[CMake](https://cmake.org) is the core infrastructure used to configure builds of
96-
Swift and its companion projects; at least version 3.4.3 is required.
110+
### Building Swift
97111

98-
On macOS, you can download the [CMake Binary Distribution](https://cmake.org/download),
99-
bundled as an application, copy it to `/Applications`, and add the embedded
100-
command line tools to your `PATH`:
112+
The `build-script` is a high-level build automation script that supports basic
113+
options such as building a Swift-compatible LLDB, building the Swift Package
114+
Manager, building for various platforms, running tests after builds, and more.
101115

102-
export PATH=/Applications/CMake.app/Contents/bin:$PATH
103-
104-
On Linux, if you have not already installed Swift's [development
105-
dependencies](#linux-dependencies), you can download and install the CMake
106-
package separately using the following command:
116+
There are two primary build systems to use: Xcode and Ninja. The Xcode build
117+
system allows you to work in Xcode.app, but Ninja is a bit faster and supports
118+
more environments.
107119

108-
sudo apt-get install cmake
109-
120+
To build using Ninja, run:
110121

111-
#### Ninja
112-
[Ninja](https://ninja-build.org) is the current recommended build system
113-
for building Swift and is the default configuration generated by CMake. [Pre-built
114-
packages](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages)
115-
are available for macOS and Linux distributions. You can also clone Ninja
116-
next to the other projects and it will be bootstrapped automatically:
122+
utils/build-script --release-debuginfo
117123

118-
**Via HTTPS**
124+
When developing Swift, it helps to build what you're working on in a debug
125+
configuration while building the rest of the project with optimizations. Below
126+
are some examples of using debug variants:
119127

120-
git clone https://github.com/ninja-build/ninja.git && cd ninja
121-
git checkout release
122-
cat README
128+
utils/build-script --release-debuginfo --debug-swift # Swift frontend built in debug
129+
utils/build-script --release-debuginfo --debug-swift-stdlib # Standard library built in debug
130+
utils/build-script --release-debuginfo --debug-swift --force-optimized-typechecker # Swift frontend sans type checker built in debug
123131

124-
**Via SSH**
132+
Limiting the amount of debug code in the compiler has a very large impact on
133+
Swift compile times, and in turn the test execution time. If you want to build
134+
the entire project in debug, you can run:
125135

126-
git clone git@github.com:ninja-build/ninja.git && cd ninja
127-
git checkout release
128-
cat README
136+
utils/build-script --debug
129137

130-
#### Install via third-party packaging tool (macOS only)
138+
For documentation of all available arguments, as well as additional usage
139+
information, see the inline help:
131140

132-
**[Homebrew](https://brew.sh/)**
141+
utils/build-script -h
133142

134-
brew install cmake ninja
143+
#### Xcode
135144

136-
**[MacPorts](https://macports.org)**
145+
To build using Xcode, specify the `--xcode` argument on any of the above commands.
146+
Xcode.app can be used to edit the Swift source code, but it is not currently
147+
fully supported as a build environment for SDKs other than macOS. The generated
148+
Xcode project does not integrate with the test runner, but the tests can be run
149+
with the 'check-swift' target.
137150

138-
sudo port install cmake ninja
151+
#### Build Products
139152

140-
### Building Swift
153+
All of the build products are placed in `swift-source/build/${TOOL}-${MODE}/${PRODUCT}-${PLATFORM}/`.
154+
If macOS Swift with Ninja in DebugAssert mode was built, all of the products
155+
would be in `swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/`. It
156+
helps to save this directory as an environment variable for future use.
141157

142-
The `build-script` is a high-level build automation script that supports basic
143-
options such as building a Swift-compatible LLDB, building the Swift Package
144-
Manager, building for iOS, running tests after builds, and more. It also
145-
supports presets, which you can define for common combinations of build options.
158+
export SWIFT_BUILD_DIR="~/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64"
146159

147-
To find out more:
160+
#### Ninja
148161

149-
utils/build-script -h
162+
Once the first build has completed, ninja can perform fast incremental builds of
163+
various products. These incremental builds are a big timesaver when developing
164+
and debugging.
165+
166+
cd ${SWIFT_BUILD_DIR}
167+
ninja swift
168+
169+
This will build the Swift compiler, but will not rebuild the standard library or
170+
any other target. Building the `swift-stdlib` target as an additional layer of
171+
testing from time to time is also a good idea. To build just the standard
172+
library, run:
173+
174+
ninja swift-stdlib
175+
176+
It is always a good idea to do a full build after using `update-checkout`.
177+
178+
#### Using Xcode
179+
180+
To open the Swift project in Xcode, open `${SWIFT_BUILD_DIR}/Swift.xcodeproj`.
181+
It will auto-create a *lot* of schemes for all of the available targets. A
182+
common debug flow would involve:
150183

151-
Note: Arguments after "--" above are forwarded to `build-script-impl`, which is
152-
the ultimate shell script that invokes the actual build and test commands.
184+
- Select the 'swift' scheme
185+
- Pull up the scheme editor (⌘⇧<)
186+
- Select the 'Arguments' tab and click the '+'
187+
- Add the command line options
188+
- Close the scheme editor
189+
- Build and run
153190

154-
A basic command to build Swift with optimizations and run basic tests with
155-
Ninja:
191+
Another option is to change the scheme to "Wait for executable to be launched",
192+
then run the build product in Terminal.
156193

157-
utils/build-script -r -t
194+
### Build Failures
158195

159-
## Developing Swift in Xcode
196+
Make sure you are using the [correct release](#macos) of Xcode.
160197

161-
`build-script` can also generate Xcode projects:
198+
If you have changed Xcode versions but still encounter errors that appear to
199+
be related to the Xcode version, try passing `--rebuild` to `build-script`.
162200

163-
utils/build-script -x
201+
When a new version of Xcode is released, you can update your build without
202+
recompiling the entire project by passing the `--reconfigure` option.
164203

165-
The Xcode IDE can be used to edit the Swift source code, but it is not currently
166-
fully supported as a build environment for SDKs other than macOS. If you need to
167-
work with other SDKs, you'll need to create a second build using Ninja.
204+
Make sure all repositories are up to date with the `update-checkout` command
205+
described above.
168206

169207
## Testing Swift
170208

171-
See [docs/Testing.md](docs/Testing.md).
209+
See [docs/Testing.md](docs/Testing.md), in particular the section on [lit.py](docs/Testing.md#using-litpy).
172210

173-
## Contributing to Swift
211+
## Learning More
174212

175-
Contributions to Swift are welcomed and encouraged! Please see the
176-
[Contributing to Swift guide](https://swift.org/contributing/).
213+
Be sure to look through the [docs/] docs directory for more information about the
214+
compiler. In particular, the document on [Debugging The Compiler](docs/DebuggingTheCompiler.rst),
215+
and [Continuous Integration.md](docs/ContinuousIntegration.md) are very helpful
216+
to understand before submitting your first PR.
177217

178-
To be a truly great community, [Swift.org](https://swift.org/) needs to welcome
179-
developers from all walks of life, with different backgrounds, and with a wide
180-
range of experience. A diverse and friendly community will have more great
181-
ideas, more unique perspectives, and produce more great code. We will work
182-
diligently to make the Swift community welcoming to everyone.
218+
### Building Documentation
183219

184-
To give clarity of what is expected of our members, Swift has adopted the
185-
code of conduct defined by the Contributor Covenant. This document is used
186-
across many open source communities, and we think it articulates our values
187-
well. For more, see the [Code of Conduct](https://swift.org/community/#code-of-conduct).
220+
To read the compiler documentation, start by installing the
221+
[Sphinx](http://sphinx-doc.org) documentation generator tool by running the command:
222+
223+
`easy_install -U Sphinx`
224+
225+
Once complete, you can build the Swift documentation by changing directory into
226+
[docs](https://github.com/apple/swift/tree/master/docs) and typing `make`. This
227+
compiles the `.rst` files in the [docs](https://github.com/apple/swift/tree/master/docs)
228+
directory into HTML in the `docs/_build/html` directory.
229+
230+
Many of the docs are out of date, but you can see some historical design
231+
documents in the `docs` directory.
232+
233+
Another source of documentation is the standard library itself, located in
234+
`stdlib`. Much of the language is actually implemented in the library
235+
(including `Int`), and the standard library gives some examples of what can be
236+
expressed today.
237+
238+
## Build Dependencies
239+
240+
### CMake
241+
[CMake](https://cmake.org) is the core infrastructure used to configure builds of
242+
Swift and its companion projects; at least version 3.4.3 is required.
243+
244+
On macOS, you can download the [CMake Binary Distribution](https://cmake.org/download),
245+
bundled as an application, copy it to `/Applications`, and add the embedded
246+
command line tools to your `PATH`:
247+
248+
export PATH=/Applications/CMake.app/Contents/bin:$PATH
249+
250+
On Linux, if you have not already installed Swift's [development
251+
dependencies](#linux), you can download and install the CMake
252+
package separately using the following command:
253+
254+
sudo apt-get install cmake
255+
256+
257+
### Ninja
258+
[Ninja](https://ninja-build.org) is the current recommended build system
259+
for building Swift and is the default configuration generated by CMake. [Pre-built
260+
packages](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages)
261+
are available for macOS and Linux distributions. You can also clone Ninja
262+
next to the other projects and it will be bootstrapped automatically:
263+
264+
**Via HTTPS**
265+
266+
git clone https://github.com/ninja-build/ninja.git && cd ninja
267+
git checkout release
268+
cat README
269+
270+
**Via SSH**
271+
272+
git clone git@github.com:ninja-build/ninja.git && cd ninja
273+
git checkout release
274+
cat README

0 commit comments

Comments
 (0)