Skip to content

[CMake] Update MinSizeRel configuration for Apple platforms... #78667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Runtimes/Core/cmake/caches/Vendors/Apple/apple-common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ set(SwiftCore_ENABLE_VECTOR_TYPES ON CACHE BOOL "")
set(SwiftCore_ENABLE_RUNTIME_FUNCTION_COUNTERS ON CACHE BOOL "")
set(SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT ON CACHE BOOL "")
set(SwiftCore_ENABLE_FILESYSTEM_SUPPORT ON CACHE BOOL "")

set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -g -DNDEBUG" CACHE STRING "")
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -g -DNDEBUG" CACHE STRING "")
set(CMAKE_Swift_FLAGS_MINSIZEREL "-Osize -g" CACHE STRING "")
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ set(CMAKE_Swift_COMPILER_TARGET "arm64-apple-bridgeos${CMAKE_OSX_DEPLOYMENT_TARG

set(SwiftCore_ARCH_SUBDIR arm64)
set(SwiftCore_PLATFORM_SUBDIR freestanding)
set(CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")

include("${CMAKE_CURRENT_LIST_DIR}/apple-common.cmake")
11 changes: 8 additions & 3 deletions Runtimes/Core/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,14 @@ target_compile_options(swiftCore PRIVATE
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-autolinking-runtime-compatibility-concurrency>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-objc-attr-requires-foundation-module>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -require-explicit-availability=ignore>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -prespecialize-generic-metadata>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xllvm -sil-inline-generics>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xllvm -sil-partial-specialization>")
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -prespecialize-generic-metadata>")

if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
# Using these in MinSizeRel would result in a 15% increase in the binary size
target_compile_options(swiftCore PRIVATE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably keep these in the target_compile_options above and let generator expressions handle the condition like so:

"$<$<AND:$<COMPILE_LANGUAGE:Swift>,$<NOT:$<CONFIG:MinSizeRel>>>:SHELL:-Xllvm -sil-inline-generics>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,$<NOT:$<CONFIG:MinSizeRel>>>:SHELL:-Xllvm -sil-partial-specialization>"

But I'm also not going to require that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointer -- I searched for CMAKE_BUILD_TYPE in the documentation of the generator expressions, and I assumed it was not supported.

"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xllvm -sil-inline-generics>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xllvm -sil-partial-specialization>")
endif()

target_compile_definitions(swiftCore PRIVATE
$<$<BOOL:${SwiftCore_ENABLE_REFLECTION}>:-DSWIFT_ENABLE_REFLECTION>
Expand Down