From 0bedc79ca5841b298a0c301da8050a47fa50d2e4 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 21 Sep 2024 12:57:29 -0600 Subject: [PATCH] CMake: Pull swift-testing from the Swift toolchain This confirmed works on Xcode 16, and Xcode 16.1 Beta 2, with CMake 3.28 or higher. On linux, the 6.0.0 release from swiftly is still missing my libstdc++ workaround, so it needs a snapshot to work. --- Meta/CMake/FindSwiftTesting.cmake | 59 ++++++---------- ...rnalProjects-to-use-console-with-Nin.patch | 68 ------------------- 2 files changed, 19 insertions(+), 108 deletions(-) delete mode 100644 Meta/CMake/patches/swift-testing/0001-CMake-Allow-ExternalProjects-to-use-console-with-Nin.patch diff --git a/Meta/CMake/FindSwiftTesting.cmake b/Meta/CMake/FindSwiftTesting.cmake index 5ece653dcd1..7f46c36d96b 100644 --- a/Meta/CMake/FindSwiftTesting.cmake +++ b/Meta/CMake/FindSwiftTesting.cmake @@ -1,45 +1,24 @@ # Finds the swift-testing library # On Apple platforms, this is a framework included in the Xcode release -# FIXME: Using Xcode's library actually doesn't work for rpath reasons -# When swift-testing ships better toolchain CMake support, we'll need to revisit this - -include(FetchContent) - -# Allow the Ninja generators to output messages as they happen by assigning -# these jobs to the 'console' job pool -set(console_access "") -if(CMAKE_GENERATOR MATCHES "^Ninja") - set(console_access - USES_TERMINAL_CONFIGURE YES - USES_TERMINAL_BUILD YES - USES_TERMINAL_INSTALL YES - ) -endif() - -set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE OPT_IN) -FetchContent_Declare(SwiftTesting - GIT_REPOSITORY https://github.com/swiftlang/swift-testing.git - GIT_TAG d00d46920f9bb35342ad29398ea4740a2bbf3d38 - PATCH_COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_LIST_DIR}/patches/git-patch.cmake" - "${CMAKE_CURRENT_LIST_DIR}/patches/swift-testing//0001-CMake-Allow-ExternalProjects-to-use-console-with-Nin.patch" - OVERRIDE_FIND_PACKAGE - SYSTEM - ${console_access} +find_library(SWIFT_TESTING NAMES Testing + PATHS ${SWIFT_LIBRARY_SEARCH_PATHS} ) - -block() - add_cxx_compile_options(-Wno-error) - set(SwiftTesting_MACRO "") - FetchContent_MakeAvailable(SwiftTesting) - add_cxx_compile_options(-Werror) -endblock() - -if (NOT TARGET SwiftTesting::SwiftTesting) - # FIXME: This should be an interface property on the target itself, if the maintainers intend - # for the repository to be fetch-content-able - set_property(TARGET Testing APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "$<$:SHELL:-load-plugin-executable ${CMAKE_BINARY_DIR}/bin/TestingMacros#TestingMacros>") - add_library(SwiftTesting::SwiftTesting ALIAS Testing) - set(SwiftTesting_LIBRARIES SwiftTesting::SwiftTesting) +if (SWIFT_TESTING) + if (NOT TARGET SwiftTesting::SwiftTesting) + add_library(SwiftTesting::SwiftTesting IMPORTED UNKNOWN) + message(STATUS "Found SwiftTesting: ${SWIFT_TESTING}") + cmake_path(GET SWIFT_TESTING PARENT_PATH _SWIFT_TESTING_DIR) + set_target_properties(SwiftTesting::SwiftTesting PROPERTIES + IMPORTED_LOCATION "${SWIFT_TESTING}" + INTERFACE_LINK_DIRECTORIES "${_SWIFT_TESTING_DIR}" + ) + if (UNIX AND NOT APPLE) + cmake_path(GET _SWIFT_TESTING_DIR PARENT_PATH _SWIFT_TESTING_TARGETLESS_DIR) + set_target_properties(SwiftTesting::SwiftTesting PROPERTIES + INTERFACE_COMPILE_OPTIONS "$<$:SHELL:-load-plugin-library ${_SWIFT_TESTING_TARGETLESS_DIR}/host/plugins/libTestingMacros.so>" + ) + endif() + endif() + set(SwiftTesting_FOUND TRUE) endif() -set(SwiftTesting_FOUND TRUE) diff --git a/Meta/CMake/patches/swift-testing/0001-CMake-Allow-ExternalProjects-to-use-console-with-Nin.patch b/Meta/CMake/patches/swift-testing/0001-CMake-Allow-ExternalProjects-to-use-console-with-Nin.patch deleted file mode 100644 index 148eaf7927a..00000000000 --- a/Meta/CMake/patches/swift-testing/0001-CMake-Allow-ExternalProjects-to-use-console-with-Nin.patch +++ /dev/null @@ -1,68 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Andrew Kaster -Date: Mon, 26 Aug 2024 21:35:45 -0600 -Subject: [PATCH] [CMake] Allow ExternalProjects to use console with Ninja - generator - -Also stop forcing the SwiftMacros project to build every rebuild. ---- - Sources/CMakeLists.txt | 13 ++++++++++++- - Sources/TestingMacros/CMakeLists.txt | 14 +++++++++++++- - 2 files changed, 25 insertions(+), 2 deletions(-) - -diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt -index 83a9a2b2330c9847ebac89e273c6ade9bf398a25..d917509ba47c2ddaf6b7a2d7d17de2afaabc68fd 100644 ---- a/Sources/CMakeLists.txt -+++ b/Sources/CMakeLists.txt -@@ -43,10 +43,21 @@ if(SwiftTesting_MACRO STREQUAL "") - # Build and install the plugin into the current build directry. - set(SwiftTesting_MACRO_INSTALL_PREFIX "${CMAKE_BINARY_DIR}") - -+ # Allow the Ninja generators to output messages as they happen by assigning -+ # these jobs to the 'console' job pool -+ set(SwiftTesting_ConsoleAccess "") -+ if(CMAKE_GENERATOR MATCHES "^Ninja") -+ set(SwiftTesting_ConsoleAccess -+ USES_TERMINAL_CONFIGURE YES -+ USES_TERMINAL_BUILD YES -+ USES_TERMINAL_INSTALL YES) -+ endif() -+ - ExternalProject_Add(TestingMacros - PREFIX "tm" - SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/TestingMacros" -- BUILD_ALWAYS ON -+ BUILD_ALWAYS OFF -+ ${SwiftTesting_ConsoleAccess} - CMAKE_ARGS - -DCMAKE_MAKE_PROGRAM=${SwiftTesting_MACRO_MAKE_PROGRAM} - -DCMAKE_Swift_COMPILER=${SwiftTesting_MACRO_Swift_COMPILER} -diff --git a/Sources/TestingMacros/CMakeLists.txt b/Sources/TestingMacros/CMakeLists.txt -index a45663025a43adf39d17f0d94d692c9bf6092194..aa9939079ff18dee00288bf7fb0c92c124438228 100644 ---- a/Sources/TestingMacros/CMakeLists.txt -+++ b/Sources/TestingMacros/CMakeLists.txt -@@ -28,11 +28,23 @@ if(SwiftTesting_BuildMacrosAsExecutables) - # When building the macro plugin as an executable, clone and build - # swift-syntax. - include(FetchContent) -+ -+ # Allow the Ninja generators to output messages as they happen by assigning -+ # these jobs to the 'console' job pool -+ set(SwiftTesting_ConsoleAccess "") -+ if(CMAKE_GENERATOR MATCHES "^Ninja") -+ set(SwiftTesting_ConsoleAccess -+ USES_TERMINAL_CONFIGURE YES -+ USES_TERMINAL_BUILD YES -+ USES_TERMINAL_INSTALL YES) -+ endif() -+ - set(FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/_d) - # TODO: Update GIT_TAG to the 6.0 release tag once it is available. - FetchContent_Declare(SwiftSyntax - GIT_REPOSITORY https://github.com/swiftlang/swift-syntax -- GIT_TAG 27b74edd5de625d0e399869a5af08f1501af8837) -+ GIT_TAG 27b74edd5de625d0e399869a5af08f1501af8837 -+ ${SwiftTesting_ConsoleAccess}) - FetchContent_MakeAvailable(SwiftSyntax) - endif() -