Skip to content

build: adjust the build to support non-Apple environments #68258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
else()
message(FATAL_ERROR "Unknown BOOTSTRAPPING_MODE '${ASRLF_BOOTSTRAPPING_MODE}'")
endif()
else()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elseif(CMAKE_SYSTEM_NAME MATCHES Windows)?

target_link_directories(${target} PRIVATE
${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH})
endif()

if(SWIFT_SWIFT_PARSER)
Expand Down
60 changes: 43 additions & 17 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ if (SWIFT_SWIFT_PARSER)
"${CMAKE_SHARED_LIBRARY_SUFFIX}"
OUTPUT_VARIABLE SWIFT_SYNTAX_SHARED_LIBRARIES)

list(TRANSFORM SWIFT_SYNTAX_MODULES PREPEND "${CMAKE_IMPORT_LIBRARY_PREFIX}"
OUTPUT_VARIABLE SWIFT_SYNTAX_IMPORT_LIBRARIES)
list(TRANSFORM SWIFT_SYNTAX_IMPORT_LIBRARIES APPEND
"${CMAKE_IMPORT_LIBRARY_SUFFIX}" OUTPUT_VARIABLE
SWIFT_SYNTAX_IMPORT_LIBRARIES)

# Interface library to collect swiftinterfaces and swiftmodules from
# SwiftSyntax
add_library(swiftSyntaxLibraries INTERFACE)
Expand All @@ -64,27 +70,47 @@ if (SWIFT_SWIFT_PARSER)
)
endif()

add_custom_command(
OUTPUT "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
DEPENDS "${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib} ${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}
${add_origin_rpath}
)

add_custom_target(copy_swiftSyntaxLibrary_${sharedlib}
DEPENDS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
COMMENT "Copying ${sharedlib}"
)

swift_install_in_component(
PROGRAMS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host"
COMPONENT compiler
)
if(CMAKE_SYSTEM_NAME MATCHES Windows)
add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib}
DEPENDS "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/bin/${sharedlib}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/bin/${sharedlib} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib})
add_custom_target(copy_swiftSyntaxLibrary_${sharedlib}
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib}
COMMENT "copying ${sharedlib}")
swift_install_in_component(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib}
DESTINATION bin
COMPONENT compiler)
else()
add_custom_command(OUTPUT "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
DEPENDS "${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib} ${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}
${add_origin_rpath})
add_custom_target(copy_swiftSyntaxLibrary_${sharedlib}
DEPENDS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
COMMENT "Copying ${sharedlib}")
swift_install_in_component(PROGRAMS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host"
COMPONENT compiler)
endif()

add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxLibrary_${sharedlib})
endforeach()

if(CMAKE_SYSTEM_NAME MATCHES Windows)
foreach(implib ${SWIFT_SYNTAX_IMPORT_LIBRARIES})
add_custom_command(OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib/swift/windows/${implib}
DEPENDS ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/lib/swift/host/${implib}
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})
add_custom_target(copy_swiftSyntaxLibrary_${implib}
DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib/swift/windows/${implib}
COMMENT "Copying ${implib}")
swift_install_in_component(PROGRAMS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib/swift/windows/${implib}
DESTINATION lib
COMPONENT compiler)
add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxLibrary_${implib})
endforeach()
endif()

# Copy all of the Swift modules from earlyswiftsyntax so they can be found
# in the same relative place within the build directory as in the final
# toolchain.
Expand Down
3 changes: 3 additions & 0 deletions tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES)
# Add rpath to the host Swift libraries.
file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host")
list(APPEND RPATH_LIST "$ORIGIN/${relative_hostlib_path}")
else()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMAKE_SYSTEM_NAME MATCHES Windows/SWIFT_HOST_VARIANT_SDK MATCHES WINDOWS

target_link_directories(${target} PRIVATE
${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH})
endif()

# For the "end step" of bootstrapping configurations on Darwin, need to be
Expand Down
2 changes: 2 additions & 0 deletions tools/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# parser is built in.
function(add_swift_parser_link_libraries target)
Copy link
Contributor

@bnbarham bnbarham Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I've missed this function in the past.

    target_link_libraries(${target}
                          PRIVATE swiftCore)

I have no idea how all the other tools are working, but we should fix this later (don't worry about it for this PR/Windows, we'll fix up on main after). This should be being added by _add_swift_runtime_link_flags from add_swift_host_tool but apparently isn't. Maybe autolinking is kicking in on Darwin?

Anyway, TLDR: target_link_directories is already done in _add_swift_runtime_link_flags, so this change shouldn't be needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was needed as otherwise I ended up with references to libraries that are not available.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how that could be, are you sure that wasn't before updating _add_swift_runtime_link_flags? add_swift_host_tool has:

  # Once the new Swift parser is linked in, every host tool has Swift modules.
  if (SWIFT_SWIFT_PARSER AND NOT ASHT_DOES_NOT_USE_SWIFT)
    set(ASHT_HAS_SWIFT_MODULES ON)
  endif()

  if (ASHT_HAS_SWIFT_MODULES)
    _add_swift_runtime_link_flags(${executable} "../lib" "${ASHT_BOOTSTRAPPING}")
  endif()

And you've added target_link_libraries there.

if(SWIFT_SWIFT_PARSER)
target_link_directories(${target} PRIVATE
${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH})
target_link_libraries(${target}
PRIVATE swiftCore)

Expand Down