Skip to content

Commit a67eb35

Browse files
authored
Merge pull request #77372 from etcwilde/ewilde/stdlib-rebuild-readme-and-sync
Extract stdlib sources for new standard library
2 parents 794165a + f03d9a0 commit a67eb35

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,17 @@ SortedCFDatabase.def
7878
htmlcov
7979
.coverage
8080
/benchmark/scripts/Benchmark_Driverc
81+
82+
#==============================================================================#
83+
# Ignore copied Swift Stdlib files while migrating stdlib
84+
#==============================================================================#
85+
Runtimes/**/*.swift
86+
Runtimes/**/*.h
87+
Runtimes/**/*.cpp
88+
Runtimes/**/*.c
89+
Runtimes/**/*.m
90+
Runtimes/**/*.mm
91+
Runtimes/**/*.def
92+
Runtimes/**/*.gyb
93+
Runtimes/**/*.apinotes
94+
Runtimes/**/*.yaml

Runtimes/Readme.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Swift Runtime Libraries
2+
3+
This directory contains the pieces of the Swift runtime libraries.
4+
5+
## Development
6+
7+
While we're bringing up the new standard library build, please do not commit the
8+
standard library source files. Use the `Resync.cmake` file to copy the files as
9+
needed.
10+
11+
```sh
12+
$ cmake -P Resync.cmake
13+
```
14+
15+
> [!IMPORTANT]
16+
> Re-run this script after updating your Swift checkout to ensure that you are
17+
> building the latest standard library sources.
18+
19+
Once the migration is completed, we will be deleting this script. It
20+
is a temporary workaround to avoid trying to keep multiple sets of files in
21+
sync.
22+
23+
## Layering
24+
25+
```
26+
╔═══════════════╗
27+
║ ║
28+
║ Testing ║
29+
║ ║
30+
╠───────────────╣
31+
│ │
32+
│ Supplemental │
33+
│ │
34+
├───────────────┤
35+
│ │
36+
│ Overlay │
37+
│ │
38+
├───────────────┤
39+
│ │
40+
│ Core │
41+
│ │
42+
└───────────────┘
43+
```
44+
45+
### Core
46+
47+
The _Core_ project contains the basic datatypes and underpinnings used by the
48+
rest of the libraries that make up the standard library. The _Core_ libraries
49+
must be built first.
50+
The _Core_ project provides the following libraries:
51+
- `swiftCore`
52+
- `swift_Concurrency`
53+
- `SwiftOnoneSupport`
54+
- `CommandLine`
55+
- `Demangling`
56+
- `Runtime`
57+
- `LLVMSupport`
58+
- `StdlibStubs`
59+
- `Threading`
60+
- `SwiftShim`
61+
62+
These libraries must work across the platforms that Swift supports.
63+
64+
### Overlay
65+
66+
The Overlay project contains a few default platform overlay libraries. A
67+
platform overlay is responsible for exposing the system libraries into Swift in
68+
an ergonomic fashion. On most systems, this exposes the C standard library and a
69+
few other libraries that are normally available on that system. The overlay
70+
libraries are allowed to depend on any of the runtime libraries provided by the
71+
_Core_ project and libraries distributed by the platform.
72+
73+
The platform overlay is specific to the platform that it overlays and cannot be
74+
used across platforms.
75+
76+
### Supplemental
77+
78+
The supplemental libraries provide the remainder of the standard distribution of
79+
libraries provided by Swift.
80+
81+
The Supplemental libraries include:
82+
- `RegexParser`
83+
- `StringProcessing`
84+
- `RegexBuilder`
85+
- `Cxx Interop`
86+
- `Synchronization`
87+
- `Distributed`
88+
- `Observation`
89+
90+
The behavior of these libraries may differ slightly based on the behavior of the
91+
underlying operating system. These libraries are allowed to depend on the
92+
platform overlay and the libraries provided by the _Core_ project.
93+
94+
### Testing
95+
96+
The testing project provides testing support for the libraries that make up the
97+
standard library. These libraries are optional and are not intended for
98+
shipping. They must be built last, after the Core, the Overlay, and the
99+
Supplemental libraries.

Runtimes/Resync.cmake

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This CMake script keeps the files in the new standard library build in sync
2+
# with the existing standard library.
3+
4+
# TODO: Once the migration is completed, we can delete this file
5+
6+
cmake_minimum_required(VERSION 3.21)
7+
8+
# Where the standard library lives today
9+
set(StdlibSources "${CMAKE_CURRENT_LIST_DIR}/../stdlib")
10+
11+
message(STATUS "Source dir: ${StdlibSources}")
12+
13+
# Copy the files under the "name" directory in the standard library into the new
14+
# location under Runtimes
15+
function(copy_library_sources name from_prefix to_prefix)
16+
message(STATUS "${name}[${StdlibSources}/${from_prefix}/${name}] -> ${to_prefix}/${name} ")
17+
18+
file(GLOB_RECURSE filenames
19+
FOLLOW_SYMLINKS
20+
LIST_DIRECTORIES FALSE
21+
RELATIVE "${StdlibSources}/${from_prefix}"
22+
"${StdlibSources}/${from_prefix}/${name}/*.swift"
23+
"${StdlibSources}/${from_prefix}/${name}/*.h"
24+
"${StdlibSources}/${from_prefix}/${name}/*.cpp"
25+
"${StdlibSources}/${from_prefix}/${name}/*.c"
26+
"${StdlibSources}/${from_prefix}/${name}/*.mm"
27+
"${StdlibSources}/${from_prefix}/${name}/*.m"
28+
"${StdlibSources}/${from_prefix}/${name}/*.def"
29+
"${StdlibSources}/${from_prefix}/${name}/*.gyb"
30+
"${StdlibSources}/${from_prefix}/${name}/*.apinotes"
31+
"${StdlibSources}/${from_prefix}/${name}/*.yaml")
32+
33+
foreach(file ${filenames})
34+
# Get and create the directory
35+
get_filename_component(dirname ${file} DIRECTORY)
36+
file(MAKE_DIRECTORY "${to_prefix}/${dirname}")
37+
file(COPY_FILE
38+
"${StdlibSources}/${from_prefix}/${file}" # From
39+
"${CMAKE_CURRENT_LIST_DIR}/${to_prefix}/${file}" # To
40+
RESULT _output
41+
ONLY_IF_DIFFERENT)
42+
if(_output)
43+
message(SEND_ERROR
44+
"Copy ${from_prefix}/${file} -> ${to_prefix}/${file} Failed: ${_output}")
45+
endif()
46+
endforeach()
47+
endfunction()
48+
49+
# Directories in the existing standard library that make up the Core project
50+
51+
# Copy shared core headers
52+
copy_library_sources(include "" "Core")
53+
54+
set(CoreLibs
55+
LLVMSupport)
56+
57+
# Add these as we get them building
58+
# core
59+
# Concurrency
60+
# SwiftOnoneSUpport
61+
# CommandLineSupport
62+
# Demangling
63+
# runtime)
64+
65+
foreach(library ${CoreLibs})
66+
copy_library_sources(${library} "public" "Core")
67+
endforeach()
68+
69+
# TODO: Add source directories for the platform overlays, supplemental
70+
# libraries, and test support libraries.

0 commit comments

Comments
 (0)