Skip to content

Commit 869bcfb

Browse files
committed
docs: describe where the build system is evolving to
Add a manifesto which describes where the build infrastructure is slowly evolving to. Although a good chunk of the necessary work to enable this is already in the tree, this helps explain the desired state to everyone working on the project.
1 parent 0dc0b03 commit 869bcfb

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

docs/BuildManifesto.md

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Build System
2+
3+
## Introduction
4+
5+
Modularising the build of Swift is a large undertaking that will simplify the
6+
infrastructure used to build the compiler, runtime, standard library, as well
7+
as the core libraries. Additionally, the work will enable a unified, uniform
8+
build system that reduces the barrier to entry for new contributors.
9+
10+
## Current State
11+
12+
Currently, the Swift build is setup similar to the way that the GCC build was
13+
setup. This requires the understanding of the terms `build`, `host`, `target`
14+
as used by autotools.
15+
16+
<dl>
17+
<dt><strong>build</strong></dt>
18+
<dd>the system where the package is being configured and compiled<br/>
19+
x86_64-unknown-linux-gnu
20+
</dd>
21+
<dt><strong>host</strong></dt>
22+
<dd>the system where the package runs (by default the same as <i>build</i>)<br/>
23+
x86-64-unknown-windows-msvc
24+
</dd>
25+
<dt><strong>target</strong></dt>
26+
<dd>the system for which the compiler tools generate code<br/>
27+
aarch64-unknown-linux-android<br/>
28+
<strong>NOTE</strong> this is not really supported properly in the original
29+
build system
30+
</dd>
31+
</dl>
32+
33+
## Desired State
34+
35+
It is preferable to instead consider the full package build as a set of builds
36+
where you are doing normal builds with a differing set of `build` and `host`
37+
values. That is, you can consider the regular host build (e.g. Linux) as:
38+
39+
```Swift
40+
[
41+
/* compiler */ (build: "x86_64-unknown-linux-gnu", host: "x86_64-unknown-linux-gnu"),
42+
/* runtime */ (build: "x86_64-unknown-linux-gnu", host: "x86_64-unknown-linux-gnu"),
43+
/* stdlib */ (build: "x86_64-unknown-linux-gnu", host: "x86_64-unknown-linux-gnu"),
44+
]
45+
```
46+
47+
Or for more complicated scenarios such as Darwin where you may be compiling for
48+
Darwin and iOS as:
49+
50+
```Swift
51+
[
52+
/* compiler */ (build: "x86_64-apple-macosx10.14", host: "x86_64-apple-macosx10.14"),
53+
/* runtime */ (build: "x86_64-apple-macosx10.14", host: "x86_64-apple-macosx10.14"),
54+
/* stdlib */ (build: "x86_64-apple-macosx10.14", host: "x86_64-apple-macosx10.14"),
55+
/* runtime */ (build: "x86_64-apple-macosx10.14", host: "armv7-apple-ios12.3"),
56+
/* stdlib */ (build: "x86_64-apple-macosx10.14", host: "armv7-apple-ios12.3"),
57+
]
58+
```
59+
60+
This simplifies the build terminology by having to only deal with the terms
61+
`build` and `host` which removes some of the confusion caused by the original
62+
build system's implementation creating multiple terms and being designed around
63+
the needs of the Darwin build.
64+
65+
This also generalises to allow for multiple cross-compilations in a single build
66+
invocation which allows the functionality currently available only on Darwin to
67+
be applied to all the targets that Swift supports (and may support in the
68+
future).
69+
70+
Doing so also enables the build system to be trimmed significantly as we can use
71+
CMake as it was designed to while retaining the ability to cross-compile. The
72+
cross-compilation model for CMake involves invoking `cmake` multiple times with
73+
`CMAKE_SYSTEM_NAME` and `CMAKE_SYSTEM_PROCESSOR` set appropriately to the host
74+
that you would like to build for. This ensures that host specific behaviour is
75+
explicitly handled properly (e.g. import libraries on Windows - something which
76+
was shoehorned into the original CMake implementation in CMake) and corrects the
77+
behaviour of the cmake `install` command.
78+
79+
Another bit of functional flexibility that this system enables is the ability to
80+
allow developers to focus entirely on the area that they are working in. The
81+
runtime and standard library can be separated and built with a prebuilt
82+
(nightly) release of the compiler toolchain, or focus entirely on building the
83+
standard library for a certain set of targets.
84+
85+
By organising the standard library build as a regular library, we enable the
86+
ability to use the LLVM runtimes build to cross-compile the standard library for
87+
multiple targets as long as the dependent system libraries are available at
88+
build time.
89+
90+
The ability to build the runtime components for different hosts allows building
91+
the Swift SDK for various hosts on a single machine. This enables the build of
92+
the android SDK and Linux SDKs on Windows and vice versa.
93+
94+
Note that none of the changes described here prevent the workflows that are
95+
possible with build-script today.
96+

0 commit comments

Comments
 (0)