Skip to content

Commit 0bf73bb

Browse files
authored
[5.6 CMake] Move most Standard Library options in a separate file (#40669)
This allows the file to be easily included where needed (e.g. `StandaloneOverlay.cmake`) and reduce the likelihood of miscompilation due to missing sensible defaults. Focus on parameters only in stdlib/CMakeLists.txt whose defaults are not computed. This matches #40610 + #40640 Addresses rdar://86740965
1 parent 4b6e56d commit 0bf73bb

File tree

3 files changed

+78
-64
lines changed

3 files changed

+78
-64
lines changed

cmake/modules/StandaloneOverlay.cmake

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# In some configurations (e.g. back deploy concurrency) we
2+
# configure the build from the root of the Swift repo but we skip
3+
# stdlib/CMakeLists.txt, with the risk of missing important parameters.
4+
# To account for this scenario, we include the stdlib options
5+
# before the guard
6+
include(${CMAKE_CURRENT_LIST_DIR}/../../stdlib/cmake/modules/StdlibOptions.cmake)
7+
18
# CMAKE_SOURCE_DIR is the directory that cmake got initially invoked on.
29
# CMAKE_CURRENT_SOURCE_DIR is the current directory. If these are equal, it's
310
# a top-level build of the CMAKE_SOURCE_DIR. Otherwise, define a guard variable
@@ -85,10 +92,6 @@ set(SWIFT_DARWIN_MODULE_ARCHS "" CACHE STRING
8592
targets on Darwin platforms. These targets are in addition to the full \
8693
library targets.")
8794

88-
option(SWIFT_STDLIB_SHORT_MANGLING_LOOKUPS
89-
"Build stdlib with fast-path context descriptor lookups based on well-known short manglings."
90-
TRUE)
91-
9295
# -----------------------------------------------------------------------------
9396
# Constants
9497

stdlib/CMakeLists.txt

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ endif()
7272
# User-configurable options for the standard library.
7373
#
7474

75+
# New options should be added to stdlib/cmake/modules/StdlibOptions.cmake,
76+
# so that they are considered in configurations using StandaloneOverlay.cmake
77+
7578
# NOTE: Some of these variables are also initialized in StandaloneOverlay.cmake
7679
# so that interfaces are emitted when overlays are separately built.
7780

78-
set(SWIFT_STDLIB_EXTRA_SWIFT_COMPILE_FLAGS "" CACHE STRING
79-
"Extra flags to pass when compiling swift stdlib files")
81+
# TODO: migrate this section to StdlibOptions.cmake to reduce duplication
8082

81-
set(SWIFT_STDLIB_EXTRA_C_COMPILE_FLAGS "" CACHE STRING
82-
"Extra flags to pass when compiling C/C++ stdlib files")
8383

8484
option(SWIFT_STDLIB_STABLE_ABI
8585
"Should stdlib be built with stable ABI (library evolution, resilience)."
@@ -89,58 +89,14 @@ option(SWIFT_ENABLE_MODULE_INTERFACES
8989
"Generate .swiftinterface files alongside .swiftmodule files"
9090
"${SWIFT_STDLIB_STABLE_ABI}")
9191

92-
option(SWIFT_ENABLE_COMPATIBILITY_OVERRIDES
93-
"Support back-deploying compatibility fixes for newer apps running on older runtimes."
94-
TRUE)
95-
96-
option(SWIFT_STDLIB_HAS_DLADDR
97-
"Build stdlib assuming the runtime environment runtime environment provides dladdr API."
98-
TRUE)
99-
10092
option(SWIFT_STDLIB_SUPPORTS_BACKTRACE_REPORTING
10193
"Build stdlib assuming the runtime environment provides the backtrace(3) API."
10294
"${SWIFT_STDLIB_SUPPORTS_BACKTRACE_REPORTING_default}")
10395

104-
option(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION
105-
"Build stdlib assuming the runtime environment runtime environment only supports a single runtime image with Swift code."
106-
FALSE)
107-
108-
option(SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC
109-
"Build stdlib assuming the Darwin build of stdlib can use extended libmalloc APIs"
110-
TRUE)
111-
11296
option(SWIFT_STDLIB_HAS_ASL
11397
"Build stdlib assuming we can use the asl_log API."
11498
"${SWIFT_STDLIB_HAS_ASL_default}")
11599

116-
option(SWIFT_STDLIB_HAS_STDIN
117-
"Build stdlib assuming the platform supports stdin and getline API."
118-
TRUE)
119-
120-
option(SWIFT_STDLIB_HAS_ENVIRON
121-
"Build stdlib assuming the platform supports environment variables."
122-
TRUE)
123-
124-
option(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
125-
"Build the standard libraries assuming that they will be used in an environment with only a single thread."
126-
FALSE)
127-
128-
option(SWIFT_STDLIB_OS_VERSIONING
129-
"Build stdlib with availability based on OS versions (Darwin only)."
130-
TRUE)
131-
132-
option(SWIFT_STDLIB_PASSTHROUGH_METADATA_ALLOCATOR
133-
"Build stdlib without a custom implementation of MetadataAllocator, relying on malloc+free instead."
134-
FALSE)
135-
136-
option(SWIFT_STDLIB_SHORT_MANGLING_LOOKUPS
137-
"Build stdlib with fast-path context descriptor lookups based on well-known short manglings."
138-
TRUE)
139-
140-
option(SWIFT_STDLIB_HAS_COMMANDLINE
141-
"Build stdlib with the CommandLine enum and support for argv/argc."
142-
TRUE)
143-
144100
option(SWIFT_BUILD_TEST_SUPPORT_MODULES
145101
"Whether to build StdlibUnittest and other test support modules. Defaults to On when SWIFT_BUILD_SDK_OVERLAY is On, or when SWIFT_INCLUDE_TESTS is On."
146102
"${SWIFT_BUILD_TEST_SUPPORT_MODULES_default}")
@@ -152,18 +108,6 @@ option(SWIFT_STDLIB_ENABLE_PRESPECIALIZATION
152108
"Should stdlib be built with generic metadata prespecialization enabled. Defaults to On on Darwin and on Linux."
153109
"${SWIFT_STDLIB_ENABLE_PRESPECIALIZATION_default}")
154110

155-
option(SWIFT_STDLIB_EXPERIMENTAL_HERMETIC_SEAL_AT_LINK
156-
"Should stdlib be built with -experimental-hermetic-seal-at-link"
157-
FALSE)
158-
159-
set(SWIFT_STDLIB_ENABLE_LTO OFF CACHE STRING "Build Swift stdlib with LTO. One
160-
must specify the form of LTO by setting this to one of: 'full', 'thin'. This
161-
option only affects the standard library and runtime, not tools.")
162-
163-
option(SWIFT_ENABLE_REFLECTION
164-
"Build stdlib with support for runtime reflection and mirrors."
165-
TRUE)
166-
167111
if(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME)
168112
set(SWIFT_CONCURRENCY_GLOBAL_EXECUTOR_default "singlethreaded")
169113
else()
@@ -174,6 +118,10 @@ set(SWIFT_CONCURRENCY_GLOBAL_EXECUTOR
174118
"${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR_default}" CACHE STRING
175119
"Build the concurrency library to use the given global executor (options: dispatch, singlethreaded, hooked)")
176120

121+
# New options should be added to stdlib/cmake/modules/StdlibOptions.cmake,
122+
# so that they are considered in configurations using StandaloneOverlay.cmake
123+
include(StdlibOptions)
124+
177125
#
178126
# End of user-configurable options.
179127
#
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
include_guard(GLOBAL)
2+
3+
set(SWIFT_STDLIB_EXTRA_SWIFT_COMPILE_FLAGS "" CACHE STRING
4+
"Extra flags to pass when compiling swift stdlib files")
5+
6+
set(SWIFT_STDLIB_EXTRA_C_COMPILE_FLAGS "" CACHE STRING
7+
"Extra flags to pass when compiling C/C++ stdlib files")
8+
9+
option(SWIFT_ENABLE_COMPATIBILITY_OVERRIDES
10+
"Support back-deploying compatibility fixes for newer apps running on older runtimes."
11+
TRUE)
12+
13+
option(SWIFT_STDLIB_SHORT_MANGLING_LOOKUPS
14+
"Build stdlib with fast-path context descriptor lookups based on well-known short manglings."
15+
TRUE)
16+
17+
option(SWIFT_STDLIB_HAS_DLADDR
18+
"Build stdlib assuming the runtime environment runtime environment provides dladdr API."
19+
TRUE)
20+
21+
option(SWIFT_RUNTIME_STATIC_IMAGE_INSPECTION
22+
"Build stdlib assuming the runtime environment runtime environment only supports a single runtime image with Swift code."
23+
FALSE)
24+
25+
option(SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC
26+
"Build stdlib assuming the Darwin build of stdlib can use extended libmalloc APIs"
27+
TRUE)
28+
29+
option(SWIFT_STDLIB_HAS_STDIN
30+
"Build stdlib assuming the platform supports stdin and getline API."
31+
TRUE)
32+
33+
option(SWIFT_STDLIB_HAS_ENVIRON
34+
"Build stdlib assuming the platform supports environment variables."
35+
TRUE)
36+
37+
option(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
38+
"Build the standard libraries assuming that they will be used in an environment with only a single thread."
39+
FALSE)
40+
41+
option(SWIFT_STDLIB_OS_VERSIONING
42+
"Build stdlib with availability based on OS versions (Darwin only)."
43+
TRUE)
44+
45+
option(SWIFT_STDLIB_PASSTHROUGH_METADATA_ALLOCATOR
46+
"Build stdlib without a custom implementation of MetadataAllocator, relying on malloc+free instead."
47+
FALSE)
48+
49+
option(SWIFT_STDLIB_HAS_COMMANDLINE
50+
"Build stdlib with the CommandLine enum and support for argv/argc."
51+
TRUE)
52+
53+
option(SWIFT_STDLIB_EXPERIMENTAL_HERMETIC_SEAL_AT_LINK
54+
"Should stdlib be built with -experimental-hermetic-seal-at-link"
55+
FALSE)
56+
57+
set(SWIFT_STDLIB_ENABLE_LTO OFF CACHE STRING "Build Swift stdlib with LTO. One
58+
must specify the form of LTO by setting this to one of: 'full', 'thin'. This
59+
option only affects the standard library and runtime, not tools.")
60+
61+
option(SWIFT_ENABLE_REFLECTION
62+
"Build stdlib with support for runtime reflection and mirrors."
63+
TRUE)

0 commit comments

Comments
 (0)