Skip to content

Commit 2e5181f

Browse files
authored
Merge pull request #79527 from etcwilde/ewilde/stdlib-rebuild-core-readme
Writing a readme on using the new build
2 parents bdc953f + 7011a40 commit 2e5181f

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

Runtimes/Core/Readme.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
Run these commands from the `Runtimes/Core` directory.
17+
18+
Build a standard library with the default configuration. This builds for the
19+
system that the command was run on, usually resulting in a static archive
20+
without optimizations applied.
21+
22+
```sh
23+
cmake -B build -S . -G Ninja -DCMAKE_Swift_COMPILER=<swiftc>
24+
cmake --build build
25+
DESTDIR=/tmp/staging-dir cmake --install build --prefix /usr
26+
```
27+
28+
The `DESTDIR` environment variable sets the staging location so that the result
29+
of the build isn't installed directly to `/usr` on the system performing the
30+
build.
31+
32+
> [!NOTE]
33+
> The `DESTDIR` environment variable is not portable to Windows.
34+
> Use `CMAKE_INSTALL_PREFIX` or the `--prefix` flag to set the staging location.
35+
36+
To build the runtimes as dynamic libraries, pass `-DBUILD_SHARED_LIBS=YES` to
37+
CMake.
38+
39+
```sh
40+
cmake -B build -S . -G Ninja -DBUILD_SHARED_LIBS=YES -DCMAKE_Swift_COMPILER=<swiftc>
41+
cmake --build build
42+
```
43+
44+
To enable semantic editing, ensure you're running CMake 3.29 or newer and enable
45+
`CMAKE_EXPORT_COMPILE_COMMANDS`.
46+
47+
```sh
48+
cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=YES
49+
```
50+
51+
Some editors will look under `<source-root>/build` for the generated
52+
`compile_commands.json` while others do not.
53+
On UNIX-like systems, run `ln -s build/compile_commands.json`.
54+
On Windows, creating symlinks requires administrator privileges, but can be done
55+
with CMake `cmake -E create_symlink build\compile_commands.json
56+
compile_commands.json`. If you do not have administrator privileges, you can
57+
copy the file from your build directory into the root directory of your sources.
58+
Note that the copied file won't be updated so you will need to copy the file
59+
each time you re-run CMake.
60+
61+
The compile-commands are specific to the current build configuration, so the
62+
semantic results shown in the editor match what you are currently building.
63+
64+
There are many more knobs for configuration. From the build directory, run
65+
`ccmake` to edit the build configuration to your liking.
66+
67+
### Reproducing a Build
68+
69+
The knobs make it easy to build the standard library to your needs, but can make
70+
it challenging to reproduce a specific build configuration.
71+
CMake has cache files to specify how to position the knobs for a given
72+
configuration.
73+
74+
These caches live under `cmake/caches`, but can live anywhere.
75+
The following command uses the `x86_64-MacOSX.cmake` cache file to reproduce the
76+
Apple Intel macOS standard library build.
77+
78+
79+
```sh
80+
cmake -B build -S . -G Ninja \
81+
-DCMAKE_OSX_DEPLOYMENT_TARGET=15.3 \
82+
-DCMAKE_OSX_SYSROOT=macosx \
83+
-DCMAKE_Swift_COMPILER=<swiftc> \
84+
--toolchain cmake/caches/Vendors/Apple/Darwin.toolchain.cmake \
85+
-C cmake/caches/Vendors/Apple/x86_64-MacOSX.cmake
86+
cmake --build build
87+
```
88+
89+
> [!NOTE]
90+
> Variables are evaluated in order of appearance on the command line.
91+
> The `x86_64-MacOSX.cmake` cache requires that `CMAKE_OSX_DEPLOYMENT_TARGET` is
92+
> set before usage. Therefore, setting `CMAKE_OSX_DEPLOYMENT_TARGET` must come
93+
> before specifying the cache or you will get an error message.

0 commit comments

Comments
 (0)