Skip to content

Commit 2fad626

Browse files
authored
When building stdlib, pass -prespecialize-generic-metadata from CMake, and respect the flag in IRGenModule::shouldPrespecializeGenericMetadata (#38946)
1 parent 60b1a0d commit 2fad626

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

lib/IRGen/IRGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ bool IRGenModule::shouldPrespecializeGenericMetadata() {
17021702
(Triple.isOSDarwin() ||
17031703
(Triple.isOSLinux() && !(Triple.isARM() && Triple.isArch32Bit())));
17041704
if (canPrespecializeTarget && isStandardLibrary()) {
1705-
return true;
1705+
return IRGen.Opts.PrespecializeGenericMetadata;
17061706
}
17071707
auto &context = getSwiftModule()->getASTContext();
17081708
auto deploymentAvailability =

stdlib/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ else()
4444
set(SWIFT_BUILD_TEST_SUPPORT_MODULES_default FALSE)
4545
endif()
4646

47+
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
48+
set(SWIFT_STDLIB_ENABLE_PRESPECIALIZATION_default TRUE)
49+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "LINUX")
50+
set(SWIFT_STDLIB_ENABLE_PRESPECIALIZATION_default TRUE)
51+
else()
52+
set(SWIFT_STDLIB_ENABLE_PRESPECIALIZATION_default FALSE)
53+
endif()
54+
4755
#
4856
# User-configurable options for the standard library.
4957
#
@@ -82,6 +90,10 @@ option(SWIFT_BUILD_TEST_SUPPORT_MODULES
8290
option(SWIFT_FREESTANDING_FLAVOR
8391
"When building the FREESTANDING stdlib, which build style to use (options: apple, linux)")
8492

93+
option(SWIFT_STDLIB_ENABLE_PRESPECIALIZATION
94+
"Should stdlib be built with generic metadata prespecialization enabled. Defaults to On on Darwin and on "
95+
"${SWIFT_STDLIB_ENABLE_PRESPECIALIZATION_default}")
96+
8597
set(SWIFT_STDLIB_ENABLE_LTO OFF CACHE STRING "Build Swift stdlib with LTO. One
8698
must specify the form of LTO by setting this to one of: 'full', 'thin'. This
8799
option only affects the standard library and runtime, not tools.")

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,10 @@ function(add_swift_target_library name)
16731673
"-Xfrontend;-disable-implicit-distributed-module-import")
16741674
endif()
16751675

1676+
if(SWIFTLIB_IS_STDLIB AND SWIFT_STDLIB_ENABLE_PRESPECIALIZATION)
1677+
list(APPEND SWIFTLIB_SWIFT_COMPILE_FLAGS "-Xfrontend;-prespecialize-generic-metadata")
1678+
endif()
1679+
16761680
# If we are building this library for targets, loop through the various
16771681
# SDKs building the variants of this library.
16781682
list_intersect(

utils/build-presets.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,10 @@ swift-enable-compatibility-overrides=0
24332433
swift-runtime-macho-no-dyld=1
24342434
swift-stdlib-single-threaded-runtime=1
24352435
swift-stdlib-os-versioning=0
2436-
extra-cmake-options=-DSWIFT_ENABLE_DISPATCH:BOOL=FALSE -DSWIFT_IMPLICIT_CONCURRENCY_IMPORT:BOOL=FALSE
2436+
extra-cmake-options=
2437+
-DSWIFT_ENABLE_DISPATCH:BOOL=FALSE
2438+
-DSWIFT_IMPLICIT_CONCURRENCY_IMPORT:BOOL=FALSE
2439+
-DSWIFT_STDLIB_ENABLE_PRESPECIALIZATION:BOOL=FALSE
24372440

24382441
[preset: stdlib_S_standalone_minimal_macho_x86_64,build]
24392442
mixin-preset=

0 commit comments

Comments
 (0)