Skip to content

Commit 94d554d

Browse files
committed
Overlay: support Catalyst, hooks and backdeployment on Apple platforms
This involves copying the correct source file to generate the magic symbols (the one for SwiftCore would not work here), and listening to the backdeployment configuration of Core. Take the chance to add hooks for vendor overrides. Addresses rdar://156436695
1 parent d7bdbcb commit 94d554d

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-1
lines changed

Runtimes/Core/cmake/interface/SwiftCoreConfig.cmake.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ include("${CMAKE_CURRENT_LIST_DIR}/SwiftCoreTargets.cmake")
44
set(SwiftCore_ENABLE_LIBRARY_EVOLUTION @SwiftCore_ENABLE_LIBRARY_EVOLUTION@)
55

66
set(SwiftCore_ENABLE_VECTOR_TYPES @SwiftCore_ENABLE_VECTOR_TYPES@)
7+
8+
set(SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT @SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT@)

Runtimes/Overlay/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ set(SwiftOverlay_SWIFTC_SOURCE_DIR
4141
"${PROJECT_SOURCE_DIR}/../../"
4242
CACHE FILEPATH "Path to the root source directory of the Swift compiler")
4343

44+
set(${PROJECT_NAME}_VENDOR_MODULE_DIR "${CMAKE_SOURCE_DIR}/cmake/modules/vendor"
45+
CACHE FILEPATH "Location for private build system extension")
46+
4447
include(GNUInstallDirs)
4548

4649
include(gyb)
@@ -51,6 +54,8 @@ include(InstallSwiftInterface)
5154
include(PlatformInfo)
5255
include(ResourceEmbedding)
5356

57+
include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/Settings.cmake" OPTIONAL)
58+
5459
defaulted_option(SwiftOverlay_ENABLE_REFLECTION "Enable runtime support for mirrors and reflection support")
5560

5661
option(SwiftOverlay_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" ON)
@@ -59,6 +64,8 @@ set(SwiftOverlay_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<
5964

6065
option(SwiftOverlay_ENABLE_LIBRARY_EVOLUTION "Generate ABI resilient runtime libraries"
6166
${SwiftCore_ENABLE_LIBRARY_EVOLUTION})
67+
option(SwiftOverlay_ENABLE_BACKDEPLOYMENT_SUPPORT "Add symbols for runtime backdeployment"
68+
${SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT})
6269

6370
add_compile_options(
6471
$<$<COMPILE_LANGUAGE:Swift>:-explicit-module-build>
@@ -71,6 +78,9 @@ add_compile_options(
7178
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-concurrency-module-import>"
7279
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>")
7380

81+
add_compile_definitions(
82+
$<$<BOOL:${SwiftOverlay_ENABLE_BACKDEPLOYMENT_SUPPORT}>:SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT>)
83+
7484
include(ExperimentalFeatures)
7585

7686
add_subdirectory(clang)
@@ -99,3 +109,5 @@ install(FILES
99109
"${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftOverlay/SwiftOverlayConfig.cmake"
100110
"${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftOverlay/SwiftOverlayConfigVersion.cmake"
101111
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SwiftOverlay")
112+
113+
include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/swiftOverlay.cmake" OPTIONAL)

Runtimes/Overlay/clang/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
include(CatalystSupport)
12

23
gyb_expand(float.swift.gyb float.swift)
34

Runtimes/Overlay/cmake/caches/Vendors/Apple/apple-common.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
22
set(BUILD_SHARED_LIBS YES CACHE BOOL "")
33
set(SwiftOverlay_INSTALL_NESTED_SUBDIR OFF CACHE BOOL "")
4+
set(SwiftOverlay_ENABLE_LIBRARY_EVOLUTION ON CACHE BOOL "")
5+
set(SwiftOverlay_ENABLE_BACKDEPLOYMENT_SUPPORT ON CACHE BOOL "")
46

57
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -g -DNDEBUG" CACHE STRING "")
68
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -g -DNDEBUG" CACHE STRING "")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
include(CheckCompilerFlag)
2+
3+
# Add flags for generating the zippered target variant in the build
4+
5+
# Initialize `${PROJECT_NAME}_VARIANT_MODULE_TRIPLE` if the driver is able to emit
6+
# modules for the target variant.
7+
8+
if(${PROJECT_NAME}_COMPILER_VARIANT_TARGET)
9+
add_compile_options(
10+
"$<$<COMPILE_LANGUAGE:C,CXX>:SHELL:-darwin-target-variant ${${PROJECT_NAME}_COMPILER_VARIANT_TARGET}>"
11+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-target-variant ${${PROJECT_NAME}_COMPILER_VARIANT_TARGET}>"
12+
13+
# TODO: Remove me once we have a driver with
14+
# https://github.com/swiftlang/swift-driver/pull/1803
15+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xclang-linker -darwin-target-variant -Xclang-linker ${${PROJECT_NAME}_COMPILER_VARIANT_TARGET}>")
16+
17+
add_link_options(
18+
"$<$<LINK_LANGUAGE:C,CXX>:SHELL:-darwin-target-variant ${${PROJECT_NAME}_COMPILER_VARIANT_TARGET}>"
19+
"$<$<LINK_LANGUAGE:Swift>:SHELL:-target-variant ${${PROJECT_NAME}_COMPILER_VARIANT_TARGET}>"
20+
21+
# TODO: Remove me once we have a driver with
22+
# https://github.com/swiftlang/swift-driver/pull/1803
23+
"$<$<LINK_LANGUAGE:Swift>:SHELL:-Xclang-linker -darwin-target-variant -Xclang-linker ${${PROJECT_NAME}_COMPILER_VARIANT_TARGET}>")
24+
25+
# TODO: Once we are guaranteed to have a driver with the variant module path
26+
# support everywhere, we should integrate this into PlatformInfo.cmake
27+
check_compiler_flag(Swift "-emit-variant-module-path ${CMAKE_CURRENT_BINARY_DIR}/CompilerID/variant.swiftmodule" HAVE_Swift_VARIANT_MODULE_PATH_FLAG)
28+
if(HAVE_Swift_VARIANT_MODULE_PATH_FLAG)
29+
# Get variant module triple
30+
set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info -target ${${PROJECT_NAME}_COMPILER_VARIANT_TARGET})
31+
execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json)
32+
message(CONFIGURE_LOG "Swift target variant info: ${target_info_json}")
33+
34+
35+
string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
36+
set(${PROJECT_NAME}_VARIANT_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used for installed swift{module,interface} files for the target variant")
37+
mark_as_advanced(${PROJECT_NAME}_VARIANT_MODULE_TRIPLE)
38+
message(CONFIGURE_LOG "Swift target variant module triple: ${module_triple}")
39+
endif()
40+
endif()

Runtimes/Resync.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ copy_files("" "Supplemental/Distributed" FILES "Info.plist.in")
105105
# Platform Overlays
106106

107107
# Copy magic linker symbols
108-
copy_library_sources("linker-support" "" "Overlay")
108+
copy_library_sources("linker-support" "public/ClangOverlays" "Overlay")
109109

110110
message(STATUS "Clang[${StdlibSources}/public/ClangOverlays] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/clang")
111111
copy_files(public/ClangOverlays Overlay/clang FILES float.swift.gyb)

0 commit comments

Comments
 (0)