Skip to content

Commit 4c480d5

Browse files
committed
Add and install a parent module map for Swift shims. NFC intended.
Header search path for Swift shims is "usr/lib/swift". Don't rely on clang looking for module maps in immediate subdirectories like "shims" but add a module map to "usr/lib/swift" sourcing "shims" modules. rdar://106677321
1 parent 2658192 commit 4c480d5

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

stdlib/cmake/modules/StdlibOptions.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,16 @@ option(SWIFT_STDLIB_USE_RELATIVE_PROTOCOL_WITNESS_TABLES
250250
"Use relative protocol witness tables"
251251
FALSE)
252252

253+
if("${SWIFT_HOST_VARIANT_SDK}" IN_LIST SWIFT_DARWIN_PLATFORMS)
254+
set(SWIFT_STDLIB_INSTALL_PARENT_MODULE_FOR_SHIMS_default TRUE)
255+
else()
256+
set(SWIFT_STDLIB_INSTALL_PARENT_MODULE_FOR_SHIMS_default FALSE)
257+
endif()
258+
259+
option(SWIFT_STDLIB_INSTALL_PARENT_MODULE_FOR_SHIMS
260+
"Install a parent module map for Swift shims."
261+
${SWIFT_STDLIB_INSTALL_PARENT_MODULE_FOR_SHIMS_default})
262+
253263
set(SWIFT_RUNTIME_FIXED_BACKTRACER_PATH "" CACHE STRING
254264
"If set, provides a fixed path to the swift-backtrace binary. This
255265
will disable dynamic determination of the path and will also disable

stdlib/public/SwiftShims/swift/shims/CMakeLists.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@ foreach(input ${sources})
6363
list(APPEND outputs "${output_dir_static}/${input}")
6464
endif()
6565
endforeach()
66+
if (SWIFT_STDLIB_INSTALL_PARENT_MODULE_FOR_SHIMS)
67+
# Copy the module map into the parent directory. Using "parent.modulemap"
68+
# instead of putting "module.modulemap" into the parent module to avoid
69+
# module redefinition conflicts with the toolchain.
70+
add_custom_command(
71+
OUTPUT "${output_dir}/../module.modulemap"
72+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/parent.modulemap"
73+
COMMAND
74+
"${CMAKE_COMMAND}" "-E" "copy_if_different"
75+
"${CMAKE_CURRENT_SOURCE_DIR}/parent.modulemap"
76+
"${output_dir}/../module.modulemap"
77+
COMMENT "Copying parent.modulemap to ${output_dir}")
78+
list(APPEND outputs "${output_dir}/../module.modulemap")
79+
if(SWIFT_BUILD_STATIC_STDLIB)
80+
add_custom_command(
81+
OUTPUT "${output_dir_static}/../module.modulemap"
82+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/parent.modulemap"
83+
COMMAND
84+
"${CMAKE_COMMAND}" "-E" "copy_if_different"
85+
"${CMAKE_CURRENT_SOURCE_DIR}/parent.modulemap"
86+
"${output_dir_static}/../module.modulemap"
87+
COMMENT "Copying parent.modulemap to ${output_dir_static}")
88+
list(APPEND outputs "${output_dir_static}/../module.modulemap")
89+
endif()
90+
endif()
6691
# Put the output dir itself last so that it isn't considered the primary output.
6792
list(APPEND outputs "${output_dir}")
6893

@@ -173,17 +198,43 @@ if(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
173198
COMMENT "Symlinking headers for bootstrapping0")
174199

175200
add_dependencies(${target_name} copy_shim_headers)
201+
202+
if (SWIFT_STDLIB_INSTALL_PARENT_MODULE_FOR_SHIMS)
203+
set(modulemap_target_name "symlink-modulemap-bootstrapping${bootstrapping}")
204+
add_custom_command_target(unused_var
205+
COMMAND
206+
"${CMAKE_COMMAND}" "-E" "make_directory" "${outdir}"
207+
COMMAND
208+
"${CMAKE_COMMAND}" "-E" ${cmake_symlink_option}
209+
"${output_dir}/../module.modulemap" "${outdir}/module.modulemap"
210+
211+
CUSTOM_TARGET_NAME ${modulemap_target_name}
212+
OUTPUT "${outdir}/module.modulemap"
213+
COMMENT "Symlinking shims modulemap for bootstrapping0")
214+
add_dependencies(${modulemap_target_name} copy_shim_headers)
215+
add_dependencies(${target_name} ${modulemap_target_name})
216+
endif()
176217
endforeach()
177218
endif()
178219

179220
swift_install_in_component(FILES ${sources}
180221
DESTINATION "lib/swift/shims"
181222
COMPONENT stdlib)
223+
if (SWIFT_STDLIB_INSTALL_PARENT_MODULE_FOR_SHIMS)
224+
swift_install_in_component(FILES "${output_dir}/../module.modulemap"
225+
DESTINATION "lib/swift"
226+
COMPONENT stdlib)
227+
endif()
182228

183229
if(SWIFT_BUILD_STATIC_STDLIB)
184230
swift_install_in_component(FILES ${sources}
185231
DESTINATION "lib/swift_static/shims"
186232
COMPONENT stdlib)
233+
if (SWIFT_STDLIB_INSTALL_PARENT_MODULE_FOR_SHIMS)
234+
swift_install_in_component(FILES "${output_dir_static}/../module.modulemap"
235+
DESTINATION "lib/swift_static"
236+
COMPONENT stdlib)
237+
endif()
187238
endif()
188239

189240
# Install Clang headers under the Swift library so that an installed Swift's
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extern module SwiftShims "shims/module.modulemap"
2+
extern module _SwiftConcurrencyShims "shims/module.modulemap"
3+
extern module SwiftOverlayShims "shims/module.modulemap"

0 commit comments

Comments
 (0)