Skip to content

Commit 581392b

Browse files
committed
[build] rewrite #21707 and swiftCore/swiftRuntime CMake config, so that it doesn't break
cross-compilation Passing swift_core_private_link_libraries to PRIVATE_LINK_LIBRARIES only works either when building a single host SDK alone or when needed by all SDKs, so move all that configuration to a swift_core_private_libraries() function that's called from add_swift_target_library() for each SDK/arch instead. Also, generate a static-executable-args.lnk for each ELF SDK, rather than just for linux if it is the host SDK.
1 parent 103cc32 commit 581392b

File tree

3 files changed

+48
-41
lines changed

3 files changed

+48
-41
lines changed

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,12 @@ function(add_swift_target_library name)
19311931
set(swiftlib_module_dependency_targets)
19321932
set(swiftlib_private_link_libraries_targets)
19331933

1934+
if(name STREQUAL swiftCore)
1935+
# This initializes swiftlib_private_link_libraries_targets for swiftCore,
1936+
# so don't move it away from the variable declaration just above.
1937+
swift_core_private_libraries(${sdk} ${arch} swiftlib_private_link_libraries_targets)
1938+
endif()
1939+
19341940
if(NOT BUILD_STANDALONE)
19351941
foreach(mod ${swiftlib_module_depends_flattened})
19361942
if(DEFINED maccatalyst_build_flavor)

stdlib/public/core/CMakeLists.txt

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -236,23 +236,27 @@ set(SWIFTLIB_GYB_SOURCES
236236
set(GROUP_INFO_JSON_FILE ${CMAKE_CURRENT_SOURCE_DIR}/GroupInfo.json)
237237
set(swift_core_link_flags "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}")
238238
set(swift_core_framework_depends)
239-
set(swift_core_private_link_libraries)
240239
set(swift_stdlib_compile_flags "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}")
241240

242-
if(SWIFT_PRIMARY_VARIANT_SDK STREQUAL CYGWIN)
243-
# TODO(compnerd) cache this variable to permit re-configuration
244-
execute_process(COMMAND "cygpath" "-u" "$ENV{SYSTEMROOT}" OUTPUT_VARIABLE ENV_SYSTEMROOT)
245-
list(APPEND swift_core_private_link_libraries "${ENV_SYSTEMROOT}/system32/psapi.dll")
246-
elseif(SWIFT_PRIMARY_VARIANT_SDK STREQUAL FREEBSD)
247-
find_library(EXECINFO_LIBRARY execinfo)
248-
list(APPEND swift_core_private_link_libraries ${EXECINFO_LIBRARY})
249-
elseif(SWIFT_PRIMARY_VARIANT_SDK STREQUAL LINUX)
250-
if(SWIFT_BUILD_STATIC_STDLIB)
251-
list(APPEND swift_core_private_link_libraries)
241+
function(swift_core_private_libraries sdk arch libraries_var_name)
242+
set(private_link_libraries)
243+
if(${sdk} STREQUAL CYGWIN)
244+
if(${sdk} STREQUAL ${SWIFT_HOST_VARIANT_SDK})
245+
# TODO(compnerd) cache this variable to permit re-configuration
246+
execute_process(COMMAND "cygpath" "-u" "$ENV{SYSTEMROOT}" OUTPUT_VARIABLE ENV_SYSTEMROOT)
247+
list(APPEND private_link_libraries "${ENV_SYSTEMROOT}/system32/psapi.dll")
248+
else()
249+
message(FATAL_ERROR "CYGWIN cross-compilation doesn't know where to find psapi.dll.")
250+
endif()
251+
elseif(${sdk} STREQUAL FREEBSD)
252+
find_library(EXECINFO_LIBRARY execinfo)
253+
list(APPEND private_link_libraries ${EXECINFO_LIBRARY})
254+
elseif(${sdk} STREQUAL WINDOWS)
255+
list(APPEND private_link_libraries shell32;DbgHelp)
252256
endif()
253-
elseif(SWIFT_PRIMARY_VARIANT_SDK STREQUAL WINDOWS)
254-
list(APPEND swift_core_private_link_libraries shell32;DbgHelp)
255-
endif()
257+
258+
set(${libraries_var_name} ${private_link_libraries} PARENT_SCOPE)
259+
endfunction()
256260

257261
option(SWIFT_CHECK_ESSENTIAL_STDLIB
258262
"Check core standard library layering by linking its essential subset"
@@ -298,8 +302,6 @@ set(swiftCore_common_options
298302
${SWIFTLIB_GYB_SOURCES}
299303
LINK_FLAGS
300304
${swift_core_link_flags}
301-
PRIVATE_LINK_LIBRARIES
302-
${swift_core_private_link_libraries}
303305
INCORPORATE_OBJECT_LIBRARIES
304306
${swift_core_incorporate_object_libraries}
305307
FRAMEWORK_DEPENDS

stdlib/public/runtime/CMakeLists.txt

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,6 @@ set(swift_runtime_library_compile_flags ${swift_runtime_compile_flags})
8282
list(APPEND swift_runtime_library_compile_flags -DswiftCore_EXPORTS)
8383
list(APPEND swift_runtime_library_compile_flags -I${SWIFT_SOURCE_DIR}/stdlib/include/llvm/Support -I${SWIFT_SOURCE_DIR}/include)
8484

85-
set(sdk "${SWIFT_HOST_VARIANT_SDK}")
86-
if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
87-
set(static_binary_lnk_file_list)
88-
string(TOLOWER "${sdk}" lowercase_sdk)
89-
90-
# Generate the static-executable-args.lnk file used for ELF systems (eg linux)
91-
set(linkfile "${lowercase_sdk}/static-executable-args.lnk")
92-
add_custom_command_target(swift_static_binary_${sdk}_args
93-
COMMAND
94-
"${CMAKE_COMMAND}" -E copy
95-
"${SWIFT_SOURCE_DIR}/utils/static-executable-args.lnk"
96-
"${SWIFTSTATICLIB_DIR}/${linkfile}"
97-
OUTPUT
98-
"${SWIFTSTATICLIB_DIR}/${linkfile}"
99-
DEPENDS
100-
"${SWIFT_SOURCE_DIR}/utils/static-executable-args.lnk")
101-
102-
list(APPEND static_binary_lnk_file_list ${swift_static_binary_${sdk}_args})
103-
swift_install_in_component(FILES "${SWIFTSTATICLIB_DIR}/${linkfile}"
104-
DESTINATION "lib/swift_static/${lowercase_sdk}"
105-
COMPONENT stdlib)
106-
add_dependencies(stdlib ${static_binary_lnk_file_list})
107-
add_custom_target(static_binary_magic ALL DEPENDS ${static_binary_lnk_file_list})
108-
endif()
109-
11085
add_swift_target_library(swiftRuntime OBJECT_LIBRARY
11186
${swift_runtime_sources}
11287
${swift_runtime_objc_sources}
@@ -148,6 +123,30 @@ add_swift_target_library(swiftImageRegistrationObjectCOFF
148123
INSTALL_IN_COMPONENT none)
149124

150125
foreach(sdk ${SWIFT_SDKS})
126+
if(SWIFT_BUILD_STATIC_STDLIB AND "${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF")
127+
set(static_binary_lnk_file_list)
128+
string(TOLOWER "${sdk}" lowercase_sdk)
129+
130+
# Generate the static-executable-args.lnk file used for ELF systems (eg linux)
131+
set(linkfile "${lowercase_sdk}/static-executable-args.lnk")
132+
add_custom_command_target(swift_static_binary_${sdk}_args
133+
COMMAND
134+
"${CMAKE_COMMAND}" -E copy
135+
"${SWIFT_SOURCE_DIR}/utils/static-executable-args.lnk"
136+
"${SWIFTSTATICLIB_DIR}/${linkfile}"
137+
OUTPUT
138+
"${SWIFTSTATICLIB_DIR}/${linkfile}"
139+
DEPENDS
140+
"${SWIFT_SOURCE_DIR}/utils/static-executable-args.lnk")
141+
142+
list(APPEND static_binary_lnk_file_list ${swift_static_binary_${sdk}_args})
143+
swift_install_in_component(FILES "${SWIFTSTATICLIB_DIR}/${linkfile}"
144+
DESTINATION "lib/swift_static/${lowercase_sdk}"
145+
COMPONENT stdlib)
146+
add_dependencies(stdlib ${static_binary_lnk_file_list})
147+
add_custom_target(static_binary_${lowercase_sdk}_magic ALL DEPENDS ${static_binary_lnk_file_list})
148+
endif()
149+
151150
foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
152151
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")
153152
set(arch_suffix "${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")

0 commit comments

Comments
 (0)