Skip to content

Commit 3b9cd5e

Browse files
committed
Writing a readme on using the new build
Adding a quick readme to get folks started with using the new build and the different ways to configure it.
1 parent 4dae976 commit 3b9cd5e

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

Runtimes/Core/Readme.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# SwiftCore
2+
3+
SwiftCore contains core libraries that sit below the platform overlays.
4+
These include the standard library and associated runtimes, SwiftOnoneSupport,
5+
and the concurrency runtimes.
6+
7+
## Build Instructions
8+
9+
> [!IMPORTANT]
10+
> The standard library requires that it is built with a Swift compiler that is
11+
> at least as new as the standard library sources. You will likely need to
12+
> build the compiler as you would normally.
13+
> In these instructions, `<swiftc>` is the path to your just-built Swift
14+
> compiler.
15+
16+
First create a build directory in the `Core/` directory and navigate to it.
17+
18+
```sh
19+
mkdir build && cd build
20+
```
21+
22+
Configure a simple default build. This results in a static build of the standard
23+
library.
24+
25+
```sh
26+
cmake -G 'Ninja' -DCMAKE_Swift_COMPILER=<swiftc> ../`
27+
ninja
28+
```
29+
30+
To build a dynamic library, pass `-DBUILD_SHARED_LIBS=YES` to CMake.
31+
32+
```sh
33+
cmake . -DBUILD_SHARED_LIBS=YES
34+
ninja
35+
```
36+
37+
To install the standard library to a staging directory, set the `DESTDIR`
38+
environment variable and run `ninja install`
39+
40+
```sh
41+
DESTDIR=SwiftCore-Staging ninja install
42+
```
43+
44+
Semantic editing support is nice during development. CMake 3.29 and newer can
45+
produce `compile_commands.json` compilation databases, which tools like
46+
SourceKit-LSP and clangd use to provide a semantic editing experience with
47+
features like semantic syntax highlighting, symbol hover information, and
48+
jump-to-definition.
49+
50+
```sh
51+
cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=YES
52+
```
53+
54+
> [!NOTE]
55+
> Some editors will look under `<source-root>/build` for the generated
56+
> `compile_commands.json` file while others do not. You may want to create a
57+
> symlink from the `Core/` directory to `build/compile_commands.json`.
58+
> `ln -s build/compile_commands.json`
59+
60+
The compile-commands are specific to the current build configuration, so the
61+
semantic results shown in the editor match what you are currently building.
62+
63+
There are many more knobs for configuration. From the build directory, run
64+
`ccmake` to edit the build configuration to your liking.
65+
66+
### Reproducing a Build
67+
68+
The knobs make it easy to build the standard library to your needs, but can make
69+
it challenging to reproduce a specific build configuration.
70+
CMake has cache files to specify how to position the knobs for a given
71+
configuration.
72+
73+
These caches live under `cmake/caches`, but can live anywhere.
74+
To reproduce the Apple intel macOS standard library build, one would use the
75+
following CMake command from the build directory:
76+
77+
```sh
78+
cmake -G 'Ninja' \
79+
-DCMAKE_OSX_DEPLOYMENT_TARGET=15.3 \
80+
-DCMAKE_OSX_SYSROOT=macosx \
81+
-DCMAKE_Swift_COMPILER=<swiftc> \
82+
--toolchain ../cmake/caches/Vendors/Apple/Darwin.toolchain.cmake \
83+
-C ../cmake/cache/Vendors/Apple/x86_64-MacOSX.cmake \
84+
../
85+
ninja
86+
```
87+
88+
> [!NOTE]
89+
> Variables are evaluated in order of appearance on the command line.
90+
> The `x86_64-MacOSX.cmake` cache requires that `CMAKE_OSX_DEPLOYMENT_TARGET` is
91+
> set before usage. Therefore, setting `CMAKE_OSX_DEPLOYMENT_TARGET` must come
92+
> before specifying the cache or you will get an error message.

0 commit comments

Comments
 (0)