Skip to content

Commit 6013212

Browse files
committed
Refactor the Build Section
1 parent ba1ca57 commit 6013212

File tree

5 files changed

+106
-100
lines changed

5 files changed

+106
-100
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Adding a New File
2+
3+
How to add a new file to WebKit
4+
5+
## Overview
6+
7+
To add a new header file or a translation unit (e.g. `.cpp`, `.m`, or `.mm`),
8+
open WebKit.xcworkspace and add respective files in each directory.
9+
10+
Make sure to uncheck the target membership so that it’s not compiled as a part of the framework in xcodebuild.
11+
Instead, add the same file in Sources.txt file that exists in each subdirectory of Source.
12+
e.g. [Source/WebCore/Sources.txt](https://github.com/WebKit/WebKit/blob/main/Source/WebCore/Sources.txt) for WebCore.
13+
This will ensure the newly added file is compiled as a part of *unified sources*.
14+
![Screenshot of adding a file to Xcode](xcode-add-file.png)
15+
When a header file in WTF is used in WebCore, or a header file in WebCore is used in WebKit or WebKitLegacy,
16+
we need to export the file to those projects.
17+
To do that, turn on the target membership in respective framework as set the membership to “Private” as seen below.
18+
This will ensure the relevant header file is exported from WTF / WebCore to other downstream projects like WebKitLegacy.
19+
![Screenshot of exporting a header file](xcode-export-header.png)
20+
21+
FIXME: Mention WTF_EXPORT_PRIVATE and WEBCORE_EXPORT.
22+
23+
FIXME: Add instructions on how to add files to CMake.
24+

Sources/WebKit/WebKit.docc/InDepth/Build/Build.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
# Build
22

3-
<!--@START_MENU_TOKEN@-->Summary<!--@END_MENU_TOKEN@-->
3+
The WebKit Build System
44

55
## Overview
66

7-
<!--@START_MENU_TOKEN@-->Text<!--@END_MENU_TOKEN@-->
7+
WebKit can be built on a wide range of platforms and architectures. When performing a build on Apple platforms we use xcodebuild, and for non Apple platforms CMake is used instead.
8+
9+
To find specific instructions on different build options please reference <doc:BuildOptions>.
810

911
## Topics
1012

1113
### Build
1214

13-
- <doc:WebKitBuildSystem>
15+
- <doc:AddingNewFile>
16+
- <doc:ConditionalCompilation>
17+
- <doc:UnifiedBuilds>
1418

1519
### CI
1620

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Conditional Compilation
2+
3+
## Overview
4+
5+
Every translation unit in WebKit starts by including “config.h”.
6+
This file defines a set of [C++ preprocessor macros](https://en.cppreference.com/w/cpp/preprocessor)
7+
used to enable or disable code based on the target operating system, platform, and whether a given feature is enabled or disabled.
8+
9+
For example, the following `#if` condition says that the code inside of it is only compiled if
10+
[SERVICE_WORKER](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) feature is enabled:
11+
12+
```cpp
13+
#if ENABLE(SERVICE_WORKER)
14+
...
15+
#endif
16+
```
17+
18+
Similarly, the following `#if` condition will enable the in-between code only on macOS:
19+
20+
```cpp
21+
#if PLATFORM(MAC)
22+
...
23+
#endif
24+
```
25+
26+
For code which should be enabled in iOS, watchOS, tvOS, and Mac Catalyst we use `PLATFORM(IOS_FAMILY)`.
27+
For each specific variant of iOS family, we also have `PLATFORM(IOS)`, `PLATFORM(WATCHOS)`, `PLATFORM(APPLETV)`, and `PLATFORM(MACCATALYST)`.
28+
29+
The following `#if` condition will enable the in-between code only if CoreGraphics is used:
30+
31+
```cpp
32+
#if USE(CG)
33+
...
34+
#endif
35+
```
36+
37+
Finally, if a certain piece of code should only be enabled in an operating system newer than some version,
38+
we use `__IPHONE_OS_VERSION_MIN_REQUIRED` or `__MAC_OS_X_VERSION_MIN_REQUIRED`.
39+
For example, the following #if enables the in-between code only on macOS 10.14 (macOS Mojave) or above:
40+
41+
```cpp
42+
#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
43+
...
44+
#endif
45+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Unified Build System
2+
3+
An overview of how the WebKit build system is structured.
4+
5+
## Overview
6+
7+
In order to reduce the compilation time, which used to take 40+ minutes on a fully loaded 2018 15“ MacBook Pro,
8+
we bundle up multiple C++ translation units (.cpp files) and compile them as a single translation unit.
9+
This is a common technique known as *Unified Sources* or *Unified Builds*.
10+
11+
Unified Sources are generated under `WebKitBuild/X/DerivedSources` where X is the name of build configuration such as `Debug` and `Release-iphonesimulator`.
12+
For example, `WebKitBuild/Debug/DerivedSources/WebCore/unified-sources/UnifiedSource116.cpp` may look like this:
13+
14+
```cpp
15+
#include "dom/Document.cpp"
16+
#include "dom/DocumentEventQueue.cpp"
17+
#include "dom/DocumentFragment.cpp"
18+
#include "dom/DocumentMarkerController.cpp"
19+
#include "dom/DocumentParser.cpp"
20+
#include "dom/DocumentSharedObjectPool.cpp"
21+
#include "dom/DocumentStorageAccess.cpp"
22+
#include "dom/DocumentType.cpp"
23+
```
24+
25+
## Build Failures with Unified Sources
26+
27+
Because of Unified Sources, it is possible that adding a new file will cause a new build failure on some platforms.
28+
This happens because if `UnifiedSource1.cpp` contains `a.cpp`, `b.cpp`, `c.cpp`, then `#include` in `a.cpp` could have pulled in some header files that `c.cpp` needed.
29+
When you add `b2.cpp`, and `c.cpp` moves to `UnifiedSource2.cpp`, `c.cpp` no longer benefits from `a.cpp` “accidentally” satisfying `c.cpp`’s header dependency.
30+
When this happens, you need to add a new `#include` to `c.cpp` as it was supposed to be done in the first place.

Sources/WebKit/WebKit.docc/InDepth/Build/WebKitBuildSystem.md

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)