Skip to content

Commit aa92419

Browse files
authored
Add a flag to build the stdlib without COMPATIBILITY_OVERRIDE (swiftlang#33438)
1 parent 11c9184 commit aa92419

File tree

7 files changed

+38
-0
lines changed

7 files changed

+38
-0
lines changed

stdlib/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ project(swift-stdlib LANGUAGES C CXX)
99
list(APPEND CMAKE_MODULE_PATH
1010
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
1111

12+
#
13+
# User-configurable options for the standard library.
14+
#
15+
16+
option(SWIFT_ENABLE_COMPATIBILITY_OVERRIDES
17+
"Support back-deploying compatibility fixes for newer apps running on older runtimes."
18+
TRUE)
19+
20+
#
21+
# End of user-configurable options.
22+
#
23+
1224
include(AddSwiftStdlib)
1325

1426
# Create convenience targets for the Swift standard library.

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ function(_add_target_variant_c_compile_flags)
333333
list(APPEND result "-DSWIFT_OBJC_INTEROP=0")
334334
endif()
335335

336+
if(NOT SWIFT_ENABLE_COMPATIBILITY_OVERRIDES)
337+
list(APPEND result "-DSWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES")
338+
endif()
339+
336340
set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)
337341
endfunction()
338342

stdlib/public/runtime/CompatibilityOverride.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17+
#ifndef SWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES
18+
1719
#include "CompatibilityOverride.h"
1820

1921
#include "ImageInspection.h"
@@ -68,3 +70,5 @@ static OverrideSection *getOverrideSectionPtr() {
6870
return Section->name; \
6971
}
7072
#include "CompatibilityOverride.def"
73+
74+
#endif // #ifndef SWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES

stdlib/public/runtime/CompatibilityOverride.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424

2525
namespace swift {
2626

27+
#ifdef SWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES
28+
29+
#define COMPATIBILITY_OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \
30+
attrs ccAttrs ret namespace swift_ ## name typedArgs { \
31+
return swift_ ## name ## Impl namedArgs; \
32+
}
33+
34+
#else // #ifdef SWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES
35+
2736
#define COMPATIBILITY_UNPAREN(...) __VA_ARGS__
2837

2938
#define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \
@@ -56,6 +65,8 @@ namespace swift {
5665
return swift_ ## name ## Impl namedArgs; \
5766
}
5867

68+
#endif // #else SWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES
69+
5970
} /* end namespace swift */
6071

6172
#endif /* COMPATIBILITY_OVERRIDE_H */

stdlib/public/runtime/ImageInspectionMachO.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ int swift::lookupSymbol(const void *address, SymbolInfo *info) {
169169
return 1;
170170
}
171171

172+
#ifndef SWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES
173+
172174
void *swift::lookupSection(const char *segment, const char *section, size_t *outSize) {
173175
unsigned long size;
174176
auto *executableHeader = static_cast<mach_header_platform *>(_NSGetMachExecuteHeader());
@@ -178,4 +180,6 @@ void *swift::lookupSection(const char *segment, const char *section, size_t *out
178180
return static_cast<void *>(data);
179181
}
180182

183+
#endif // #ifndef SWIFT_RUNTIME_NO_COMPATIBILITY_OVERRIDES
184+
181185
#endif // defined(__APPLE__) && defined(__MACH__)

utils/build-presets.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,6 +2390,7 @@ build-swift-dynamic-sdk-overlay=0
23902390
build-swift-dynamic-stdlib=0
23912391
build-swift-static-stdlib=1
23922392
swift-objc-interop=0
2393+
swift-enable-compatibility-overrides=0
23932394

23942395
[preset: stdlib_S_standalone_minimal_macho_x86_64,build]
23952396
mixin-preset=

utils/build-script-impl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ KNOWN_SETTINGS=(
193193
sil-verify-all "0" "If enabled, run the SIL verifier after each transform when building Swift files during this build process"
194194
stdlib-deployment-targets "" "space-separated list of targets to configure the Swift standard library to be compiled or cross-compiled for"
195195
swift-objc-interop "" "whether to enable interoperability with Objective-C, default is 1 on Apple platfors, 0 otherwise"
196+
swift-enable-compatibility-overrides "1" "whether to support back-deploying compatibility fixes for newer apps running on older runtimes"
196197

197198
## FREESTANDING Stdlib Options
198199
swift-freestanding-sdk "" "which SDK to use when building the FREESTANDING stdlib"
@@ -1763,6 +1764,7 @@ for host in "${ALL_HOSTS[@]}"; do
17631764
-DSWIFT_STDLIB_BUILD_TYPE:STRING="${SWIFT_STDLIB_BUILD_TYPE}"
17641765
-DSWIFT_STDLIB_ASSERTIONS:BOOL=$(true_false "${SWIFT_STDLIB_ENABLE_ASSERTIONS}")
17651766
-DSWIFT_STDLIB_USE_NONATOMIC_RC:BOOL=$(true_false "${SWIFT_STDLIB_USE_NONATOMIC_RC}")
1767+
-DSWIFT_ENABLE_COMPATIBILITY_OVERRIDES:BOOL=$(true_false "${SWIFT_ENABLE_COMPATIBILITY_OVERRIDES}")
17661768
-DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS:BOOL=$(true_false "${SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS}")
17671769
-DSWIFT_NATIVE_LLVM_TOOLS_PATH:STRING="${native_llvm_tools_path}"
17681770
-DSWIFT_NATIVE_CLANG_TOOLS_PATH:STRING="${native_clang_tools_path}"

0 commit comments

Comments
 (0)