From 1e6bab05f7834468c511b5ebeb71f6b29dce33ba Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Fri, 6 May 2022 18:39:39 -0700 Subject: [PATCH] [build] Add build options to force-enable debug preconditions and to set a trap function in the stdlib (The underlying functionality was added in #41445 and #41449, respectively.) --- stdlib/cmake/modules/StdlibOptions.cmake | 3 +++ stdlib/cmake/modules/SwiftSource.cmake | 4 ++++ utils/build-script-impl | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/stdlib/cmake/modules/StdlibOptions.cmake b/stdlib/cmake/modules/StdlibOptions.cmake index 81e69a43750f7..2d0f2fa63a3f1 100644 --- a/stdlib/cmake/modules/StdlibOptions.cmake +++ b/stdlib/cmake/modules/StdlibOptions.cmake @@ -113,6 +113,9 @@ option(SWIFT_STDLIB_HAS_TYPE_PRINTING "Build stdlib with support for printing user-friendly type name as strings at runtime" TRUE) +set(SWIFT_STDLIB_TRAP_FUNCTION "" CACHE STRING + "Name of function to call instead of emitting a trap instruction in the stdlib") + option(SWIFT_STDLIB_BUILD_PRIVATE "Build private part of the Standard Library." TRUE) diff --git a/stdlib/cmake/modules/SwiftSource.cmake b/stdlib/cmake/modules/SwiftSource.cmake index db728e26d7909..6286db16ddafb 100644 --- a/stdlib/cmake/modules/SwiftSource.cmake +++ b/stdlib/cmake/modules/SwiftSource.cmake @@ -497,6 +497,10 @@ function(_compile_swift_files list(APPEND swift_flags "-D" "SWIFT_ENABLE_REFLECTION") endif() + if(NOT "${SWIFT_STDLIB_TRAP_FUNCTION}" STREQUAL "") + list(APPEND swift_flags "-Xfrontend" "-trap-function" "-Xfrontend" "${SWIFT_STDLIB_TRAP_FUNCTION}") + endif() + # FIXME: Cleaner way to do this? if(SWIFTFILE_IS_STDLIB_CORE) list(APPEND swift_flags diff --git a/utils/build-script-impl b/utils/build-script-impl index 723b40ad242f5..509e3b9eb19e5 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -191,6 +191,7 @@ KNOWN_SETTINGS=( swift-primary-variant-sdk "" "default SDK for target binaries" swift-runtime-enable-leak-checker "0" "Enable leaks checking routines in the runtime" swift-stdlib-enable-assertions "1" "enable assertions in Swift" + swift-stdlib-enable-debug-preconditions-in-release "0" "Enable _debugPrecondition checks in the stdlib in Release configurations" 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'" 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, ...]" report-statistics "0" "set to 1 to generate compilation statistics files for swift libraries" @@ -223,6 +224,7 @@ KNOWN_SETTINGS=( swift-stdlib-experimental-hermetic-seal-at-link "0" "whether stdlib should be built with -experimental-hermetic-seal-at-link" swift-stdlib-disable-instantiation-caches "0" "whether to build stdlib with -disable-preallocated-instantiation-caches" swift-stdlib-has-type-printing "1" "whether stdlib should support printing user-friendly type name as strings at runtime" + swift-stdlib-trap-function "" "Name of function to call instead of emitting a trap instruction" swift-disable-dead-stripping "0" "turns off Darwin-specific dead stripping for Swift host tools" common-swift-flags "" "Flags used for Swift targets other than the stdlib, like the corelibs" swift-enable-experimental-string-processing "1" "whether to build experimental string processing feature" @@ -2006,6 +2008,7 @@ for host in "${ALL_HOSTS[@]}"; do -DSWIFT_ANALYZE_CODE_COVERAGE:STRING=$(toupper "${SWIFT_ANALYZE_CODE_COVERAGE}") -DSWIFT_STDLIB_BUILD_TYPE:STRING="${SWIFT_STDLIB_BUILD_TYPE}" -DSWIFT_STDLIB_ASSERTIONS:BOOL=$(true_false "${SWIFT_STDLIB_ENABLE_ASSERTIONS}") + -DSWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE=$(true_false "${SWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE}") -DSWIFT_ENABLE_DISPATCH:BOOL=$(true_false "${SWIFT_ENABLE_DISPATCH}") -DSWIFT_IMPLICIT_CONCURRENCY_IMPORT:BOOL=$(true_false "${SWIFT_IMPLICIT_CONCURRENCY_IMPORT}") -DSWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT:BOOL=$(true_false "${SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT}") @@ -2023,6 +2026,7 @@ for host in "${ALL_HOSTS[@]}"; do -DSWIFT_STDLIB_SHORT_MANGLING_LOOKUPS:BOOL=$(true_false "${SWIFT_STDLIB_SHORT_MANGLING_LOOKUPS}") -DSWIFT_STDLIB_ENABLE_VECTOR_TYPES:BOOL=$(true_false "${SWIFT_STDLIB_ENABLE_VECTOR_TYPES}") -DSWIFT_STDLIB_HAS_TYPE_PRINTING:BOOL=$(true_false "${SWIFT_STDLIB_HAS_TYPE_PRINTING}") + -DSWIFT_STDLIB_TRAP_FUNCTION:STRING="${SWIFT_STDLIB_TRAP_FUNCTION}" -DSWIFT_STDLIB_EXPERIMENTAL_HERMETIC_SEAL_AT_LINK:BOOL=$(true_false "${SWIFT_STDLIB_EXPERIMENTAL_HERMETIC_SEAL_AT_LINK}") -DSWIFT_STDLIB_DISABLE_INSTANTIATION_CACHES:BOOL=$(true_false "${SWIFT_STDLIB_DISABLE_INSTANTIATION_CACHES}") -DSWIFT_NATIVE_LLVM_TOOLS_PATH:STRING="${native_llvm_tools_path}"