Skip to content

Commit f023bde

Browse files
committed
Base override section names on swift version
This patch automates maintaining the right compatibility override section names so we don't need to remember to update them by hand with each version. The expansions look like '"__swift" "5" "9" "_hooks"' and '"__s" "5" "9" "async_hook"'. Note: The section names can only grow to be 16 characters long. If we see explosions regarding these names, that could be why.
1 parent 7059248 commit f023bde

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ set(SWIFT_ANALYZE_CODE_COVERAGE FALSE CACHE STRING
268268
# SWIFT_VERSION is deliberately /not/ cached so that an existing build directory
269269
# can be reused when a new version of Swift comes out (assuming the user hasn't
270270
# manually set it as part of their own CMake configuration).
271-
set(SWIFT_VERSION "5.9")
271+
set(SWIFT_VERSION_MAJOR 5)
272+
set(SWIFT_VERSION_MINOR 9)
273+
set(SWIFT_VERSION "${SWIFT_VERSION_MAJOR}.${SWIFT_VERSION_MINOR}")
272274

273275
set(SWIFT_VENDOR "" CACHE STRING
274276
"The vendor name of the Swift compiler")

include/swift/Runtime/CMakeConfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
#cmakedefine01 SWIFT_BNI_OS_BUILD
88
#cmakedefine01 SWIFT_BNI_XCODE_BUILD
99

10+
#cmakedefine SWIFT_VERSION_MAJOR "@SWIFT_VERSION_MAJOR@"
11+
#cmakedefine SWIFT_VERSION_MINOR "@SWIFT_VERSION_MINOR@"
12+
1013
#endif

stdlib/public/CompatibilityOverride/CompatibilityOverride.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#include "swift/Runtime/Concurrency.h"
8686
#include "swift/Runtime/Metadata.h"
8787
#include "swift/Runtime/Once.h"
88+
#include "swift/Runtime/CMakeConfig.h"
8889
#include <type_traits>
8990

9091
namespace swift {
@@ -153,8 +154,17 @@ namespace swift {
153154
// Override section name computation. `COMPATIBILITY_OVERRIDE_SECTION_NAME` will
154155
// resolve to string literal containing the appropriate section name for the
155156
// current library.
156-
#define COMPATIBILITY_OVERRIDE_SECTION_NAME_swiftRuntime "__swift58_hooks"
157-
#define COMPATIBILITY_OVERRIDE_SECTION_NAME_swift_Concurrency "__s58async_hook"
157+
// Turns into '__swift<major><minor>_hooks'
158+
#define COMPATIBILITY_OVERRIDE_SECTION_NAME_swiftRuntime "__swift" \
159+
SWIFT_VERSION_MAJOR \
160+
SWIFT_VERSION_MINOR \
161+
"_hooks"
162+
163+
// Turns into '__s<major><minor>async_hook'
164+
#define COMPATIBILITY_OVERRIDE_SECTION_NAME_swift_Concurrency "__s" \
165+
SWIFT_VERSION_MAJOR \
166+
SWIFT_VERSION_MINOR \
167+
"async_hook"
158168

159169
#define COMPATIBILITY_OVERRIDE_SECTION_NAME \
160170
COMPATIBILITY_CONCAT(COMPATIBILITY_OVERRIDE_SECTION_NAME_, \

0 commit comments

Comments
 (0)