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