Skip to content

Commit df2fe71

Browse files
committed
Pull libswiftStdlibStubs.a, libswiftRuntime.a into libswiftCore.a
libswiftStdlibStubs.a is meant to be an intermediate built product that's pulled into libswiftCore.a, not its own thing. Add a post-build step for libswiftCore.a to pull all the object files into it from libswiftStdlibStubs.a. (Also, be careful only to do this for private link libraries that are actually targets.) <rdar://problem/23621157>
1 parent 3d79008 commit df2fe71

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,22 @@ function(_add_swift_lipo_target target output)
615615
endif()
616616
endfunction()
617617

618+
# After target 'dst_target' is built from its own object files, merge the
619+
# contents of 'src_target' into it. 'dst_target' and 'src_target' must be
620+
# static-library targets.
621+
function(_target_merge_static_library dst_target src_target)
622+
add_dependencies("${dst_target}" "${src_target}")
623+
set(unpack_dir "${CMAKE_BINARY_DIR}/tmp/unpack/${dst_target}")
624+
add_custom_command(TARGET "${dst_target}" POST_BUILD
625+
COMMAND "${CMAKE_COMMAND}" -E make_directory "${unpack_dir}"
626+
COMMAND pushd "${unpack_dir}"
627+
COMMAND "${CMAKE_AR}" -x "$<TARGET_FILE:${src_target}>"
628+
COMMAND "${CMAKE_AR}" -r "$<TARGET_FILE:${dst_target}>" ./*.o
629+
COMMAND popd
630+
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${unpack_dir}"
631+
)
632+
endfunction()
633+
618634
# Add a single variant of a new Swift library.
619635
#
620636
# Usage:
@@ -1107,6 +1123,17 @@ function(_add_swift_library_single target name)
11071123
LINK_FLAGS " ${link_flags} -L${SWIFTSTATICLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR} -L${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR} -L${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_LIB_SUBDIR}")
11081124
target_link_libraries("${target_static}" PRIVATE
11091125
${SWIFTLIB_SINGLE_PRIVATE_LINK_LIBRARIES})
1126+
1127+
if("${name}" STREQUAL "swiftCore")
1128+
# Have libswiftCore.a include the contents of the private Swift libraries
1129+
# it depends on, so statically linking clients don't have to know about
1130+
# them.
1131+
foreach(private_link_library ${SWIFTLIB_SINGLE_PRIVATE_LINK_LIBRARIES})
1132+
if(TARGET "${private_link_library}")
1133+
_target_merge_static_library("${target_static}" "${private_link_library}")
1134+
endif()
1135+
endforeach()
1136+
endif()
11101137
endif()
11111138

11121139
# Do not add code here.

0 commit comments

Comments
 (0)