Skip to content

Commit 9f80a9c

Browse files
committed
Copy legacy layouts to stdlib build directory
This adds a new copy-legacy-layouts-${platform}-${arch} target for each platform and architecture that the standard library is built for. If the platform and architecture has a corresponding layout file in stdlib/public/legacy_layouts/${platform}/layouts-${arch}.yaml, the target copies this file to the build directory; otherwise, it does nothing. When building Swift code, the subroutines in SwiftSource.cmake add a dependency on this target from each Swift code target. Finally, we ensure that the YAML files are copied into the toolchain package when building a toolchain.
1 parent 093d483 commit 9f80a9c

File tree

12 files changed

+4273
-0
lines changed

12 files changed

+4273
-0
lines changed

cmake/modules/SwiftSource.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,16 @@ function(_compile_swift_files
434434
string(REPLACE ";" "'\n'" source_files_quoted "${source_files}")
435435
file(WRITE "${file_path}" "'${source_files_quoted}'")
436436

437+
# If this platform/architecture combo supports backward deployment to old
438+
# Objective-C runtimes, we need to copy a YAML file with legacy type layout
439+
# information to the build directory so that the compiler can find it.
440+
#
441+
# See stdlib/CMakeLists.txt and TypeConverter::TypeConverter() in
442+
# lib/IRGen/GenType.cpp.
443+
set(SWIFTFILE_PLATFORM "${SWIFT_SDK_${SWIFTFILE_SDK}_LIB_SUBDIR}")
444+
set(copy_legacy_layouts_dep
445+
"copy-legacy-layouts-${SWIFTFILE_PLATFORM}-${SWIFTFILE_ARCHITECTURE}")
446+
437447
add_custom_command_target(
438448
dependency_target
439449
COMMAND
@@ -447,6 +457,7 @@ function(_compile_swift_files
447457
${file_path} ${source_files} ${SWIFTFILE_DEPENDS}
448458
${swift_ide_test_dependency}
449459
${obj_dirs_dependency_target}
460+
${copy_legacy_layouts_dep}
450461
COMMENT "Compiling ${first_output}")
451462
set("${dependency_target_out_var_name}" "${dependency_target}" PARENT_SCOPE)
452463

stdlib/CMakeLists.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,48 @@ swift_create_stdlib_targets("swift-stdlib" "sibopt" TRUE)
107107
swift_create_stdlib_targets("swift-stdlib" "sibgen" TRUE)
108108
swift_create_stdlib_targets("swift-test-stdlib" "" FALSE)
109109

110+
foreach(sdk ${SWIFT_SDKS})
111+
foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
112+
set(platform "${SWIFT_SDK_${sdk}_LIB_SUBDIR}")
113+
set(input "${SWIFT_SOURCE_DIR}/stdlib/public/legacy_layouts/${platform}/layouts-${arch}.yaml")
114+
set(output "${SWIFTLIB_DIR}/${platform}/layouts-${arch}.yaml")
115+
116+
if(EXISTS "${input}")
117+
# Copy the input file to the build directory.
118+
add_custom_command(
119+
OUTPUT "${output}"
120+
DEPENDS "${input}"
121+
COMMAND
122+
"${CMAKE_COMMAND}" -E copy
123+
"${input}"
124+
"${output}")
125+
126+
# Define a target for this so that we can depend on it when
127+
# building Swift sources.
128+
add_custom_target(
129+
"copy-legacy-layouts-${platform}-${arch}"
130+
DEPENDS "${output}"
131+
SOURCES "${input}")
132+
133+
# Make sure we ultimately always do this as part of building the
134+
# standard library. In practice we'll do this earlier if at least
135+
# one Swift source file has changed.
136+
add_dependencies(
137+
"swift-stdlib-${platform}-${arch}"
138+
"copy-legacy-layouts-${platform}-${arch}")
139+
140+
swift_install_in_component(stdlib
141+
FILES ${input}
142+
DESTINATION "lib/swift/${platform}/")
143+
else()
144+
# Add a dummy target that does nothing so we can still depend on it
145+
# later without checking if the input files exist.
146+
add_custom_target(
147+
"copy-legacy-layouts-${platform}-${arch}")
148+
endif()
149+
endforeach()
150+
endforeach()
151+
110152
add_subdirectory(public)
111153
add_subdirectory(private)
112154
add_subdirectory(tools)

0 commit comments

Comments
 (0)