Skip to content

Commit 47c56bd

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 2c3c3c1 commit 47c56bd

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
@@ -573,6 +573,9 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
573573
else()
574574
message(FATAL_ERROR "Unknown BOOTSTRAPPING_MODE '${ASRLF_BOOTSTRAPPING_MODE}'")
575575
endif()
576+
else()
577+
target_link_directories(${target} PRIVATE
578+
${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/Windows/x86_64)
576579
endif()
577580

578581
if(SWIFT_SWIFT_PARSER)

lib/CMakeLists.txt

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ if (SWIFT_SWIFT_PARSER)
4646
"${CMAKE_SHARED_LIBRARY_SUFFIX}"
4747
OUTPUT_VARIABLE SWIFT_SYNTAX_SHARED_LIBRARIES)
4848

49+
list(TRANSFORM SWIFT_SYNTAX_MODULES PREPEND "${CMAKE_IMPORT_LIBRARY_PREFIX}"
50+
OUTPUT_VARIABLE SWIFT_SYNTAX_IMPORT_LIBRARIES)
51+
list(TRANSFORM SWIFT_SYNTAX_IMPORT_LIBRARIES APPEND
52+
"${CMAKE_IMPORT_LIBRARY_SUFFIX}" OUTPUT_VARIABLE
53+
SWIFT_SYNTAX_IMPORT_LIBRARIES)
54+
4955
# Interface library to collect swiftinterfaces and swiftmodules from
5056
# SwiftSyntax
5157
add_library(swiftSyntaxLibraries INTERFACE)
@@ -64,27 +70,47 @@ if (SWIFT_SWIFT_PARSER)
6470
)
6571
endif()
6672

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

8596
add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxLibrary_${sharedlib})
8697
endforeach()
8798

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

tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES)
161161
# Add rpath to the host Swift libraries.
162162
file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host")
163163
list(APPEND RPATH_LIST "$ORIGIN/${relative_hostlib_path}")
164+
else()
165+
target_link_directories(${target} PRIVATE
166+
${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/Windows/x86_64)
164167
endif()
165168

166169
# For the "end step" of bootstrapping configurations on Darwin, need to be

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/Windows/x86_64)
810
target_link_libraries(${target}
911
PRIVATE swiftCore)
1012

0 commit comments

Comments
 (0)