Skip to content

Commit 48b9593

Browse files
committed
build: adjust the build to support non-Apple environments
Account for import libraries and the associated layout difference on platforms (e.g. DLLs are placed in `bin`). This is required to enable building the macro path on Windows.
1 parent b23238f commit 48b9593

File tree

4 files changed

+51
-17
lines changed

4 files changed

+51
-17
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,9 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
570570
else()
571571
message(FATAL_ERROR "Unknown BOOTSTRAPPING_MODE '${ASRLF_BOOTSTRAPPING_MODE}'")
572572
endif()
573+
else()
574+
target_link_directories(${target} PRIVATE
575+
${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH})
573576
endif()
574577
575578
if(SWIFT_SWIFT_PARSER)

lib/CMakeLists.txt

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ if (SWIFT_SWIFT_PARSER)
4949
"${CMAKE_SHARED_LIBRARY_SUFFIX}"
5050
OUTPUT_VARIABLE SWIFT_SYNTAX_SHARED_LIBRARIES)
5151

52+
list(TRANSFORM SWIFT_SYNTAX_MODULES PREPEND "${CMAKE_IMPORT_LIBRARY_PREFIX}"
53+
OUTPUT_VARIABLE SWIFT_SYNTAX_IMPORT_LIBRARIES)
54+
list(TRANSFORM SWIFT_SYNTAX_IMPORT_LIBRARIES APPEND
55+
"${CMAKE_IMPORT_LIBRARY_SUFFIX}" OUTPUT_VARIABLE
56+
SWIFT_SYNTAX_IMPORT_LIBRARIES)
57+
5258
# Interface library to collect swiftinterfaces and swiftmodules from
5359
# SwiftSyntax
5460
add_library(swiftSyntaxLibraries INTERFACE)
@@ -67,27 +73,47 @@ if (SWIFT_SWIFT_PARSER)
6773
)
6874
endif()
6975

70-
add_custom_command(
71-
OUTPUT "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
72-
DEPENDS "${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib}"
73-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib} ${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}
74-
${add_origin_rpath}
75-
)
76-
77-
add_custom_target(copy_swiftSyntaxLibrary_${sharedlib}
78-
DEPENDS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
79-
COMMENT "Copying ${sharedlib}"
80-
)
81-
82-
swift_install_in_component(
83-
PROGRAMS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
84-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host"
85-
COMPONENT compiler
86-
)
76+
if(CMAKE_SYSTEM_NAME MATCHES Windows)
77+
add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib}
78+
DEPENDS "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/bin/${sharedlib}"
79+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/bin/${sharedlib} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib})
80+
add_custom_target(copy_swiftSyntaxLibrary_${sharedlib}
81+
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib}
82+
COMMENT "copying ${sharedlib}")
83+
swift_install_in_component(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib}
84+
DESTINATION bin
85+
COMPONENT compiler)
86+
else()
87+
add_custom_command(OUTPUT "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
88+
DEPENDS "${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib}"
89+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib} ${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}
90+
${add_origin_rpath})
91+
add_custom_target(copy_swiftSyntaxLibrary_${sharedlib}
92+
DEPENDS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
93+
COMMENT "Copying ${sharedlib}")
94+
swift_install_in_component(PROGRAMS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
95+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host"
96+
COMPONENT compiler)
97+
endif()
8798

8899
add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxLibrary_${sharedlib})
89100
endforeach()
90101

102+
if(CMAKE_SYSTEM_NAME MATCHES Windows)
103+
foreach(implib ${SWIFT_SYNTAX_IMPORT_LIBRARIES})
104+
add_custom_command(OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib/swift/windows/${implib}
105+
DEPENDS ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/lib/swift/host/${implib}
106+
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/lib/swift/host/${implib} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib/swift/windows/${implib})
107+
add_custom_target(copy_swiftSyntaxLibrary_${implib}
108+
DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib/swift/windows/${implib}
109+
COMMENT "Copying ${implib}")
110+
swift_install_in_component(PROGRAMS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib/swift/windows/${implib}
111+
DESTINATION lib
112+
COMPONENT compiler)
113+
add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxLibrary_${implib})
114+
endforeach()
115+
endif()
116+
91117
# Copy all of the Swift modules from earlyswiftsyntax so they can be found
92118
# in the same relative place within the build directory as in the final
93119
# toolchain.

tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES)
162162
file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host")
163163
list(APPEND RPATH_LIST "$ORIGIN/${relative_hostlib_path}")
164164
endif()
165+
else()
166+
target_link_directories(${target} PRIVATE
167+
${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH})
165168
endif()
166169

167170
if(SWIFT_SWIFT_PARSER)

tools/driver/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# parser is built in.
66
function(add_swift_parser_link_libraries target)
77
if(SWIFT_SWIFT_PARSER)
8+
target_link_directories(${target} PRIVATE
9+
${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH})
810
target_link_libraries(${target}
911
PRIVATE swiftCore)
1012

0 commit comments

Comments
 (0)