Skip to content

Commit 2b1c39f

Browse files
authored
Merge pull request #58732 from lorentey/miscellaneous-build-options
[build] Add build options to force-enable debug preconditions and to set a trap function in the stdlib
2 parents a5a15b7 + 1e6bab0 commit 2b1c39f

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

stdlib/cmake/modules/StdlibOptions.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ option(SWIFT_STDLIB_HAS_TYPE_PRINTING
113113
"Build stdlib with support for printing user-friendly type name as strings at runtime"
114114
TRUE)
115115

116+
set(SWIFT_STDLIB_TRAP_FUNCTION "" CACHE STRING
117+
"Name of function to call instead of emitting a trap instruction in the stdlib")
118+
116119
option(SWIFT_STDLIB_BUILD_PRIVATE
117120
"Build private part of the Standard Library."
118121
TRUE)

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ function(_compile_swift_files
497497
list(APPEND swift_flags "-D" "SWIFT_ENABLE_REFLECTION")
498498
endif()
499499

500+
if(NOT "${SWIFT_STDLIB_TRAP_FUNCTION}" STREQUAL "")
501+
list(APPEND swift_flags "-Xfrontend" "-trap-function" "-Xfrontend" "${SWIFT_STDLIB_TRAP_FUNCTION}")
502+
endif()
503+
500504
# FIXME: Cleaner way to do this?
501505
if(SWIFTFILE_IS_STDLIB_CORE)
502506
list(APPEND swift_flags

utils/build-script-impl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ KNOWN_SETTINGS=(
191191
swift-primary-variant-sdk "" "default SDK for target binaries"
192192
swift-runtime-enable-leak-checker "0" "Enable leaks checking routines in the runtime"
193193
swift-stdlib-enable-assertions "1" "enable assertions in Swift"
194+
swift-stdlib-enable-debug-preconditions-in-release "0" "Enable _debugPrecondition checks in the stdlib in Release configurations"
194195
swift-tools-enable-lto "" "enable LTO compilation of Swift tools. *NOTE* This does not include the swift standard library and runtime. Must be set to one of 'thin' or 'full'"
195196
extra-swift-args "" "Extra arguments to pass to swift modules which match regex. Assumed to be a flattened cmake list consisting of [module_regexp, args, module_regexp, args, ...]"
196197
report-statistics "0" "set to 1 to generate compilation statistics files for swift libraries"
@@ -223,6 +224,7 @@ KNOWN_SETTINGS=(
223224
swift-stdlib-experimental-hermetic-seal-at-link "0" "whether stdlib should be built with -experimental-hermetic-seal-at-link"
224225
swift-stdlib-disable-instantiation-caches "0" "whether to build stdlib with -disable-preallocated-instantiation-caches"
225226
swift-stdlib-has-type-printing "1" "whether stdlib should support printing user-friendly type name as strings at runtime"
227+
swift-stdlib-trap-function "" "Name of function to call instead of emitting a trap instruction"
226228
swift-disable-dead-stripping "0" "turns off Darwin-specific dead stripping for Swift host tools"
227229
common-swift-flags "" "Flags used for Swift targets other than the stdlib, like the corelibs"
228230
swift-enable-experimental-string-processing "1" "whether to build experimental string processing feature"
@@ -2006,6 +2008,7 @@ for host in "${ALL_HOSTS[@]}"; do
20062008
-DSWIFT_ANALYZE_CODE_COVERAGE:STRING=$(toupper "${SWIFT_ANALYZE_CODE_COVERAGE}")
20072009
-DSWIFT_STDLIB_BUILD_TYPE:STRING="${SWIFT_STDLIB_BUILD_TYPE}"
20082010
-DSWIFT_STDLIB_ASSERTIONS:BOOL=$(true_false "${SWIFT_STDLIB_ENABLE_ASSERTIONS}")
2011+
-DSWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE=$(true_false "${SWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE}")
20092012
-DSWIFT_ENABLE_DISPATCH:BOOL=$(true_false "${SWIFT_ENABLE_DISPATCH}")
20102013
-DSWIFT_IMPLICIT_CONCURRENCY_IMPORT:BOOL=$(true_false "${SWIFT_IMPLICIT_CONCURRENCY_IMPORT}")
20112014
-DSWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT:BOOL=$(true_false "${SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT}")
@@ -2023,6 +2026,7 @@ for host in "${ALL_HOSTS[@]}"; do
20232026
-DSWIFT_STDLIB_SHORT_MANGLING_LOOKUPS:BOOL=$(true_false "${SWIFT_STDLIB_SHORT_MANGLING_LOOKUPS}")
20242027
-DSWIFT_STDLIB_ENABLE_VECTOR_TYPES:BOOL=$(true_false "${SWIFT_STDLIB_ENABLE_VECTOR_TYPES}")
20252028
-DSWIFT_STDLIB_HAS_TYPE_PRINTING:BOOL=$(true_false "${SWIFT_STDLIB_HAS_TYPE_PRINTING}")
2029+
-DSWIFT_STDLIB_TRAP_FUNCTION:STRING="${SWIFT_STDLIB_TRAP_FUNCTION}"
20262030
-DSWIFT_STDLIB_EXPERIMENTAL_HERMETIC_SEAL_AT_LINK:BOOL=$(true_false "${SWIFT_STDLIB_EXPERIMENTAL_HERMETIC_SEAL_AT_LINK}")
20272031
-DSWIFT_STDLIB_DISABLE_INSTANTIATION_CACHES:BOOL=$(true_false "${SWIFT_STDLIB_DISABLE_INSTANTIATION_CACHES}")
20282032
-DSWIFT_NATIVE_LLVM_TOOLS_PATH:STRING="${native_llvm_tools_path}"

0 commit comments

Comments
 (0)