Skip to content

Commit dbc0544

Browse files
committed
Non-Darwin SDKs product results in per-arch directories.
Depends on swiftlang/swift#19432 Unix (other than Darwin) and Windows do not support fat binaries. However, the build system was placing the build results in the platform/OS folder, instead of the per-architecture folder. Having two architectures side by side was impossible. After applying the above patch in the Swift compiler, non-Darwin platforms will look into the per-architecture folders, so the sibling projects need to leave the products in the right place. The change is performed in the CMakeList.txt file (which as far as I understand is not used to build Foundation at the moment), and the Python script.
1 parent 771f525 commit dbc0544

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,28 @@ if(ENABLE_TESTING)
408408
LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}:${FOUNDATION_PATH_TO_XCTEST_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
409409
endif()
410410

411+
get_swift_host_arch(SWIFT_HOST_ARCH)
412+
413+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
414+
set(INSTALL_TARGET_DIR "${INSTALL_LIBDIR}/swift/${SWIFT_OS}")
415+
else()
416+
set(INSTALL_TARGET_DIR "${INSTALL_LIBDIR}/swift/${SWIFT_OS}/${SWIFT_HOST_ARCH}")
417+
endif()
418+
411419
install(FILES
412420
${CMAKE_CURRENT_BINARY_DIR}/swift/Foundation.swiftdoc
413421
${CMAKE_CURRENT_BINARY_DIR}/swift/Foundation.swiftmodule
414422
DESTINATION
415-
${CMAKE_INSTALL_FULL_LIBDIR}/swift/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR})
423+
${CMAKE_INSTALL_FULL_LIBDIR}/swift/${CMAKE_SYSTEM_NAME}/${SWIFT_HOST_ARCH})
416424
install(FILES
417425
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}Foundation${CMAKE_SHARED_LIBRARY_SUFFIX}
418426
DESTINATION
419427
${CMAKE_INSTALL_FULL_LIBDIR})
428+
install(FILES
429+
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}Foundation${CMAKE_SHARED_LIBRARY_SUFFIX}
430+
DESTINATION
431+
${INSTALL_TARGET_DIR})
420432
install(FILES
421433
${CMAKE_CURRENT_BINARY_DIR}/plutil
422434
DESTINATION
423435
${CMAKE_INSTALL_FULL_BINDIR})
424-

build.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,18 @@
551551

552552
Configuration.current.variables["LIBS_DIRS"] = LIBS_DIRS
553553

554-
extra_script = """
554+
if "darwin" in triple.lower():
555+
extra_script = "INSTALL_TARGET_DIR=${OS}"
556+
else:
557+
extra_script = "INSTALL_TARGET_DIR=${OS}/${ARCH}"
558+
559+
extra_script += """
560+
555561
rule InstallFoundation
556-
command = mkdir -p "${DSTROOT}/${PREFIX}/lib/swift/${OS}"; $
557-
cp "${BUILD_DIR}/Foundation/${DYLIB_PREFIX}Foundation${DYLIB_SUFFIX}" "${DSTROOT}/${PREFIX}/lib/swift/${OS}"; $
558-
mkdir -p "${DSTROOT}/${PREFIX}/lib/swift_static/${OS}"; $
559-
cp "${BUILD_DIR}/Foundation/${STATICLIB_PREFIX}Foundation${STATICLIB_SUFFIX}" "${DSTROOT}/${PREFIX}/lib/swift_static/${OS}"; $
562+
command = mkdir -p "${DSTROOT}/${PREFIX}/lib/swift/${INSTALL_TARGET_DIR}"; $
563+
cp "${BUILD_DIR}/Foundation/${DYLIB_PREFIX}Foundation${DYLIB_SUFFIX}" "${DSTROOT}/${PREFIX}/lib/swift/${INSTALL_TARGET_DIR}"; $
564+
mkdir -p "${DSTROOT}/${PREFIX}/lib/swift_static/${INSTALL_TARGET_DIR}"; $
565+
cp "${BUILD_DIR}/Foundation/${STATICLIB_PREFIX}Foundation${STATICLIB_SUFFIX}" "${DSTROOT}/${PREFIX}/lib/swift_static/${INSTALL_TARGET_DIR}"; $
560566
mkdir -p "${DSTROOT}/${PREFIX}/lib/swift/${OS}/${ARCH}"; $
561567
cp "${BUILD_DIR}/Foundation/Foundation.swiftmodule" "${DSTROOT}/${PREFIX}/lib/swift/${OS}/${ARCH}/"; $
562568
cp "${BUILD_DIR}/Foundation/Foundation.swiftdoc" "${DSTROOT}/${PREFIX}/lib/swift/${OS}/${ARCH}/"; $

cmake/modules/SwiftSupport.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,35 @@ function(add_swift_executable executable)
152152
add_swift_target(${executable} ${ARGN})
153153
endfunction()
154154

155+
# Returns the current achitecture name in a variable
156+
#
157+
# Usage:
158+
# get_swift_host_arch(result_var_name)
159+
#
160+
# If the current architecture is supported by Swift, sets ${result_var_name}
161+
# with the sanitized host architecture name derived from CMAKE_SYSTEM_PROCESSOR.
162+
function(get_swift_host_arch result_var_name)
163+
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
164+
set("${result_var_name}" "x86_64" PARENT_SCOPE)
165+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
166+
set("${result_var_name}" "aarch64" PARENT_SCOPE)
167+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
168+
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
169+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
170+
set("${result_var_name}" "powerpc64le" PARENT_SCOPE)
171+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
172+
set("${result_var_name}" "s390x" PARENT_SCOPE)
173+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
174+
set("${result_var_name}" "armv6" PARENT_SCOPE)
175+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
176+
set("${result_var_name}" "armv7" PARENT_SCOPE)
177+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
178+
set("${result_var_name}" "x86_64" PARENT_SCOPE)
179+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
180+
set("${result_var_name}" "itanium" PARENT_SCOPE)
181+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
182+
set("${result_var_name}" "i686" PARENT_SCOPE)
183+
else()
184+
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
185+
endif()
186+
endfunction()

0 commit comments

Comments
 (0)