Skip to content

Commit 6ab641e

Browse files
committed
Add zippering support
Upstream build system zippering support. Setting the `SWIFT_ENABLE_MACCATALYST` flag will build the compatibility libraries with zippering enabled. Note that AppleClang and LLVM Clang use different flags to write zippered files. The Swift stdlib build doesn't know what clang we're using, so we can't ask it for the compiler ID to determine which whether we're using AppleClang or LLVM clang, hence the nasty `execute_process` trick to figure out whether the compiler that's actually compiling the stdlib knows about the flag or not.
1 parent 7323d32 commit 6ab641e

File tree

6 files changed

+40
-2
lines changed

6 files changed

+40
-2
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_OSX "10.9")
460460
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_IOS "7.0")
461461
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS "9.0")
462462
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS "2.0")
463+
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_MACCATALYST "13.1")
463464

464465
#
465466
# User-configurable debugging options.
@@ -585,6 +586,13 @@ option(SWIFT_THREADING_PACKAGE
585586
Valid package names are 'pthreads', 'darwin', 'linux', 'win32', 'c11', 'none'
586587
or the empty string for the SDK default.")
587588

589+
option(SWIFT_ENABLE_MACCATALYST
590+
"Build the Standard Library and overlays with MacCatalyst support"
591+
FALSE)
592+
593+
set(SWIFT_DARWIN_DEPLOYMENT_VERSION_MACCATALYST "14.5" CACHE STRING
594+
"Minimum deployment target version for macCatalyst")
595+
588596
#
589597
# End of user-configurable options.
590598
#

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,29 @@ function(_add_target_variant_c_compile_link_flags)
8282
DEPLOYMENT_VERSION "${DEPLOYMENT_VERSION}")
8383
list(APPEND result "-target" "${target}")
8484
if(target_variant)
85-
list(APPEND result "-target-variant" "${target_variant}")
85+
# Check if the C compiler supports `-target-variant` flag
86+
# TODO (etcwilde): This is a massive hack to deal with the fact that we
87+
# are lying to cmake about what compiler is being used. Normally we could
88+
# use `check_compiler_flag(C ...)` here. Unfortunately, that uses a
89+
# different compiler since we swap out the C/CXX compiler part way through
90+
# the build.
91+
file(WRITE "${CMAKE_BINARY_DIR}/stdlib/empty" "")
92+
execute_process(
93+
COMMAND
94+
"${CMAKE_C_COMPILER}"
95+
-Wno-unused-command-line-argument
96+
-target-variant x86_64-apple-ios14.5-macabi -x c -c - -o /dev/null
97+
INPUT_FILE
98+
"${CMAKE_BINARY_DIR}/stdlib/empty"
99+
OUTPUT_QUIET ERROR_QUIET
100+
RESULT_VARIABLE
101+
SUPPORTS_TARGET_VARIANT)
102+
103+
if(NOT SUPPORTS_TARGET_VARIANT)
104+
list(APPEND result "-target-variant" "${target_variant}")
105+
else()
106+
list(APPEND result "-darwin-target-variant" "${target_variant}")
107+
endif()
86108
endif()
87109
endif()
88110

stdlib/toolchain/Compatibility51/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ add_swift_target_library("${library_name}" STATIC
1919
DEPLOYMENT_VERSION_TVOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS}
2020
DEPLOYMENT_VERSION_WATCHOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS}
2121

22+
MACCATALYST_BUILD_FLAVOR "zippered"
23+
2224
INSTALL_IN_COMPONENT compiler
2325
INSTALL_WITH_SHARED)
2426

stdlib/toolchain/Compatibility56/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ add_swift_target_library("${library_name}" STATIC
2727
DEPLOYMENT_VERSION_TVOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS}
2828
DEPLOYMENT_VERSION_WATCHOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS}
2929

30+
MACCATALYST_BUILD_FLAVOR "zippered"
31+
3032
INSTALL_IN_COMPONENT compiler
3133
INSTALL_WITH_SHARED)
3234

stdlib/toolchain/CompatibilityConcurrency/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ add_swift_target_library("${library_name}" STATIC
1414
DEPLOYMENT_VERSION_TVOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS}
1515
DEPLOYMENT_VERSION_WATCHOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS}
1616

17+
MACCATALYST_BUILD_FLAVOR "zippered"
18+
1719
INSTALL_IN_COMPONENT compiler
1820
INSTALL_WITH_SHARED)
1921

stdlib/toolchain/CompatibilityThreading/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ add_swift_target_library(swiftCompatibilityThreading OBJECT_LIBRARY
1111
DEPLOYMENT_VERSION_OSX ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_OSX}
1212
DEPLOYMENT_VERSION_IOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_IOS}
1313
DEPLOYMENT_VERSION_TVOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS}
14-
DEPLOYMENT_VERSION_WATCHOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS})
14+
DEPLOYMENT_VERSION_WATCHOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS}
15+
16+
MACCATALYST_BUILD_FLAVOR "zippered")

0 commit comments

Comments
 (0)