diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 33fff3dd9..748b15643 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -45,6 +45,50 @@ jobs: # Workaround https://github.com/nektos/act/issues/1875 uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main + cmake-lists: + name: Check cmake lists + # Workaround https://github.com/nektos/act/issues/1875 + uses: apple/swift-nio/.github/workflows/cmake_tests.yml@main + with: + image: "swift:6.4-noble" + cmake_version: "3.29.6" + c_compiler: "clang" + cxx_compiler: "clang++" + update_cmake_lists_config: >- + { + "targets": [ + { "name": "CNIOAtomics", "type": "source", "exceptions": [] }, + { "name": "CNIOPosix", "type": "source", "exceptions": [] }, + { "name": "CNIOLinux", "type": "source", "exceptions": [] }, + { "name": "CNIOLLHTTP", "type": "source", "exceptions": [] }, + { "name": "CNIODarwin", "type": "source", "exceptions": [] }, + { "name": "CNIOSHA1", "type": "source", "exceptions": [] }, + { "name": "CNIOOpenBSD", "type": "source", "exceptions": [] }, + { "name": "CNIOFreeBSD", "type": "source", "exceptions": [] }, + { "name": "CNIOWindows", "type": "source", "exceptions": [] }, + { "name": "CNIOWASI", "type": "source", "exceptions": [] }, + { "name": "NIOCore", "type": "source", "exceptions": [] }, + { "name": "_NIODataStructures", "type": "source", "exceptions": [] }, + { "name": "_NIOBase64", "type": "source", "exceptions": [] }, + { "name": "NIOEmbedded", "type": "source", "exceptions": [] }, + { "name": "NIOPosix", "type": "source", "exceptions": [] }, + { "name": "NIO", "type": "source", "exceptions": [] }, + { "name": "_NIOConcurrency", "type": "source", "exceptions": [] }, + { "name": "NIOFoundationEssentialsCompat", "type": "source", "exceptions": [] }, + { "name": "NIOFoundationCompat", "type": "source", "exceptions": [] }, + { "name": "NIOConcurrencyHelpers", "type": "source", "exceptions": [] }, + { "name": "NIOHTTP1", "type": "source", "exceptions": [] }, + { "name": "NIOWebSocket", "type": "source", "exceptions": [] }, + { "name": "NIOTLS", "type": "source", "exceptions": [] }, + { "name": "NIOTestUtils", "type": "source", "exceptions": [] }, + { "name": "NIOFS", "type": "source", "exceptions": [] }, + { "name": "NIOFSFoundationCompat", "type": "source", "exceptions": [] }, + { "name": "_NIOFileSystem", "type": "source", "exceptions": [] }, + { "name": "_NIOFileSystemFoundationCompat", "type": "source", "exceptions": [] }, + { "name": "NIOFileSystem", "type": "source", "exceptions": [] } + ] + } + construct-integration-test-matrix: name: Construct integration test matrix runs-on: ubuntu-latest diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..854db791b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,127 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +cmake_minimum_required(VERSION 3.29) + +project(SwiftNIO + LANGUAGES C Swift) + +# SwiftNIO's headers use Clang's nullability qualifiers (`_Nonnull` and friends), which other C +# compilers reject, so fail early with a clear message rather than deep inside the build. +if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang") + message(FATAL_ERROR + "SwiftNIO must be built with a Clang C compiler, but the C compiler is " + "'${CMAKE_C_COMPILER}' (${CMAKE_C_COMPILER_ID}). Set CC=clang or pass " + "-DCMAKE_C_COMPILER= when configuring.") +endif() + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) + +include(SwiftNIOSupport) + +option(BUILD_SHARED_LIBS "Build shared libraries by default" YES) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) + +set(SWIFT_NIO_COMPILE_OPTIONS + -package-name swift-nio + -enable-experimental-feature Lifetimes + -enable-upcoming-feature MemberImportVisibility +) + +set(CMAKE_POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}) + +if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND NOT CMAKE_CROSSCOMPILING) + set(CMAKE_AR "/usr/bin/ar") + set(CMAKE_C_ARCHIVE_CREATE " crs ") + set(CMAKE_RANLIB "/usr/bin/ranlib") +endif() + +if(CMAKE_SYSTEM_NAME STREQUAL Windows) + # We can only link against the DLL version of the MSVC runtime library for now. + set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY MultiThreadedDLL) + set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL) + if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2) + # We need to set the static library prefix to "lib" so that we can link against the static libraries. + set(CMAKE_STATIC_LIBRARY_PREFIX_Swift "lib") + endif() +endif() + +if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) + find_package(dispatch CONFIG) + find_package(Foundation CONFIG) +endif() + +include(FetchContent) + +set(_NIO_SAVED_BUILD_EXAMPLES ${BUILD_EXAMPLES}) +set(_NIO_SAVED_BUILD_TESTING ${BUILD_TESTING}) +# swift-atomics builds its tests when BUILD_TESTING is on. +set(BUILD_TESTING NO) + +find_package(swift-atomics CONFIG) +if(NOT swift-atomics_FOUND) + message("-- Vending swift-atomics") + FetchContent_Declare(SwiftAtomics + GIT_REPOSITORY https://github.com/apple/swift-atomics + GIT_TAG 1.3.1) + FetchContent_MakeAvailable(SwiftAtomics) +endif() + +find_package(SwiftCollections CONFIG) +if(NOT SwiftCollections_FOUND) + message("-- Vending swift-collections") + FetchContent_Declare(SwiftCollections + GIT_REPOSITORY https://github.com/apple/swift-collections + GIT_TAG 1.7.6) + FetchContent_MakeAvailable(SwiftCollections) +endif() + +find_package(SwiftSystem CONFIG) +if(NOT SwiftSystem_FOUND) + message("-- Vending swift-system") + FetchContent_Declare(SwiftSystem + GIT_REPOSITORY https://github.com/apple/swift-system + GIT_TAG 1.8.1) + FetchContent_MakeAvailable(SwiftSystem) +endif() + +set(BUILD_TESTING ${_NIO_SAVED_BUILD_TESTING}) +set(BUILD_EXAMPLES ${_NIO_SAVED_BUILD_EXAMPLES}) + +# swift-collections can be built as a single module, which has no DequeModule target. +if(NOT TARGET SwiftCollections::DequeModule AND NOT TARGET DequeModule) + message(FATAL_ERROR "SwiftNIO needs swift-collections' DequeModule target; COLLECTIONS_SINGLE_MODULE builds of swift-collections are not supported") +endif() + +# find_package() provides namespaced targets whereas the vended dependencies only provide plain ones. +# Always link against the namespaced names. +if(NOT TARGET SwiftAtomics::Atomics) + add_library(SwiftAtomics::Atomics ALIAS Atomics) +endif() +if(NOT TARGET SwiftCollections::DequeModule) + add_library(SwiftCollections::DequeModule ALIAS DequeModule) +endif() +if(NOT TARGET SwiftSystem::SystemPackage) + add_library(SwiftSystem::SystemPackage ALIAS SystemPackage) +endif() + +# Set after vending the dependencies so their targets keep their own language mode. +set(CMAKE_Swift_LANGUAGE_VERSION 6) + +add_subdirectory(Sources) +add_subdirectory(cmake/modules) diff --git a/Package.swift b/Package.swift index 18af92a13..6d47a8383 100644 --- a/Package.swift +++ b/Package.swift @@ -76,14 +76,17 @@ let package = Package( swiftCollections, swiftAtomics, ], + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( name: "_NIODataStructures", + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( name: "_NIOBase64", + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( @@ -95,6 +98,7 @@ let package = Package( swiftAtomics, swiftCollections, ], + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( @@ -110,7 +114,7 @@ let package = Package( "CNIOPosix", swiftAtomics, ], - exclude: includePrivacyManifest ? [] : ["PrivacyInfo.xcprivacy"], + exclude: includePrivacyManifest ? ["CMakeLists.txt"] : ["CMakeLists.txt", "PrivacyInfo.xcprivacy"], resources: includePrivacyManifest ? [.copy("PrivacyInfo.xcprivacy")] : [], swiftSettings: swiftSettings ), @@ -121,6 +125,7 @@ let package = Package( "NIOEmbedded", "NIOPosix", ], + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( @@ -129,6 +134,7 @@ let package = Package( .target(name: "NIO", condition: .when(platforms: historicalNIOPosixDependencyRequired)), "NIOCore", ], + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( @@ -136,6 +142,7 @@ let package = Package( dependencies: [ "NIOCore" ], + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( @@ -144,11 +151,13 @@ let package = Package( .target(name: "NIO", condition: .when(platforms: historicalNIOPosixDependencyRequired)), "NIOFoundationEssentialsCompat", ], + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( name: "CNIOAtomics", dependencies: [], + exclude: ["CMakeLists.txt"], cSettings: [ .define("_GNU_SOURCE") ] @@ -156,25 +165,30 @@ let package = Package( .target( name: "CNIOPosix", dependencies: [], + exclude: ["CMakeLists.txt"], cSettings: [ .define("_GNU_SOURCE") ] ), .target( name: "CNIOSHA1", - dependencies: [] + dependencies: [], + exclude: ["CMakeLists.txt"] ), .target( name: "CNIOOpenBSD", - dependencies: [] + dependencies: [], + exclude: ["CMakeLists.txt"] ), .target( name: "CNIOFreeBSD", - dependencies: [] + dependencies: [], + exclude: ["CMakeLists.txt"] ), .target( name: "CNIOLinux", dependencies: [], + exclude: ["CMakeLists.txt"], cSettings: [ .define("_GNU_SOURCE") ] @@ -182,23 +196,27 @@ let package = Package( .target( name: "CNIODarwin", dependencies: [], + exclude: ["CMakeLists.txt"], cSettings: [ .define("__APPLE_USE_RFC_3542") ] ), .target( name: "CNIOWindows", - dependencies: [] + dependencies: [], + exclude: ["CMakeLists.txt"] ), .target( name: "CNIOWASI", - dependencies: [] + dependencies: [], + exclude: ["CMakeLists.txt"] ), .target( name: "NIOConcurrencyHelpers", dependencies: [ "CNIOAtomics" ], + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( @@ -210,6 +228,7 @@ let package = Package( "CNIOLLHTTP", swiftCollections, ], + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( @@ -221,10 +240,12 @@ let package = Package( "CNIOSHA1", "_NIOBase64", ], + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( name: "CNIOLLHTTP", + exclude: ["CMakeLists.txt"], cSettings: [ .define("_GNU_SOURCE"), .define("LLHTTP_STRICT_MODE"), @@ -237,6 +258,7 @@ let package = Package( "NIOCore", swiftCollections, ], + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( @@ -248,6 +270,7 @@ let package = Package( "NIOHTTP1", swiftAtomics, ], + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( @@ -263,7 +286,7 @@ let package = Package( swiftSystem, ], path: "Sources/NIOFS", - exclude: includePrivacyManifest ? [] : ["PrivacyInfo.xcprivacy"], + exclude: includePrivacyManifest ? ["CMakeLists.txt"] : ["CMakeLists.txt", "PrivacyInfo.xcprivacy"], resources: includePrivacyManifest ? [.copy("PrivacyInfo.xcprivacy")] : [], swiftSettings: swiftSettings + [ .define("ENABLE_MOCKING", .when(configuration: .debug)) @@ -276,6 +299,7 @@ let package = Package( "NIOFoundationEssentialsCompat", ], path: "Sources/NIOFSFoundationCompat", + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), @@ -292,7 +316,7 @@ let package = Package( swiftSystem, ], path: "Sources/_NIOFileSystem", - exclude: includePrivacyManifest ? [] : ["PrivacyInfo.xcprivacy"], + exclude: includePrivacyManifest ? ["CMakeLists.txt"] : ["CMakeLists.txt", "PrivacyInfo.xcprivacy"], resources: includePrivacyManifest ? [.copy("PrivacyInfo.xcprivacy")] : [], swiftSettings: swiftSettings + [ .define("ENABLE_MOCKING", .when(configuration: .debug)) @@ -305,11 +329,13 @@ let package = Package( "NIOFoundationEssentialsCompat", ], path: "Sources/_NIOFileSystemFoundationCompat", + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), .target( name: "NIOFileSystem", dependencies: ["_NIOFileSystem"], + exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt new file mode 100644 index 000000000..4ca6bf018 --- /dev/null +++ b/Sources/CMakeLists.txt @@ -0,0 +1,43 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_subdirectory(CNIOAtomics) +add_subdirectory(CNIOPosix) +add_subdirectory(CNIOLinux) +add_subdirectory(CNIOLLHTTP) +add_subdirectory(CNIODarwin) +add_subdirectory(CNIOSHA1) +add_subdirectory(CNIOOpenBSD) +add_subdirectory(CNIOFreeBSD) +add_subdirectory(CNIOWindows) +add_subdirectory(CNIOWASI) +add_subdirectory(NIOCore) +add_subdirectory(_NIODataStructures) +add_subdirectory(_NIOBase64) +add_subdirectory(NIOEmbedded) +add_subdirectory(NIOPosix) +add_subdirectory(NIO) +add_subdirectory(_NIOConcurrency) +add_subdirectory(NIOFoundationEssentialsCompat) +add_subdirectory(NIOFoundationCompat) +add_subdirectory(NIOConcurrencyHelpers) +add_subdirectory(NIOHTTP1) +add_subdirectory(NIOWebSocket) +add_subdirectory(NIOTLS) +add_subdirectory(NIOTestUtils) +add_subdirectory(NIOFS) +add_subdirectory(NIOFSFoundationCompat) +add_subdirectory(_NIOFileSystem) +add_subdirectory(_NIOFileSystemFoundationCompat) +add_subdirectory(NIOFileSystem) diff --git a/Sources/CNIOAtomics/CMakeLists.txt b/Sources/CNIOAtomics/CMakeLists.txt new file mode 100644 index 000000000..742ce8bd4 --- /dev/null +++ b/Sources/CNIOAtomics/CMakeLists.txt @@ -0,0 +1,29 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(CNIOAtomics STATIC + "src/c-atomics.c" + "src/c-nioatomics.c" +) + +target_include_directories(CNIOAtomics PUBLIC + include) + +target_compile_definitions(CNIOAtomics PRIVATE + _GNU_SOURCE) + +set_target_properties(CNIOAtomics PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_Swift_MODULE_DIRECTORY}") + +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS CNIOAtomics) diff --git a/Sources/CNIOAtomics/include/module.modulemap b/Sources/CNIOAtomics/include/module.modulemap new file mode 100644 index 000000000..36487dcb0 --- /dev/null +++ b/Sources/CNIOAtomics/include/module.modulemap @@ -0,0 +1,4 @@ +module CNIOAtomics { + umbrella header "CNIOAtomics.h" + export * +} diff --git a/Sources/CNIODarwin/CMakeLists.txt b/Sources/CNIODarwin/CMakeLists.txt new file mode 100644 index 000000000..8513d113f --- /dev/null +++ b/Sources/CNIODarwin/CMakeLists.txt @@ -0,0 +1,28 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(CNIODarwin STATIC + "shim.c" +) + +target_include_directories(CNIODarwin PUBLIC + include) + +target_compile_definitions(CNIODarwin PRIVATE + __APPLE_USE_RFC_3542) + +set_target_properties(CNIODarwin PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_Swift_MODULE_DIRECTORY}") + +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS CNIODarwin) diff --git a/Sources/CNIODarwin/include/module.modulemap b/Sources/CNIODarwin/include/module.modulemap new file mode 100644 index 000000000..26ab249b2 --- /dev/null +++ b/Sources/CNIODarwin/include/module.modulemap @@ -0,0 +1,4 @@ +module CNIODarwin { + umbrella header "CNIODarwin.h" + export * +} diff --git a/Sources/CNIOFreeBSD/CMakeLists.txt b/Sources/CNIOFreeBSD/CMakeLists.txt new file mode 100644 index 000000000..63dd1d277 --- /dev/null +++ b/Sources/CNIOFreeBSD/CMakeLists.txt @@ -0,0 +1,25 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(CNIOFreeBSD STATIC + "shim.c" +) + +target_include_directories(CNIOFreeBSD PUBLIC + include) + +set_target_properties(CNIOFreeBSD PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_Swift_MODULE_DIRECTORY}") + +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS CNIOFreeBSD) diff --git a/Sources/CNIOFreeBSD/include/module.modulemap b/Sources/CNIOFreeBSD/include/module.modulemap new file mode 100644 index 000000000..9036a2ca1 --- /dev/null +++ b/Sources/CNIOFreeBSD/include/module.modulemap @@ -0,0 +1,4 @@ +module CNIOFreeBSD { + umbrella header "CNIOFreeBSD.h" + export * +} diff --git a/Sources/CNIOLLHTTP/CMakeLists.txt b/Sources/CNIOLLHTTP/CMakeLists.txt new file mode 100644 index 000000000..928749ba7 --- /dev/null +++ b/Sources/CNIOLLHTTP/CMakeLists.txt @@ -0,0 +1,31 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(CNIOLLHTTP STATIC + "c_nio_api.c" + "c_nio_http.c" + "c_nio_llhttp.c" +) + +target_include_directories(CNIOLLHTTP PUBLIC + include) + +target_compile_definitions(CNIOLLHTTP PRIVATE + _GNU_SOURCE + LLHTTP_STRICT_MODE) + +set_target_properties(CNIOLLHTTP PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_Swift_MODULE_DIRECTORY}") + +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS CNIOLLHTTP) diff --git a/Sources/CNIOLLHTTP/include/module.modulemap b/Sources/CNIOLLHTTP/include/module.modulemap new file mode 100644 index 000000000..b0b259891 --- /dev/null +++ b/Sources/CNIOLLHTTP/include/module.modulemap @@ -0,0 +1,4 @@ +module CNIOLLHTTP { + umbrella header "CNIOLLHTTP.h" + export * +} diff --git a/Sources/CNIOLinux/CMakeLists.txt b/Sources/CNIOLinux/CMakeLists.txt new file mode 100644 index 000000000..7bbcce41e --- /dev/null +++ b/Sources/CNIOLinux/CMakeLists.txt @@ -0,0 +1,29 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(CNIOLinux STATIC + "liburing_shims.c" + "shim.c" +) + +target_include_directories(CNIOLinux PUBLIC + include) + +target_compile_definitions(CNIOLinux PRIVATE + _GNU_SOURCE) + +set_target_properties(CNIOLinux PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_Swift_MODULE_DIRECTORY}") + +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS CNIOLinux) diff --git a/Sources/CNIOLinux/include/module.modulemap b/Sources/CNIOLinux/include/module.modulemap new file mode 100644 index 000000000..f9a8cbb63 --- /dev/null +++ b/Sources/CNIOLinux/include/module.modulemap @@ -0,0 +1,4 @@ +module CNIOLinux { + umbrella header "CNIOLinux.h" + export * +} diff --git a/Sources/CNIOOpenBSD/CMakeLists.txt b/Sources/CNIOOpenBSD/CMakeLists.txt new file mode 100644 index 000000000..207452caa --- /dev/null +++ b/Sources/CNIOOpenBSD/CMakeLists.txt @@ -0,0 +1,25 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(CNIOOpenBSD STATIC + "shim.c" +) + +target_include_directories(CNIOOpenBSD PUBLIC + include) + +set_target_properties(CNIOOpenBSD PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_Swift_MODULE_DIRECTORY}") + +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS CNIOOpenBSD) diff --git a/Sources/CNIOOpenBSD/include/module.modulemap b/Sources/CNIOOpenBSD/include/module.modulemap new file mode 100644 index 000000000..b2d74a79c --- /dev/null +++ b/Sources/CNIOOpenBSD/include/module.modulemap @@ -0,0 +1,4 @@ +module CNIOOpenBSD { + umbrella header "CNIOOpenBSD.h" + export * +} diff --git a/Sources/CNIOPosix/CMakeLists.txt b/Sources/CNIOPosix/CMakeLists.txt new file mode 100644 index 000000000..a30d87a4a --- /dev/null +++ b/Sources/CNIOPosix/CMakeLists.txt @@ -0,0 +1,28 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(CNIOPosix STATIC + "event_loop_id.c" +) + +target_include_directories(CNIOPosix PUBLIC + include) + +target_compile_definitions(CNIOPosix PRIVATE + _GNU_SOURCE) + +set_target_properties(CNIOPosix PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_Swift_MODULE_DIRECTORY}") + +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS CNIOPosix) diff --git a/Sources/CNIOPosix/include/module.modulemap b/Sources/CNIOPosix/include/module.modulemap new file mode 100644 index 000000000..b19e23aa1 --- /dev/null +++ b/Sources/CNIOPosix/include/module.modulemap @@ -0,0 +1,4 @@ +module CNIOPosix { + umbrella header "CNIOPosix.h" + export * +} diff --git a/Sources/CNIOSHA1/CMakeLists.txt b/Sources/CNIOSHA1/CMakeLists.txt new file mode 100644 index 000000000..824cf91ae --- /dev/null +++ b/Sources/CNIOSHA1/CMakeLists.txt @@ -0,0 +1,25 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(CNIOSHA1 STATIC + "c_nio_sha1.c" +) + +target_include_directories(CNIOSHA1 PUBLIC + include) + +set_target_properties(CNIOSHA1 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_Swift_MODULE_DIRECTORY}") + +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS CNIOSHA1) diff --git a/Sources/CNIOSHA1/include/module.modulemap b/Sources/CNIOSHA1/include/module.modulemap new file mode 100644 index 000000000..9115ce5c0 --- /dev/null +++ b/Sources/CNIOSHA1/include/module.modulemap @@ -0,0 +1,4 @@ +module CNIOSHA1 { + umbrella header "CNIOSHA1.h" + export * +} diff --git a/Sources/CNIOWASI/CMakeLists.txt b/Sources/CNIOWASI/CMakeLists.txt new file mode 100644 index 000000000..767feb085 --- /dev/null +++ b/Sources/CNIOWASI/CMakeLists.txt @@ -0,0 +1,25 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(CNIOWASI STATIC + "CNIOWASI.c" +) + +target_include_directories(CNIOWASI PUBLIC + include) + +set_target_properties(CNIOWASI PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_Swift_MODULE_DIRECTORY}") + +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS CNIOWASI) diff --git a/Sources/CNIOWASI/include/module.modulemap b/Sources/CNIOWASI/include/module.modulemap new file mode 100644 index 000000000..1b989467b --- /dev/null +++ b/Sources/CNIOWASI/include/module.modulemap @@ -0,0 +1,4 @@ +module CNIOWASI { + umbrella header "CNIOWASI.h" + export * +} diff --git a/Sources/CNIOWindows/CMakeLists.txt b/Sources/CNIOWindows/CMakeLists.txt new file mode 100644 index 000000000..62c5c8b7e --- /dev/null +++ b/Sources/CNIOWindows/CMakeLists.txt @@ -0,0 +1,35 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(CNIOWindows STATIC + "WSAStartup.c" + "shim.c" +) + +target_include_directories(CNIOWindows PUBLIC + include) + +# `WSAStartup.c` calls into Winsock. +target_link_libraries(CNIOWindows PUBLIC + $<$:ws2_32>) + +# `WSAStartup.c` initialises Winsock from a `.CRT$XCU` initializer that nothing references, so +# make sure the linker keeps it. +target_link_options(CNIOWindows INTERFACE + $<$:LINKER:/INCLUDE:NIOWSAStartup_ptr>) + +set_target_properties(CNIOWindows PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_Swift_MODULE_DIRECTORY}") + +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS CNIOWindows) diff --git a/Sources/NIO/CMakeLists.txt b/Sources/NIO/CMakeLists.txt new file mode 100644 index 000000000..57d3dcb2b --- /dev/null +++ b/Sources/NIO/CMakeLists.txt @@ -0,0 +1,30 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIO + "Exports.swift" +) + +target_link_libraries(NIO PUBLIC + NIOCore + NIOEmbedded + NIOPosix) + +target_compile_options(NIO PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(NIO PRIVATE $<$>:DEBUG>) +set_target_properties(NIO PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIO) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIO) diff --git a/Sources/NIOConcurrencyHelpers/CMakeLists.txt b/Sources/NIOConcurrencyHelpers/CMakeLists.txt new file mode 100644 index 000000000..ae74d46af --- /dev/null +++ b/Sources/NIOConcurrencyHelpers/CMakeLists.txt @@ -0,0 +1,33 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIOConcurrencyHelpers + "NIOAtomic.swift" + "NIOLock.swift" + "NIOLockedValueBox.swift" + "NIOThreadPoolWorkAvailable.swift" + "atomics.swift" + "lock.swift" +) + +target_link_libraries(NIOConcurrencyHelpers PUBLIC + CNIOAtomics) + +target_compile_options(NIOConcurrencyHelpers PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(NIOConcurrencyHelpers PRIVATE $<$>:DEBUG>) +set_target_properties(NIOConcurrencyHelpers PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIOConcurrencyHelpers) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIOConcurrencyHelpers) diff --git a/Sources/NIOCore/CMakeLists.txt b/Sources/NIOCore/CMakeLists.txt new file mode 100644 index 000000000..4a6bc1de2 --- /dev/null +++ b/Sources/NIOCore/CMakeLists.txt @@ -0,0 +1,109 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIOCore + "AddressedEnvelope.swift" + "AsyncAwaitSupport.swift" + "AsyncChannel/AsyncChannel.swift" + "AsyncChannel/AsyncChannelHandler.swift" + "AsyncChannel/AsyncChannelInboundStream.swift" + "AsyncChannel/AsyncChannelOutboundWriter.swift" + "AsyncSequences/NIOAsyncSequenceProducer.swift" + "AsyncSequences/NIOAsyncSequenceProducerStrategies.swift" + "AsyncSequences/NIOAsyncWriter.swift" + "AsyncSequences/NIOThrowingAsyncSequenceProducer.swift" + "BSDSocketAPI.swift" + "ByteBuffer-aux.swift" + "ByteBuffer-binaryEncodedLengthPrefix.swift" + "ByteBuffer-conversions.swift" + "ByteBuffer-core.swift" + "ByteBuffer-hex.swift" + "ByteBuffer-int.swift" + "ByteBuffer-lengthPrefix.swift" + "ByteBuffer-multi-int.swift" + "ByteBuffer-quicBinaryEncodingStrategy.swift" + "ByteBuffer-views.swift" + "Channel.swift" + "ChannelHandler.swift" + "ChannelHandlers.swift" + "ChannelInvoker.swift" + "ChannelOption.swift" + "ChannelPipeline.swift" + "CircularBuffer.swift" + "Codec.swift" + "ConvenienceOptionSupport.swift" + "DeadChannel.swift" + "DispatchQueue+WithFuture.swift" + "EventLoop+Deprecated.swift" + "EventLoop+SerialExecutor.swift" + "EventLoop.swift" + "EventLoopFuture+AssumeIsolated.swift" + "EventLoopFuture+Deprecated.swift" + "EventLoopFuture+WithEventLoop.swift" + "EventLoopFuture.swift" + "FileDescriptor.swift" + "FileHandle.swift" + "FileRegion.swift" + "GlobalSingletons.swift" + "IO.swift" + "IOData.swift" + "IPProtocol.swift" + "IntegerBitPacking.swift" + "IntegerTypes.swift" + "Interfaces.swift" + "Linux.swift" + "MarkedCircularBuffer.swift" + "MulticastChannel.swift" + "NIOAny.swift" + "NIOCloseOnErrorHandler.swift" + "NIOCoreSendableMetatype.swift" + "NIODecodedAsyncSequence.swift" + "NIOLoopBound.swift" + "NIOPooledRecvBufferAllocator.swift" + "NIOScheduledCallback.swift" + "NIOSendable.swift" + "NIOSplitLinesMessageDecoder.swift" + "NIOTransportAccessibleChannelCore.swift" + "RecvByteBufferAllocator.swift" + "SingleStepByteToMessageDecoder.swift" + "SocketAddresses.swift" + "SocketOptionProvider.swift" + "SystemCallHelpers.swift" + "TimeAmount+Duration.swift" + "TypeAssistedChannelHandler.swift" + "UniversalBootstrapSupport.swift" + "Utilities.swift" +) + +target_link_libraries(NIOCore PUBLIC + $<$>:dispatch> + NIOConcurrencyHelpers + _NIOBase64 + _NIODataStructures + CNIOOpenBSD + CNIOFreeBSD + CNIODarwin + CNIOLinux + CNIOWindows + CNIOWASI + SwiftCollections::DequeModule + SwiftAtomics::Atomics) + +target_compile_options(NIOCore PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(NIOCore PRIVATE $<$>:DEBUG>) +set_target_properties(NIOCore PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIOCore) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIOCore) diff --git a/Sources/NIOEmbedded/CMakeLists.txt b/Sources/NIOEmbedded/CMakeLists.txt new file mode 100644 index 000000000..978dc34ef --- /dev/null +++ b/Sources/NIOEmbedded/CMakeLists.txt @@ -0,0 +1,35 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIOEmbedded + "AsyncTestingChannel.swift" + "AsyncTestingEventLoop.swift" + "Embedded.swift" +) + +target_link_libraries(NIOEmbedded PUBLIC + $<$>:dispatch> + NIOCore + NIOConcurrencyHelpers + _NIODataStructures + SwiftAtomics::Atomics + SwiftCollections::DequeModule) + +target_compile_options(NIOEmbedded PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(NIOEmbedded PRIVATE $<$>:DEBUG>) +set_target_properties(NIOEmbedded PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIOEmbedded) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIOEmbedded) diff --git a/Sources/NIOFS/CMakeLists.txt b/Sources/NIOFS/CMakeLists.txt new file mode 100644 index 000000000..5fe98c8d7 --- /dev/null +++ b/Sources/NIOFS/CMakeLists.txt @@ -0,0 +1,77 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIOFS + "Array+FileSystem.swift" + "ArraySlice+FileSystem.swift" + "BufferedReader.swift" + "BufferedWriter.swift" + "ByteBuffer+FileSystem.swift" + "ByteCount.swift" + "Convenience.swift" + "DirectoryEntries.swift" + "DirectoryEntry.swift" + "Exports.swift" + "FileChunks.swift" + "FileHandle.swift" + "FileHandleProtocol.swift" + "FileInfo.swift" + "FileSystem.swift" + "FileSystemError+Syscall.swift" + "FileSystemError.swift" + "FileSystemProtocol.swift" + "FileType.swift" + "IOStrategy.swift" + "Internal/BufferedOrAnyStream.swift" + "Internal/BufferedStream.swift" + "Internal/Cancellation.swift" + "Internal/Concurrency Primitives/TokenBucket.swift" + "Internal/ParallelDirCopy.swift" + "Internal/ParallelRemoval.swift" + "Internal/String+UnsafeUnititializedCapacity.swift" + "Internal/System Calls/CInterop.swift" + "Internal/System Calls/Errno.swift" + "Internal/System Calls/FileDescriptor+Syscalls.swift" + "Internal/System Calls/Mocking.swift" + "Internal/System Calls/Syscall.swift" + "Internal/System Calls/Syscalls.swift" + "Internal/System Calls/SystemPackage+Windows.swift" + "Internal/SystemFileHandle.swift" + "Internal/Utilities.swift" + "NIOFilePath.swift" + "NIOFileSystemSendableMetatype.swift" + "OpenOptions.swift" + "String+FileSystem.swift" +) + +target_link_libraries(NIOFS PUBLIC + NIOCore + NIOPosix + NIOConcurrencyHelpers + CNIOLinux + CNIODarwin + CNIOWindows + SwiftAtomics::Atomics + SwiftCollections::DequeModule + SwiftSystem::SystemPackage) + +target_compile_options(NIOFS PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +# ENABLE_MOCKING (defined for debug builds in Package.swift) is deliberately not defined here: it only adds the +# `@_spi(Testing)` syscall-mocking hooks that are used by NIOFSTests. +target_compile_definitions(NIOFS PRIVATE $<$>:DEBUG>) +set_target_properties(NIOFS PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIOFS) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIOFS) diff --git a/Sources/NIOFSFoundationCompat/CMakeLists.txt b/Sources/NIOFSFoundationCompat/CMakeLists.txt new file mode 100644 index 000000000..e168de64d --- /dev/null +++ b/Sources/NIOFSFoundationCompat/CMakeLists.txt @@ -0,0 +1,32 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIOFSFoundationCompat + "Data+FileSystem.swift" + "Date+FileInfo.swift" +) + +target_link_libraries(NIOFSFoundationCompat PUBLIC + NIOFS + NIOCore + NIOFoundationEssentialsCompat + $<$>:$>) + +target_compile_options(NIOFSFoundationCompat PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(NIOFSFoundationCompat PRIVATE $<$>:DEBUG>) +set_target_properties(NIOFSFoundationCompat PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIOFSFoundationCompat) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIOFSFoundationCompat) diff --git a/Sources/NIOFileSystem/CMakeLists.txt b/Sources/NIOFileSystem/CMakeLists.txt new file mode 100644 index 000000000..30805df08 --- /dev/null +++ b/Sources/NIOFileSystem/CMakeLists.txt @@ -0,0 +1,28 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIOFileSystem + "Exports.swift" +) + +target_link_libraries(NIOFileSystem PUBLIC + _NIOFileSystem) + +target_compile_options(NIOFileSystem PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(NIOFileSystem PRIVATE $<$>:DEBUG>) +set_target_properties(NIOFileSystem PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIOFileSystem) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIOFileSystem) diff --git a/Sources/NIOFoundationCompat/CMakeLists.txt b/Sources/NIOFoundationCompat/CMakeLists.txt new file mode 100644 index 000000000..76b7f47e7 --- /dev/null +++ b/Sources/NIOFoundationCompat/CMakeLists.txt @@ -0,0 +1,35 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIOFoundationCompat + "Exports.swift" + "JSONSerialization+ByteBuffer.swift" + "WaitSpinningRunLoop.swift" +) + +target_link_libraries(NIOFoundationCompat PUBLIC + $<$:NIO> + NIOCore + NIOFoundationEssentialsCompat + NIOConcurrencyHelpers + SwiftAtomics::Atomics + $<$>:Foundation>) + +target_compile_options(NIOFoundationCompat PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(NIOFoundationCompat PRIVATE $<$>:DEBUG>) +set_target_properties(NIOFoundationCompat PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIOFoundationCompat) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIOFoundationCompat) diff --git a/Sources/NIOFoundationEssentialsCompat/CMakeLists.txt b/Sources/NIOFoundationEssentialsCompat/CMakeLists.txt new file mode 100644 index 000000000..1626f68f4 --- /dev/null +++ b/Sources/NIOFoundationEssentialsCompat/CMakeLists.txt @@ -0,0 +1,30 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIOFoundationEssentialsCompat + "ByteBuffer-foundation.swift" + "Codable+ByteBuffer.swift" +) + +target_link_libraries(NIOFoundationEssentialsCompat PUBLIC + NIOCore + $<$>:$>) + +target_compile_options(NIOFoundationEssentialsCompat PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(NIOFoundationEssentialsCompat PRIVATE $<$>:DEBUG>) +set_target_properties(NIOFoundationEssentialsCompat PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIOFoundationEssentialsCompat) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIOFoundationEssentialsCompat) diff --git a/Sources/NIOHTTP1/CMakeLists.txt b/Sources/NIOHTTP1/CMakeLists.txt new file mode 100644 index 000000000..bf8619feb --- /dev/null +++ b/Sources/NIOHTTP1/CMakeLists.txt @@ -0,0 +1,57 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIOHTTP1 + "ByteCollectionUtils.swift" + "HTTPDecoder.swift" + "HTTPEncoder.swift" + "HTTPHeaderValidator.swift" + "HTTPHeaders+Validation.swift" + "HTTPPipelineSetup.swift" + "HTTPServerPipelineHandler.swift" + "HTTPServerProtocolErrorHandler.swift" + "HTTPServerRequestMethodQueue.swift" + "HTTPServerUpgradeHandler.swift" + "HTTPTypedPipelineSetup.swift" + "HTTPTypes.swift" + "NIOHTTPClientUpgradeHandler.swift" + "NIOHTTPObjectAggregator.swift" + "NIOTypedHTTPClientUpgradeHandler.swift" + "NIOTypedHTTPClientUpgraderStateMachine.swift" + "NIOTypedHTTPServerUpgradeHandler.swift" + "NIOTypedHTTPServerUpgraderStateMachine.swift" +) + +# CNIOLLHTTP is only imported with `private import`, so it is linked privately. NIOHTTP1 is not built with +# library evolution though, so its module file still requires CNIOLLHTTP's module to be loadable by clients: +# forward the headers and module map (but not the archive) to them. Static builds still link the archive via +# LINK_ONLY. +target_link_libraries(NIOHTTP1 + PUBLIC + $<$:NIO> + NIOCore + NIOConcurrencyHelpers + SwiftCollections::DequeModule + PRIVATE + CNIOLLHTTP + INTERFACE + $) + +target_compile_options(NIOHTTP1 PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(NIOHTTP1 PRIVATE $<$>:DEBUG>) +set_target_properties(NIOHTTP1 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIOHTTP1) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIOHTTP1) diff --git a/Sources/NIOPosix/CMakeLists.txt b/Sources/NIOPosix/CMakeLists.txt new file mode 100644 index 000000000..1a968048d --- /dev/null +++ b/Sources/NIOPosix/CMakeLists.txt @@ -0,0 +1,102 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIOPosix + "BSDSocketAPICommon.swift" + "BSDSocketAPIPosix.swift" + "BSDSocketAPIWindows.swift" + "BaseSocket.swift" + "BaseSocketChannel+AccessibleTransport.swift" + "BaseSocketChannel+SocketOptionProvider.swift" + "BaseSocketChannel.swift" + "BaseStreamSocketChannel.swift" + "Bootstrap.swift" + "ControlMessage.swift" + "DatagramVectorReadManager.swift" + "Errors+Any.swift" + "FileDescriptor.swift" + "GetaddrinfoResolver.swift" + "HappyEyeballs.swift" + "IO.swift" + "IntegerBitPacking.swift" + "IntegerTypes.swift" + "Linux.swift" + "LinuxCPUSet.swift" + "LinuxUring.swift" + "MultiThreadedEventLoopGroup.swift" + "NIOPosixSendableMetatype.swift" + "NIORandomizedDNSResolver.swift" + "NIOThreadPool.swift" + "NonBlockingFileIO.swift" + "PendingDatagramWritesManager.swift" + "PendingWritesManager.swift" + "PipeChannel.swift" + "PipePair.swift" + "Pool.swift" + "PosixSingletons+ConcurrencyTakeOver.swift" + "PosixSingletons.swift" + "RawSocketBootstrap.swift" + "Resolver.swift" + "Selectable.swift" + "SelectableChannel.swift" + "SelectableEventLoop.swift" + "SelectorEpoll.swift" + "SelectorGeneric.swift" + "SelectorKqueue.swift" + "SelectorUring.swift" + "SelectorWSAPoll.swift" + "ServerSocket.swift" + "Socket.swift" + "SocketChannel.swift" + "SocketProtocols.swift" + "StructuredConcurrencyHelpers.swift" + "System.swift" + "Thread.swift" + "ThreadPosix.swift" + "ThreadWindows.swift" + "Utilities.swift" + "VsockAddress.swift" + "VsockChannelEvents.swift" + "Windows.swift" +) + +# CNIOPosix holds thread-local state (the current event loop's ID and pointer). It is linked privately so +# that its archive, and with it that state, stays off the link lines of NIOPosix's consumers: only NIOPosix +# itself reaches it, through `inEventLoop`, which is `@usableFromInline` but not `@inlinable`. It is still +# forwarded as COMPILE_ONLY because NIOPosix is not built with library evolution, so its clients must be able +# to load CNIOPosix's module. Static builds still link the archive through the LINK_ONLY usage requirement. +target_link_libraries(NIOPosix + PUBLIC + $<$>:dispatch> + CNIOOpenBSD + CNIOLinux + CNIODarwin + CNIOWindows + NIOConcurrencyHelpers + NIOCore + _NIODataStructures + SwiftAtomics::Atomics + SwiftCollections::DequeModule + PRIVATE + CNIOPosix + INTERFACE + $) + +target_compile_options(NIOPosix PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(NIOPosix PRIVATE $<$>:DEBUG>) +set_target_properties(NIOPosix PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIOPosix) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIOPosix) diff --git a/Sources/NIOTLS/CMakeLists.txt b/Sources/NIOTLS/CMakeLists.txt new file mode 100644 index 000000000..9aa6671e5 --- /dev/null +++ b/Sources/NIOTLS/CMakeLists.txt @@ -0,0 +1,34 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIOTLS + "ApplicationProtocolNegotiationHandler.swift" + "NIOTypedApplicationProtocolNegotiationHandler.swift" + "ProtocolNegotiationHandlerStateMachine.swift" + "SNIHandler.swift" + "TLSEvents.swift" +) + +target_link_libraries(NIOTLS PUBLIC + $<$:NIO> + NIOCore + SwiftCollections::DequeModule) + +target_compile_options(NIOTLS PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(NIOTLS PRIVATE $<$>:DEBUG>) +set_target_properties(NIOTLS PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIOTLS) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIOTLS) diff --git a/Sources/NIOTestUtils/CMakeLists.txt b/Sources/NIOTestUtils/CMakeLists.txt new file mode 100644 index 000000000..031a47ee1 --- /dev/null +++ b/Sources/NIOTestUtils/CMakeLists.txt @@ -0,0 +1,37 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIOTestUtils + "ByteToMessageDecoderVerifier.swift" + "EventCounterHandler.swift" + "ManualTaskExecutor.swift" + "NIOHTTP1TestServer.swift" +) + +target_link_libraries(NIOTestUtils PUBLIC + NIOPosix + NIOCore + NIOEmbedded + NIOHTTP1 + NIOConcurrencyHelpers + SwiftAtomics::Atomics + SwiftCollections::DequeModule) + +target_compile_options(NIOTestUtils PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(NIOTestUtils PRIVATE $<$>:DEBUG>) +set_target_properties(NIOTestUtils PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIOTestUtils) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIOTestUtils) diff --git a/Sources/NIOWebSocket/CMakeLists.txt b/Sources/NIOWebSocket/CMakeLists.txt new file mode 100644 index 000000000..4313bfcf1 --- /dev/null +++ b/Sources/NIOWebSocket/CMakeLists.txt @@ -0,0 +1,41 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(NIOWebSocket + "NIOWebSocketClientUpgrader.swift" + "NIOWebSocketFrameAggregator.swift" + "NIOWebSocketServerUpgrader.swift" + "SHA1.swift" + "WebSocketErrorCodes.swift" + "WebSocketFrame.swift" + "WebSocketFrameDecoder.swift" + "WebSocketFrameEncoder.swift" + "WebSocketOpcode.swift" + "WebSocketProtocolErrorHandler.swift" +) + +target_link_libraries(NIOWebSocket PUBLIC + $<$:NIO> + NIOCore + NIOHTTP1 + CNIOSHA1 + _NIOBase64) + +target_compile_options(NIOWebSocket PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(NIOWebSocket PRIVATE $<$>:DEBUG>) +set_target_properties(NIOWebSocket PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(NIOWebSocket) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS NIOWebSocket) diff --git a/Sources/_NIOBase64/CMakeLists.txt b/Sources/_NIOBase64/CMakeLists.txt new file mode 100644 index 000000000..d0e626199 --- /dev/null +++ b/Sources/_NIOBase64/CMakeLists.txt @@ -0,0 +1,25 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(_NIOBase64 + "Base64.swift" +) + +target_compile_options(_NIOBase64 PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(_NIOBase64 PRIVATE $<$>:DEBUG>) +set_target_properties(_NIOBase64 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(_NIOBase64) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS _NIOBase64) diff --git a/Sources/_NIOConcurrency/CMakeLists.txt b/Sources/_NIOConcurrency/CMakeLists.txt new file mode 100644 index 000000000..4bf30aba9 --- /dev/null +++ b/Sources/_NIOConcurrency/CMakeLists.txt @@ -0,0 +1,29 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(_NIOConcurrency + "Empty.swift" +) + +target_link_libraries(_NIOConcurrency PUBLIC + $<$:NIO> + NIOCore) + +target_compile_options(_NIOConcurrency PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(_NIOConcurrency PRIVATE $<$>:DEBUG>) +set_target_properties(_NIOConcurrency PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(_NIOConcurrency) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS _NIOConcurrency) diff --git a/Sources/_NIODataStructures/CMakeLists.txt b/Sources/_NIODataStructures/CMakeLists.txt new file mode 100644 index 000000000..e132794d2 --- /dev/null +++ b/Sources/_NIODataStructures/CMakeLists.txt @@ -0,0 +1,27 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(_NIODataStructures + "Heap.swift" + "PriorityQueue.swift" + "_TinyArray.swift" +) + +target_compile_options(_NIODataStructures PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(_NIODataStructures PRIVATE $<$>:DEBUG>) +set_target_properties(_NIODataStructures PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(_NIODataStructures) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS _NIODataStructures) diff --git a/Sources/_NIOFileSystem/CMakeLists.txt b/Sources/_NIOFileSystem/CMakeLists.txt new file mode 100644 index 000000000..a27ee2706 --- /dev/null +++ b/Sources/_NIOFileSystem/CMakeLists.txt @@ -0,0 +1,77 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(_NIOFileSystem + "Array+FileSystem.swift" + "ArraySlice+FileSystem.swift" + "BufferedReader.swift" + "BufferedWriter.swift" + "ByteBuffer+FileSystem.swift" + "ByteCount.swift" + "Convenience.swift" + "DirectoryEntries.swift" + "DirectoryEntry.swift" + "Exports.swift" + "FileChunks.swift" + "FileHandle.swift" + "FileHandleProtocol.swift" + "FileInfo.swift" + "FileSystem.swift" + "FileSystemError+Syscall.swift" + "FileSystemError.swift" + "FileSystemProtocol.swift" + "FileType.swift" + "IOStrategy.swift" + "Internal/BufferedOrAnyStream.swift" + "Internal/BufferedStream.swift" + "Internal/Cancellation.swift" + "Internal/Concurrency Primitives/TokenBucket.swift" + "Internal/ParallelDirCopy.swift" + "Internal/ParallelRemoval.swift" + "Internal/String+UnsafeUnititializedCapacity.swift" + "Internal/System Calls/CInterop.swift" + "Internal/System Calls/Errno.swift" + "Internal/System Calls/FileDescriptor+Syscalls.swift" + "Internal/System Calls/Mocking.swift" + "Internal/System Calls/Syscall.swift" + "Internal/System Calls/Syscalls.swift" + "Internal/System Calls/SystemPackage+Windows.swift" + "Internal/SystemFileHandle.swift" + "Internal/Utilities.swift" + "NIOFilePath.swift" + "NIOFileSystemSendableMetatype.swift" + "OpenOptions.swift" + "String+FileSystem.swift" +) + +target_link_libraries(_NIOFileSystem PUBLIC + NIOCore + NIOPosix + NIOConcurrencyHelpers + CNIOLinux + CNIODarwin + CNIOWindows + SwiftAtomics::Atomics + SwiftCollections::DequeModule + SwiftSystem::SystemPackage) + +target_compile_options(_NIOFileSystem PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +# ENABLE_MOCKING (defined for debug builds in Package.swift) is deliberately not defined here: it only adds the +# `@_spi(Testing)` syscall-mocking hooks that are used by NIOFSTests. +target_compile_definitions(_NIOFileSystem PRIVATE $<$>:DEBUG>) +set_target_properties(_NIOFileSystem PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(_NIOFileSystem) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS _NIOFileSystem) diff --git a/Sources/_NIOFileSystemFoundationCompat/CMakeLists.txt b/Sources/_NIOFileSystemFoundationCompat/CMakeLists.txt new file mode 100644 index 000000000..fb3521b44 --- /dev/null +++ b/Sources/_NIOFileSystemFoundationCompat/CMakeLists.txt @@ -0,0 +1,32 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +add_library(_NIOFileSystemFoundationCompat + "Data+FileSystem.swift" + "Date+FileInfo.swift" +) + +target_link_libraries(_NIOFileSystemFoundationCompat PUBLIC + _NIOFileSystem + NIOCore + NIOFoundationEssentialsCompat + $<$>:$>) + +target_compile_options(_NIOFileSystemFoundationCompat PRIVATE ${SWIFT_NIO_COMPILE_OPTIONS}) +target_compile_definitions(_NIOFileSystemFoundationCompat PRIVATE $<$>:DEBUG>) +set_target_properties(_NIOFileSystemFoundationCompat PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +swift_nio_install_target(_NIOFileSystemFoundationCompat) +set_property(GLOBAL APPEND PROPERTY SWIFT_NIO_EXPORTS _NIOFileSystemFoundationCompat) diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt new file mode 100644 index 000000000..9a6dda843 --- /dev/null +++ b/cmake/modules/CMakeLists.txt @@ -0,0 +1,20 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +set(SWIFT_NIO_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/SwiftNIOExports.cmake) +configure_file(SwiftNIOConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/SwiftNIOConfig.cmake) + +get_property(SWIFT_NIO_EXPORTS GLOBAL PROPERTY SWIFT_NIO_EXPORTS) +export(TARGETS ${SWIFT_NIO_EXPORTS} FILE ${SWIFT_NIO_EXPORTS_FILE}) diff --git a/cmake/modules/SwiftNIOConfig.cmake.in b/cmake/modules/SwiftNIOConfig.cmake.in new file mode 100644 index 000000000..c5e237412 --- /dev/null +++ b/cmake/modules/SwiftNIOConfig.cmake.in @@ -0,0 +1,21 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +if(NOT TARGET SwiftNIO) + include(CMakeFindDependencyMacro) + find_dependency(swift-atomics) + find_dependency(SwiftCollections) + find_dependency(SwiftSystem) + include(@SWIFT_NIO_EXPORTS_FILE@) +endif() diff --git a/cmake/modules/SwiftNIOSupport.cmake b/cmake/modules/SwiftNIOSupport.cmake new file mode 100644 index 000000000..5a17cb1d8 --- /dev/null +++ b/cmake/modules/SwiftNIOSupport.cmake @@ -0,0 +1,77 @@ +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +# The names of this file and of its functions are specific to SwiftNIO: CMake functions are global, so the +# `SwiftSupport.cmake`, `get_swift_host_os` and `_install_target` names that other packages use (with different +# definitions, for example in swift-collections) would collide when SwiftNIO vends its dependencies. + +if(NOT SwiftNIO_SWIFTMODULE_TRIPLE) + set(target_info_cmd "${CMAKE_Swift_COMPILER}" -print-target-info) + if(CMAKE_Swift_COMPILER_TARGET) + list(APPEND target_info_cmd -target ${CMAKE_Swift_COMPILER_TARGET}) + endif() + execute_process(COMMAND ${target_info_cmd} OUTPUT_VARIABLE target_info) + string(JSON module_triple GET "${target_info}" "target" "moduleTriple") + set(SwiftNIO_SWIFTMODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used to install Swift module files") + mark_as_advanced(SwiftNIO_SWIFTMODULE_TRIPLE) + message(CONFIGURE_LOG "Swift module triple: ${module_triple}") +endif() + +# Returns the os name in a variable +# +# Usage: +# swift_nio_get_swift_host_os(result_var_name) +# +# +# Sets ${result_var_name} with the converted OS name derived from +# CMAKE_SYSTEM_NAME. +function(swift_nio_get_swift_host_os result_var_name) + if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + set(${result_var_name} macosx PARENT_SCOPE) + else() + string(TOLOWER ${CMAKE_SYSTEM_NAME} cmake_system_name_lc) + set(${result_var_name} ${cmake_system_name_lc} PARENT_SCOPE) + endif() +endfunction() + +function(swift_nio_install_target module) + swift_nio_get_swift_host_os(swift_os) + get_target_property(type ${module} TYPE) + + if(type STREQUAL STATIC_LIBRARY) + set(swift swift_static) + else() + set(swift swift) + endif() + + install(TARGETS ${module} + ARCHIVE DESTINATION lib/${swift}/${swift_os} + LIBRARY DESTINATION lib/${swift}/${swift_os} + RUNTIME DESTINATION bin) + if(type STREQUAL EXECUTABLE) + return() + endif() + + get_target_property(module_name ${module} Swift_MODULE_NAME) + if(NOT module_name) + set(module_name ${module}) + endif() + + install(FILES $/${module_name}.swiftdoc + DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule + RENAME ${SwiftNIO_SWIFTMODULE_TRIPLE}.swiftdoc) + install(FILES $/${module_name}.swiftmodule + DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule + RENAME ${SwiftNIO_SWIFTMODULE_TRIPLE}.swiftmodule) +endfunction()