@@ -424,6 +424,47 @@ add_swift_target_library(swiftCore
424424 zippered
425425 )
426426
427+ # Backward deployment of Span on Apple platforms is implemented via the
428+ # libswiftCompatibilitySpan.dylib shim.
429+ #
430+ # When a binary built with an older deployment target is run with a new
431+ # standard library, the symbols that were previously in the backward
432+ # compatibility shim are now in the standard library. To ensure the
433+ # dynamic linker continues to find these symbols, the compatibility
434+ # shim must be replaced by a symlink to the standard library.
435+ #
436+ # Since we're building the "new" standard library here, we create this
437+ # symlink in the same directory, from libswiftCompatibilitySpan.dylib to
438+ # libswiftCore.dylib.
439+ #
440+ # The sources for the real libswiftCompatibilitySpan.dylib are found in
441+ # stdlib/toolchain/CompatibilitySpan. When running a binary with an old
442+ # standard library, this dynamic library must be present at run time.
443+ #
444+ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
445+ foreach (sdk ${SWIFT_SDKS} )
446+ set (lib_dir "${SWIFT_SDK_${sdk} _LIB_SUBDIR}" )
447+ set (lib_path "${SWIFTLIB_DIR} /${lib_dir} " )
448+ set (compat_lib_name "${lib_path} /libswiftCompatibilitySpan.dylib" )
449+
450+ # This doesn't depend on libswiftCore.dylib because we don't actually need
451+ # for it to exist to create the symlink, nor is there any need to recreate
452+ # the symlink if the dylib changes.
453+ add_custom_command_target(unused_var
454+ CUSTOM_TARGET_NAME "swiftCompatibilitySpan-symlink-${lib_dir} "
455+ OUTPUT "${compat_lib_name} "
456+ COMMAND ${CMAKE_COMMAND} "-E" "create_symlink" "${lib_path} /libswiftCore.dylib" "${compat_lib_name} " )
457+ foreach (ARCH ${SWIFT_SDK_${sdk} _ARCHITECTURES})
458+ add_dependencies ("swiftCore-${lib_dir} -${ARCH} " "swiftCompatibilitySpan-symlink-${lib_dir} " )
459+ endforeach ()
460+
461+ swift_install_symlink_component(stdlib
462+ LINK_NAME libswiftCompatibilitySpan.dylib
463+ TARGET libswiftCore.dylib
464+ DESTINATION "lib/swift/${lib_dir} " )
465+ endforeach ()
466+ endif ()
467+
427468# Embedded standard library - embedded libraries are built as .swiftmodule only,
428469# i.e. there is no .o or .a file produced (no binary code is actually produced)
429470# and only users of a library are going to actually compile any needed code.
0 commit comments