Skip to content

Commit 2eaa0e9

Browse files
[Runtimes][CMake] Supplemental super-build (#81179)
Continue with #81006 Will land the common Cmake modules next before implementing Synchronization build
1 parent b2fe628 commit 2eaa0e9

File tree

3 files changed

+106
-4
lines changed

3 files changed

+106
-4
lines changed

CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,13 +1665,14 @@ if(SWIFT_ENABLE_NEW_RUNTIME_BUILD)
16651665

16661666
ExternalProject_Get_Property("${stdlib_target}-core" INSTALL_DIR)
16671667

1668-
ExternalProject_Add("${stdlib_target}-StringProcessing"
1669-
SOURCE_DIR
1670-
"${CMAKE_CURRENT_SOURCE_DIR}/Runtimes/Supplemental/StringProcessing"
1668+
ExternalProject_Add("${stdlib_target}-Supplemental"
1669+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Runtimes/Supplemental"
16711670
DEPENDS "${stdlib_target}-core"
16721671
INSTALL_DIR "${INSTALL_DIR}"
1673-
INSTALL_COMMAND "" # No install story set up yet
1672+
INSTALL_COMMAND ""
1673+
LIST_SEPARATOR "|"
16741674
CMAKE_ARGS
1675+
-DSwift_ENABLE_RUNTIMES=StringProcessing
16751676
-DBUILD_SHARED_LIBS=YES
16761677
-DCMAKE_Swift_COMPILER_WORKS:BOOLEAN=YES
16771678
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}

Runtimes/Supplemental/CMakeLists.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
cmake_minimum_required(VERSION 3.29)
2+
3+
project(SwiftRuntime LANGUAGES Swift C CXX)
4+
5+
include(ExternalProject)
6+
include(GNUInstallDirs)
7+
8+
set(SwiftRuntime_SWIFTC_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../")
9+
10+
foreach(lib ${Swift_ENABLE_RUNTIMES})
11+
string(TOLOWER ${lib} name)
12+
set(SwiftRuntime_ENABLE_${name} YES)
13+
endforeach()
14+
15+
if(SwiftCore_DIR)
16+
set(SwiftCore_DIR_FLAG "-DSwiftCore_DIR=${SwiftCore_DIR}")
17+
endif()
18+
19+
if(CMAKE_MAKE_PROGRAM)
20+
set(MAKE_PROGRAM_FLAG "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}")
21+
endif()
22+
23+
set(COMMON_OPTIONS
24+
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
25+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
26+
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
27+
-DCMAKE_INSTALL_NAME_DIR=${CMAKE_INSTALL_NAME_DIR}
28+
-DCMAKE_BUILD_WITH_INSTALL_NAME_DIR=${CMAKE_BUILD_WITH_INSTALL_NAME_DIR}
29+
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
30+
-DCMAKE_COLOR_DIAGNOSTICS=${CMAKE_COLOR_DIAGNOSTICS}
31+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
32+
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
33+
-DCMAKE_Swift_COMPILER=${CMAKE_Swift_COMPILER}
34+
-DCMAKE_C_COMPILER_TARGET=${CMAKE_C_COMPILER_TARGET}
35+
-DCMAKE_CXX_COMPILER_TARGET=${CMAKE_CXX_COMPILER_TARGET}
36+
-DCMAKE_Swift_COMPILER_TARGET=${CMAKE_Swift_COMPILER_TARGET}
37+
${SwiftCore_DIR_FLAG}
38+
${MAKE_PROGRAM_FLAG})
39+
40+
# StringProcessing
41+
if(SwiftRuntime_ENABLE_stringprocessing)
42+
ExternalProject_Add(StringProcessing
43+
PREFIX "StringProcessing"
44+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/StringProcessing"
45+
INSTALL_DIR "${CMAKE_INSTALL_PREFIX}"
46+
INSTALL_COMMAND ""
47+
CMAKE_ARGS
48+
${COMMON_OPTIONS})
49+
endif()

Runtimes/Supplemental/Readme.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Swift Supplemental Libraries
2+
3+
The supplemental libraries are all libraries that are not one of the Core or
4+
overlay libraries. Each supplemental library builds as an independent project.
5+
6+
The supplemental libraries are:
7+
- CxxInterop
8+
- Differentiation
9+
- Distributed
10+
- Observation
11+
- StringProcessing
12+
- Runtime
13+
- Synchronization
14+
15+
The top-level Supplemental CMakeLists supplies a super-build pattern for
16+
configuring and compiling each of the supplemental library projects through a
17+
single CMake invocation. The `Swift_ENABLE_RUNTIMES` CMake option enables the
18+
specified supplemental libraries. All libraries configured this way are built
19+
with the same compilers, against the same sysroot, with the same target triple
20+
and installed into the same location.
21+
22+
## Super-Build
23+
24+
Configuring each project independently is tedious. The Supplemental directory
25+
contains a Super-Build CMakeLists that invokes the build of each of the
26+
supplemental libraries in the appropriate order, simplifying the process of
27+
building each library.
28+
29+
Important configuration variables:
30+
- `Swift_ENABLE_RUNTIMES`: Used to configure which runtime libraries are built.
31+
32+
The super-build forwards the following variables to each sub-project
33+
unconditionally:
34+
- `BUILD_SHARED_LIBS`
35+
- `CMAKE_BUILD_TYPE`
36+
- `CMAKE_INSTALL_PREFIX`
37+
- `CMAKE_COLOR_DIAGNOSTICS`
38+
- `CMAKE_C_COMPILER`
39+
- `CMAKE_C_COMPILER_TARGET`
40+
- `CMAKE_CXX_COMPILER`
41+
- `CMAKE_CXX_COMPILER_TARGET`
42+
- `CMAKE_Swift_COMPILER`
43+
- `CMAKE_Swift_COMPILER_TARGET`
44+
45+
If set, the super-build forwards the following values to each sub-project:
46+
47+
- `SwiftCore_DIR`: Path to the SwiftCore build directory
48+
- `CMAKE_MAKE_PROGRAM`: Path to `ninja`
49+
50+
The super-build is for convenience. If more fine-grained control is desired for
51+
configuring a specific runtime library, you may configure that library
52+
independently.

0 commit comments

Comments
 (0)