From c3ed92c864fa894c5d86ec28f6bb1fcd5272f8b5 Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Fri, 31 May 2024 13:18:04 -0700 Subject: [PATCH 1/2] Add new single-module and foundation-toolchain-module modes to CMake build --- CMakeLists.txt | 7 ++ Sources/BitCollections/CMakeLists.txt | 20 ++-- Sources/CMakeLists.txt | 4 +- Sources/Collections/CMakeLists.txt | 93 ++++++++++++++++--- Sources/DequeModule/CMakeLists.txt | 20 ++-- Sources/HashTreeCollections/CMakeLists.txt | 20 ++-- Sources/HeapModule/CMakeLists.txt | 20 ++-- .../CMakeLists.txt | 16 +++- Sources/OrderedCollections/CMakeLists.txt | 20 ++-- Sources/RopeModule/CMakeLists.txt | 20 ++-- 10 files changed, 178 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98d73f801..939a29e48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,13 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows OR CMAKE_SYSTEM_NAME STREQUAL Darwin) option(BUILD_SHARED_LIBS "Build shared libraries by default" YES) endif() +option(COLLECTIONS_SINGLE_MODULE "Build as a single module" NO) +option(COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE "Build a module for Foundation in the toolchain" NO) + +if(COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE) + set(COLLECTIONS_SINGLE_MODULE YES) +endif() + include(CTest) include(SwiftSupport) diff --git a/Sources/BitCollections/CMakeLists.txt b/Sources/BitCollections/CMakeLists.txt index 837cab503..b287e5b2c 100644 --- a/Sources/BitCollections/CMakeLists.txt +++ b/Sources/BitCollections/CMakeLists.txt @@ -7,7 +7,7 @@ Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information #]] -add_library(BitCollections +list(APPEND COLLECTIONS_BIT_SOURCES "BitArray/BitArray+BitwiseOperations.swift" "BitArray/BitArray+ChunkedBitsIterators.swift" "BitArray/BitArray+Codable.swift" @@ -65,10 +65,16 @@ add_library(BitCollections "Shared/UInt+Tricks.swift" "Shared/_Word.swift" ) -target_link_libraries(BitCollections PRIVATE - InternalCollectionsUtilities) -set_target_properties(BitCollections PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +set_property(GLOBAL APPEND PROPERTY COLLECTIONS_BIT_SOURCES ${COLLECTIONS_BIT_SOURCES}) -_install_target(BitCollections) -set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS BitCollections) +if(NOT COLLECTIONS_SINGLE_MODULE) + add_library(BitCollections + ${COLLECTIONS_BIT_SOURCES}) + target_link_libraries(BitCollections PRIVATE + InternalCollectionsUtilities) + set_target_properties(BitCollections PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + _install_target(BitCollections) + set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS BitCollections) +endif() diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 988bc2106..29525bf55 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -8,10 +8,12 @@ See https://swift.org/LICENSE.txt for license information #]] add_subdirectory(BitCollections) -add_subdirectory(Collections) add_subdirectory(DequeModule) add_subdirectory(HashTreeCollections) add_subdirectory(HeapModule) add_subdirectory(OrderedCollections) add_subdirectory(RopeModule) add_subdirectory(InternalCollectionsUtilities) + +# Add Collections last so it can find global properties set by sub directories +add_subdirectory(Collections) diff --git a/Sources/Collections/CMakeLists.txt b/Sources/Collections/CMakeLists.txt index f8be93bd3..26bca4df6 100644 --- a/Sources/Collections/CMakeLists.txt +++ b/Sources/Collections/CMakeLists.txt @@ -7,17 +7,82 @@ Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information #]] -add_library(Collections - "Collections.swift") -target_link_libraries(Collections PRIVATE - BitCollections - DequeModule - HeapModule - OrderedCollections - HashTreeCollections - ) -set_target_properties(Collections PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) - -_install_target(Collections) -set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS Collections) +if(COLLECTIONS_SINGLE_MODULE) + if (COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE) + set(COLLECTIONS_MODULE_NAME _FoundationCollections) + set(COLLECTIONS_MODULE_TYPE STATIC) + else() + set(COLLECTIONS_MODULE_NAME Collections) + set(COLLECTIONS_MODULE_TYPE) + endif() + + get_property(COLLECTIONS_UTILITIES_SOURCES GLOBAL PROPERTY COLLECTIONS_UTILITIES_SOURCES) + list(TRANSFORM COLLECTIONS_UTILITIES_SOURCES PREPEND "../InternalCollectionsUtilities/") + get_property(COLLECTIONS_BIT_SOURCES GLOBAL PROPERTY COLLECTIONS_BIT_SOURCES) + list(TRANSFORM COLLECTIONS_BIT_SOURCES PREPEND "../BitCollections/") + get_property(COLLECTIONS_DEQUE_SOURCES GLOBAL PROPERTY COLLECTIONS_DEQUE_SOURCES) + list(TRANSFORM COLLECTIONS_DEQUE_SOURCES PREPEND "../DequeModule/") + get_property(COLLECTIONS_HEAP_SOURCES GLOBAL PROPERTY COLLECTIONS_HEAP_SOURCES) + list(TRANSFORM COLLECTIONS_HEAP_SOURCES PREPEND "../HeapModule/") + get_property(COLLECTIONS_ORDERED_SOURCES GLOBAL PROPERTY COLLECTIONS_ORDERED_SOURCES) + list(TRANSFORM COLLECTIONS_ORDERED_SOURCES PREPEND "../OrderedCollections/") + get_property(COLLECTIONS_HASHTREE_SOURCES GLOBAL PROPERTY COLLECTIONS_HASHTREE_SOURCES) + list(TRANSFORM COLLECTIONS_HASHTREE_SOURCES PREPEND "../HashTreeCollections/") + + add_library(${COLLECTIONS_MODULE_NAME} ${COLLECTIONS_MODULE_TYPE} + "Collections.swift" + ${COLLECTIONS_UTILITIES_SOURCES} + ${COLLECTIONS_BIT_SOURCES} + ${COLLECTIONS_DEQUE_SOURCES} + ${COLLECTIONS_HEAP_SOURCES} + ${COLLECTIONS_ORDERED_SOURCES} + ${COLLECTIONS_HASHTREE_SOURCES}) + + if(COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE) + get_property(COLLECTIONS_ROPE_SOURCES GLOBAL PROPERTY COLLECTIONS_ROPE_SOURCES) + list(TRANSFORM COLLECTIONS_ROPE_SOURCES PREPEND "../RopeModule/") + target_sources(${COLLECTIONS_MODULE_NAME} PRIVATE + ${COLLECTIONS_ROPE_SOURCES}) + target_compile_options(${COLLECTIONS_MODULE_NAME} PRIVATE + -allowable-client FoundationEssentials) + endif() + + target_compile_definitions(${COLLECTIONS_MODULE_NAME} PRIVATE COLLECTIONS_SINGLE_MODULE) + set_target_properties(${COLLECTIONS_MODULE_NAME} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + if(COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE) + # Install only the swift module and not the library + if(BUILD_SHARED_LIBS) + set(swift swift) + else() + set(swift swift_static) + endif() + get_swift_host_os(swift_os) + get_swift_host_arch(swift_arch) + install(FILES $/${COLLECTIONS_MODULE_NAME}.swiftdoc + DESTINATION lib/${swift}/${swift_os}/${COLLECTIONS_MODULE_NAME}.swiftmodule + RENAME ${swift_arch}.swiftdoc) + install(FILES $/${COLLECTIONS_MODULE_NAME}.swiftmodule + DESTINATION lib/${swift}/${swift_os}/${COLLECTIONS_MODULE_NAME}.swiftmodule + RENAME ${swift_arch}.swiftmodule) + else() + _install_target(${COLLECTIONS_MODULE_NAME}) + endif() + set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS ${COLLECTIONS_MODULE_NAME}) +else() + add_library(Collections + "Collections.swift") + target_link_libraries(Collections PRIVATE + BitCollections + DequeModule + HeapModule + OrderedCollections + HashTreeCollections + ) + set_target_properties(Collections PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + _install_target(Collections) + set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS Collections) +endif() diff --git a/Sources/DequeModule/CMakeLists.txt b/Sources/DequeModule/CMakeLists.txt index bb92f8733..69f32e4dc 100644 --- a/Sources/DequeModule/CMakeLists.txt +++ b/Sources/DequeModule/CMakeLists.txt @@ -7,7 +7,7 @@ Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information #]] -add_library(DequeModule +list(APPEND COLLECTIONS_DEQUE_SOURCES "Deque+Codable.swift" "Deque+Collection.swift" "Deque+CustomReflectable.swift" @@ -26,10 +26,16 @@ add_library(DequeModule "_DequeSlot.swift" "_UnsafeWrappedBuffer.swift" ) -target_link_libraries(DequeModule PRIVATE - InternalCollectionsUtilities) -set_target_properties(DequeModule PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +set_property(GLOBAL APPEND PROPERTY COLLECTIONS_DEQUE_SOURCES ${COLLECTIONS_DEQUE_SOURCES}) -_install_target(DequeModule) -set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS DequeModule) +if(NOT COLLECTIONS_SINGLE_MODULE) + add_library(DequeModule + ${COLLECTIONS_DEQUE_SOURCES}) + target_link_libraries(DequeModule PRIVATE + InternalCollectionsUtilities) + set_target_properties(DequeModule PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + _install_target(DequeModule) + set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS DequeModule) +endif() diff --git a/Sources/HashTreeCollections/CMakeLists.txt b/Sources/HashTreeCollections/CMakeLists.txt index 14587f7bf..ead04f08a 100644 --- a/Sources/HashTreeCollections/CMakeLists.txt +++ b/Sources/HashTreeCollections/CMakeLists.txt @@ -7,7 +7,7 @@ Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information #]] -add_library(HashTreeCollections +list(APPEND COLLECTIONS_HASHTREE_SOURCES "HashNode/_AncestorHashSlots.swift" "HashNode/_Bitmap.swift" "HashNode/_Bucket.swift" @@ -94,10 +94,16 @@ add_library(HashTreeCollections "TreeSet/TreeSet+SetAlgebra union.swift" "TreeSet/TreeSet.swift" ) -target_link_libraries(HashTreeCollections PRIVATE - InternalCollectionsUtilities) -set_target_properties(HashTreeCollections PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +set_property(GLOBAL APPEND PROPERTY COLLECTIONS_HASHTREE_SOURCES ${COLLECTIONS_HASHTREE_SOURCES}) -_install_target(HashTreeCollections) -set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS HashTreeCollections) +if(NOT COLLECTIONS_SINGLE_MODULE) + add_library(HashTreeCollections + ${COLLECTIONS_HASHTREE_SOURCES}) + target_link_libraries(HashTreeCollections PRIVATE + InternalCollectionsUtilities) + set_target_properties(HashTreeCollections PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + _install_target(HashTreeCollections) + set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS HashTreeCollections) +endif() diff --git a/Sources/HeapModule/CMakeLists.txt b/Sources/HeapModule/CMakeLists.txt index 3bc611fbd..d24faae2a 100644 --- a/Sources/HeapModule/CMakeLists.txt +++ b/Sources/HeapModule/CMakeLists.txt @@ -7,17 +7,23 @@ Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information #]] -add_library(HeapModule +list(APPEND COLLECTIONS_HEAP_SOURCES "_HeapNode.swift" "Heap.swift" "Heap+Descriptions.swift" "Heap+ExpressibleByArrayLiteral.swift" "Heap+Invariants.swift" "Heap+UnsafeHandle.swift") -target_link_libraries(HeapModule PRIVATE - InternalCollectionsUtilities) -set_target_properties(HeapModule PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +set_property(GLOBAL APPEND PROPERTY COLLECTIONS_HEAP_SOURCES ${COLLECTIONS_HEAP_SOURCES}) -_install_target(HeapModule) -set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS HeapModule) +if(NOT COLLECTIONS_SINGLE_MODULE) + add_library(HeapModule + ${COLLECTIONS_HEAP_SOURCES}) + target_link_libraries(HeapModule PRIVATE + InternalCollectionsUtilities) + set_target_properties(HeapModule PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + _install_target(HeapModule) + set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS HeapModule) +endif() diff --git a/Sources/InternalCollectionsUtilities/CMakeLists.txt b/Sources/InternalCollectionsUtilities/CMakeLists.txt index bd38f9d99..e0941f8be 100644 --- a/Sources/InternalCollectionsUtilities/CMakeLists.txt +++ b/Sources/InternalCollectionsUtilities/CMakeLists.txt @@ -7,7 +7,7 @@ Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information #]] -add_library(InternalCollectionsUtilities +list(APPEND COLLECTIONS_UTILITIES_SOURCES "autogenerated/Debugging.swift" "autogenerated/Descriptions.swift" "autogenerated/RandomAccessCollection+Offsets.swift" @@ -27,8 +27,14 @@ add_library(InternalCollectionsUtilities "_SortedCollection.swift" "_UniqueCollection.swift" ) -set_target_properties(InternalCollectionsUtilities PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +set_property(GLOBAL APPEND PROPERTY COLLECTIONS_UTILITIES_SOURCES ${COLLECTIONS_UTILITIES_SOURCES}) -_install_target(InternalCollectionsUtilities) -set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS InternalCollectionsUtilities) +if(NOT COLLECTIONS_SINGLE_MODULE) + add_library(InternalCollectionsUtilities + ${COLLECTIONS_UTILITIES_SOURCES}) + set_target_properties(InternalCollectionsUtilities PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + _install_target(InternalCollectionsUtilities) + set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS InternalCollectionsUtilities) +endif() diff --git a/Sources/OrderedCollections/CMakeLists.txt b/Sources/OrderedCollections/CMakeLists.txt index 0b3604e63..333c7e0a3 100644 --- a/Sources/OrderedCollections/CMakeLists.txt +++ b/Sources/OrderedCollections/CMakeLists.txt @@ -7,7 +7,7 @@ Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information #]] -add_library(OrderedCollections +list(APPEND COLLECTIONS_ORDERED_SOURCES "HashTable/_HashTable.swift" "HashTable/_HashTable+Bucket.swift" "HashTable/_HashTable+BucketIterator.swift" @@ -71,10 +71,16 @@ add_library(OrderedCollections "OrderedSet/OrderedSet.swift" "Utilities/_UnsafeBitset.swift" ) -target_link_libraries(OrderedCollections PRIVATE - InternalCollectionsUtilities) -set_target_properties(OrderedCollections PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +set_property(GLOBAL APPEND PROPERTY COLLECTIONS_ORDERED_SOURCES ${COLLECTIONS_ORDERED_SOURCES}) -_install_target(OrderedCollections) -set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS OrderedCollections) +if(NOT COLLECTIONS_SINGLE_MODULE) + add_library(OrderedCollections + ${COLLECTIONS_ORDERED_SOURCES}) + target_link_libraries(OrderedCollections PRIVATE + InternalCollectionsUtilities) + set_target_properties(OrderedCollections PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + _install_target(OrderedCollections) + set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS OrderedCollections) +endif() diff --git a/Sources/RopeModule/CMakeLists.txt b/Sources/RopeModule/CMakeLists.txt index 7324a0119..60a78007d 100644 --- a/Sources/RopeModule/CMakeLists.txt +++ b/Sources/RopeModule/CMakeLists.txt @@ -7,7 +7,7 @@ Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information #]] -add_library(_RopeModule +list(APPEND COLLECTIONS_ROPE_SOURCES "BigString/Basics/BigString+Metrics.swift" "BigString/Basics/BigString+Index.swift" "BigString/Basics/BigString+Summary.swift" @@ -85,10 +85,16 @@ add_library(_RopeModule "Utilities/String.Index+ABI.swift" "Utilities/Optional Utilities.swift" ) -target_link_libraries(_RopeModule PRIVATE - InternalCollectionsUtilities) -set_target_properties(_RopeModule PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +set_property(GLOBAL APPEND PROPERTY COLLECTIONS_ROPE_SOURCES ${COLLECTIONS_ROPE_SOURCES}) -_install_target(_RopeModule) -set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS _RopeModule) +if(NOT COLLECTIONS_SINGLE_MODULE) + add_library(_RopeModule + ${COLLECTIONS_ROPE_SOURCES}) + target_link_libraries(_RopeModule PRIVATE + InternalCollectionsUtilities) + set_target_properties(_RopeModule PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + _install_target(_RopeModule) + set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS _RopeModule) +endif() From d10a328f79966ada76c0f5e1f13922363e1d7da9 Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Mon, 3 Jun 2024 15:13:19 -0700 Subject: [PATCH 2/2] Fix allowable client flag syntax --- Sources/Collections/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Collections/CMakeLists.txt b/Sources/Collections/CMakeLists.txt index 26bca4df6..d562606a0 100644 --- a/Sources/Collections/CMakeLists.txt +++ b/Sources/Collections/CMakeLists.txt @@ -44,7 +44,7 @@ if(COLLECTIONS_SINGLE_MODULE) target_sources(${COLLECTIONS_MODULE_NAME} PRIVATE ${COLLECTIONS_ROPE_SOURCES}) target_compile_options(${COLLECTIONS_MODULE_NAME} PRIVATE - -allowable-client FoundationEssentials) + "SHELL:$<$:-Xfrontend -allowable-client -Xfrontend FoundationEssentials>") endif() target_compile_definitions(${COLLECTIONS_MODULE_NAME} PRIVATE COLLECTIONS_SINGLE_MODULE)