Skip to content

Commit 6f77e8b

Browse files
authored
Split out SWIFT_ENABLE_REFLECTION into a separate SWIFT_STDLIB_REFLECTION_METADATA CMake flag to control whether stdlib is built with reflection metadata or not (#61496)
1 parent 36c01e8 commit 6f77e8b

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

stdlib/cmake/modules/StdlibOptions.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,11 @@ option(SWIFT_STDLIB_HAS_COMMANDLINE
169169
TRUE)
170170

171171
option(SWIFT_ENABLE_REFLECTION
172-
"Build stdlib with support for runtime reflection and mirrors."
173-
TRUE)
172+
"Build stdlib with support for runtime reflection and mirrors."
173+
TRUE)
174+
175+
set(SWIFT_STDLIB_REFLECTION_METADATA "enabled" CACHE STRING
176+
"Build stdlib with runtime metadata (valid options are 'enabled', 'disabled' and 'debugger-only').")
174177

175178
if(SWIFT_FREESTANDING_FLAVOR STREQUAL "apple" AND NOT SWIFT_FREESTANDING_IS_DARWIN)
176179
set(SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY_default TRUE)

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,18 @@ function(_compile_swift_files
499499
list(APPEND swift_flags "-Xfrontend" "-emit-sorted-sil")
500500
endif()
501501

502-
if(NOT SWIFT_ENABLE_REFLECTION)
502+
if(SWIFT_ENABLE_REFLECTION)
503+
list(APPEND swift_flags "-D" "SWIFT_ENABLE_REFLECTION")
504+
endif()
505+
506+
if("${SWIFT_STDLIB_REFLECTION_METADATA}" STREQUAL "enabled")
507+
# do nothing, emitting reflection metadata is the default in swiftc
508+
elseif("${SWIFT_STDLIB_REFLECTION_METADATA}" STREQUAL "debugger-only")
503509
list(APPEND swift_flags "-Xfrontend" "-reflection-metadata-for-debugger-only")
510+
elseif("${SWIFT_STDLIB_REFLECTION_METADATA}" STREQUAL "disabled")
511+
list(APPEND swift_flags "-Xfrontend" "-disable-reflection-metadata")
504512
else()
505-
list(APPEND swift_flags "-D" "SWIFT_ENABLE_REFLECTION")
513+
message(FATAL_ERROR "Invalid SWIFT_STDLIB_REFLECTION_METADATA value: ${SWIFT_STDLIB_REFLECTION_METADATA}")
506514
endif()
507515

508516
if(NOT "${SWIFT_STDLIB_TRAP_FUNCTION}" STREQUAL "")

utils/build-presets.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,6 +2514,7 @@ swift-enable-dispatch=0
25142514
swift-implicit-concurrency-import=0
25152515
swift-stdlib-support-back-deployment=0
25162516
swift-enable-reflection=0
2517+
swift-stdlib-reflection-metadata=debugger-only
25172518
swift-stdlib-stable-abi=0
25182519
swift-stdlib-has-dladdr=0
25192520
swift-stdlib-supports-backtrace-reporting=0

utils/build-script-impl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ KNOWN_SETTINGS=(
204204
swift-implicit-concurrency-import "1" "whether to implicitly import the Swift concurrency module"
205205
swift-stdlib-support-back-deployment "1" "whether to support back-deployment of built binaries to older OS versions"
206206
swift-enable-reflection "1" "whether to support reflection and mirrors"
207+
swift-stdlib-reflection-metadata "enabled" "whether to build stdlib with runtime metadata (valid options are 'enabled', 'disabled' and 'debugger-only')"
207208
swift-stdlib-has-dladdr "1" "whether to build stdlib assuming the runtime environment provides dladdr API"
208209
swift-stdlib-supports-backtrace-reporting "" "whether to build stdlib assuming the runtime environment provides the backtrace(3) API, if not set defaults to true on all platforms except for Cygwin, Haiku and wasm"
209210
swift-runtime-static-image-inspection "0" "whether to build stdlib assuming the runtime environment only supports a single runtime image with Swift code"
@@ -2024,6 +2025,7 @@ for host in "${ALL_HOSTS[@]}"; do
20242025
-DSWIFT_STDLIB_TRAP_FUNCTION:STRING="${SWIFT_STDLIB_TRAP_FUNCTION}"
20252026
-DSWIFT_STDLIB_EXPERIMENTAL_HERMETIC_SEAL_AT_LINK:BOOL=$(true_false "${SWIFT_STDLIB_EXPERIMENTAL_HERMETIC_SEAL_AT_LINK}")
20262027
-DSWIFT_STDLIB_DISABLE_INSTANTIATION_CACHES:BOOL=$(true_false "${SWIFT_STDLIB_DISABLE_INSTANTIATION_CACHES}")
2028+
-DSWIFT_STDLIB_REFLECTION_METADATA:STRING="${SWIFT_STDLIB_REFLECTION_METADATA}"
20272029
-DSWIFT_NATIVE_LLVM_TOOLS_PATH:STRING="${native_llvm_tools_path}"
20282030
-DSWIFT_NATIVE_CLANG_TOOLS_PATH:STRING="${native_clang_tools_path}"
20292031
-DSWIFT_NATIVE_SWIFT_TOOLS_PATH:STRING="${native_swift_tools_path}"

0 commit comments

Comments
 (0)