Windows-specific timeout issue with URLSession in Swift (Error Code -1001)

Hello everyone, :waving_hand:t3::cowboy_hat_face:

I've been struggling with a persistent issue for several weeks and would greatly appreciate any insights or suggestions from the community.

:red_exclamation_mark:Problem Summary

We are sending JSON requests (~100 KB in size) via URLSession from a Swift app running on Windows. These requests consistently time out after a while. Specifically, we receive the following error:

Error Domain=NSURLErrorDomain Code=-1001 "(null)"

This only occurs on Windows – under macOS and Linux, the same requests work perfectly.

:magnifying_glass_tilted_left: Details

  • The server responds in under 5 seconds, and we have verified that the backend (a Vapor app in Kubernetes) is definitely not the bottleneck.
  • The request always hits the timeout interval, no matter how high we configure it: 60, 120, 300, 600 seconds – the error remains the same. (timeoutForRequest)
  • The request flow: Swift App (Windows) ---> HTTPS ---> Load Balancer (NGINX) ---> HTTP ---> Ingress Controller ---> Vapor App (Kubernetes)
  • On the load balancer we see this error: client prematurely closed connection, so upstream connection is closed too (104: Connection reset by peer)
  • The Ingress Controller never receives the complete body in these error cases. The content length set by the Swift app exceeds the data actually received.
  • We disabled request buffering in the Ingress Controller, but the issue persists.
  • We even tested a setup where we inserted a Caddy server in between to strip away TLS. The Swift app sent unencrypted HTTP requests to Caddy, which then forwarded them. This slightly improved stability but did not solve the issue.

:test_tube: Additional Notes

  • The URLSession is configured in an actor, with a nonisolated URLSession instance:
actor DataConnectActor {nonisolated let session : URLSession = URLSession(configuration: { let urlSessionConfiguration : URLSessionConfiguration = URLSessionConfiguration.default urlSessionConfiguration.httpMaximumConnectionsPerHost = ProcessInfo.processInfo.environment["DATACONNECT_MAX_CONNECTIONS"]?.asInt() ?? 16 urlSessionConfiguration.timeoutIntervalForRequest = TimeInterval(ProcessInfo.processInfo.environment["DATACONNECT_REQUEST_TIMEOUT"]?.asInt() ?? 120) urlSessionConfiguration.timeoutIntervalForResource = TimeInterval(ProcessInfo.processInfo.environment["DATACONNECT_RESSOURCE_TIMEOUT"]?.asInt() ?? 300) urlSessionConfiguration.httpAdditionalHeaders = ["User-Agent": "DataConnect Agent (\(Environment.version))"] return urlSessionConfiguration }()) public internal(set) var accessToken: UUID? = nil...} 
  • Requests are sent via a TaskGroup, limited to 5 concurrent tasks.
  • The more concurrent tasks we allow, the faster the timeout occurs.
  • We already increased the number of ephemeral ports in Windows. This made things slightly better, but the problem remains.
  • Using URLSessionDebugLibcurl=1 doesn't reveal any obvious issue related to libcurl.
  • We have also implemented a retry mechanism, but all retries also time out.

:wrench: Request Flow (Code Snippet Summary)

let data = try JSONEncoder().encode(entries)var request = URLRequest(url: url)request.httpMethod = "POST"request.httpBody = datarequest.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")request.setValue("application/json; charset=UTF-8", forHTTPHeaderField: "Content-Type")// additional headers... let (responseData, response) = try await urlSession.data(for: request) 

:white_check_mark: What We’ve Tried

  • Tested with and without TLS
  • Increased timeout and connection settings
  • Disabled buffering on Ingress
  • Increased ephemeral ports on Windows
  • Limited concurrent requests
  • Used URLSessionDebugLibcurl=1

We don't know how we can look any further here.

Thank you in advance for any guidance!

1 Like

The problem disappeared immediately when we built swift-corelibs-fondation under Windows with HTTP/2 support and used the built FoundationNetworking.dll (and .lib) accordingly.

2 Likes

This seems promising.
I have been chasing a similar issue as described here: URLSession.upload(for:from:)

Can you pls share some more tips on how to do this ?
I’m not a windows developer.
Do I just build from spm and replace the one already provided by the 6.1.2 toolchain ?
I see a few .lib and one .dll under ..\Programs\Swift

We use the Swift 6.2 toolchain. However, I think this can also be ported to Swift 6.1.2.

  1. Clone swift-corelibs-foundation repository

  2. Go into the directory

  3. Edit the cmake/modules/WindowsSwiftPMDependencies.cmake file (to include nghttp2, zlib and libxml)

    Summary

    ##===----------------------------------------------------------------------===##

    This source file is part of the Swift open source project

    Copyright (c) 2025 Apple Inc. and the Swift project authors

    Licensed under Apache License v2.0

    See LICENSE.txt for license information

    See CONTRIBUTORS.md for the list of Swift project authors

    SPDX-License-Identifier: Apache-2.0

    ##===----------------------------------------------------------------------===##

    Builds Windows CMake dependencies for a SwiftPM build (zlib, libxml, and curl)

    function(_foundation_setup_windows_swiftpm_dependencies_target)

    message(STATUS "Configuring Windows SwiftPM dependencies target")

    if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
    message(FATAL_ERROR "Windows SwiftPM dependencies is only allowed on Windows hosts. Building on Linux does not require pre-building dependencies via CMake.")
    endif()

    include(ExternalProject)

    set(DEST_DIR "${CMAKE_BINARY_DIR}/windows-deps")

    ExternalProject_Add(zlib
    GIT_REPOSITORY GitHub - madler/zlib: A massively spiffy yet delicately unobtrusive compression library.
    GIT_TAG v1.3.1
    CMAKE_ARGS
    -DCMAKE_INSTALL_PREFIX=${DEST_DIR}/zlib
    -DCMAKE_C_COMPILER=cl
    -DBUILD_SHARED_LIBS=NO
    -DCMAKE_POSITION_INDEPENDENT_CODE=YES
    -DCMAKE_BUILD_TYPE=Release
    EXCLUDE_FROM_ALL YES
    )

    ExternalProject_Add(libxml
    GIT_REPOSITORY GitHub - GNOME/libxml2: Read-only mirror of https://gitlab.gnome.org/GNOME/libxml2
    GIT_TAG v2.14.5
    CMAKE_ARGS
    -DCMAKE_INSTALL_PREFIX=${DEST_DIR}/libxml
    -DCMAKE_C_COMPILER=cl
    -DBUILD_SHARED_LIBS=NO
    -DLIBXML2_WITH_ICONV=NO
    -DLIBXML2_WITH_ICU=NO
    -DLIBXML2_WITH_LZMA=NO
    -DLIBXML2_WITH_PYTHON=NO
    -DLIBXML2_WITH_TESTS=NO
    -DLIBXML2_WITH_THREADS=YES
    -DLIBXML2_WITH_ZLIB=NO
    -DCMAKE_BUILD_TYPE=Release
    EXCLUDE_FROM_ALL YES
    )

    ExternalProject_Add(nghttp2
    GIT_REPOSITORY GitHub - nghttp2/nghttp2: nghttp2 - HTTP/2 C Library and tools
    GIT_TAG v1.59.0
    CMAKE_ARGS
    -DCMAKE_INSTALL_PREFIX=${DEST_DIR}/nghttp2
    -DCMAKE_C_COMPILER=cl
    -DBUILD_SHARED_LIBS=NO
    -DENABLE_APP=OFF
    -DENABLE_HPACK_TOOLS=OFF
    -DENABLE_EXAMPLES=OFF
    -DENABLE_DOC=OFF
    -DCMAKE_BUILD_TYPE=Release
    EXCLUDE_FROM_ALL YES
    )

    set(ZLIB_ROOT "${DEST_DIR}/zlib")
    set(ZLIB_LIBRARY_DIR "${ZLIB_ROOT}/lib")
    set(ZLIB_INCLUDE_DIR "${ZLIB_ROOT}/include")
    set(ZLIB_LIBRARY_PATH "${ZLIB_LIBRARY_DIR}/zlibstatic.lib")
    set(NGHTTP2_ROOT "${DEST_DIR}/nghttp2")
    set(NGHTTP2_LIBRARY_DIR "${NGHTTP2_ROOT}/lib")
    set(NGHTTP2_INCLUDE_DIR "${NGHTTP2_ROOT}/include")

    Add a custom target for zlib's install step that curl can depend on

    ExternalProject_Add_StepTargets(zlib install)
    ExternalProject_Add_StepTargets(nghttp2 install)

    ExternalProject_Add(curl
    GIT_REPOSITORY GitHub - curl/curl: A command line tool and library for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP, WS and WSS. libcurl offers a myriad of powerful features
    GIT_TAG curl-8_15_0
    CMAKE_ARGS
    -DCMAKE_INSTALL_PREFIX=${DEST_DIR}/curl
    -DCMAKE_C_COMPILER=cl
    -DBUILD_SHARED_LIBS=NO
    -DBUILD_TESTING=NO
    -DBUILD_CURL_EXE=NO
    -DCURL_CA_BUNDLE=none
    -DCURL_CA_FALLBACK=NO
    -DCURL_CA_PATH=none
    -DCURL_BROTLI=NO
    -DCURL_DISABLE_ALTSVC=NO
    -DCURL_DISABLE_AWS=YES
    -DCURL_DISABLE_BASIC_AUTH=NO
    -DCURL_DISABLE_BEARER_AUTH=NO
    -DCURL_DISABLE_COOKIES=NO
    -DCURL_DISABLE_DICT=YES
    -DCURL_DISABLE_DIGEST_AUTH=NO
    -DCURL_DISABLE_DOH=NO
    -DCURL_DISABLE_FILE=YES
    -DCURL_DISABLE_FORM_API=NO
    -DCURL_DISABLE_FTP=YES
    -DCURL_DISABLE_GETOPTIONS=NO
    -DCURL_DISABLE_GOPHER=YES
    -DCURL_DISABLE_HSTS=NO
    -DCURL_DISABLE_HTTP=NO
    -DCURL_DISABLE_HTTP_AUTH=NO
    -DCURL_DISABLE_IMAP=YES
    -DCURL_DISABLE_KERBEROS_AUTH=NO
    -DCURL_DISABLE_LDAP=YES
    -DCURL_DISABLE_LDAPS=YES
    -DCURL_DISABLE_MIME=NO
    -DCURL_DISABLE_MQTT=YES
    -DCURL_DISABLE_NEGOTIATE_AUTH=NO
    -DCURL_DISABLE_NETRC=NO
    -DCURL_DISABLE_NTLM=NO
    -DCURL_DISABLE_PARSEDATE=NO
    -DCURL_DISABLE_POP3=YES
    -DCURL_DISABLE_PROGRESS_METER=YES
    -DCURL_DISABLE_PROXY=NO
    -DCURL_DISABLE_RTSP=YES
    -DCURL_DISABLE_SHUFFLE_DNS=YES
    -DCURL_DISABLE_SMB=YES
    -DCURL_DISABLE_SMTP=YES
    -DCURL_DISABLE_SOCKETPAIR=YES
    -DCURL_DISABLE_SRP=NO
    -DCURL_DISABLE_TELNET=YES
    -DCURL_DISABLE_TFTP=YES
    -DCURL_DISABLE_VERBOSE_STRINGS=NO
    -DCURL_LTO=NO
    -DCURL_USE_BEARSSL=NO
    -DCURL_USE_GNUTLS=NO
    -DCURL_USE_GSSAPI=NO
    -DCURL_USE_LIBPSL=NO
    -DCURL_USE_LIBSSH=NO
    -DCURL_USE_LIBSSH2=NO
    -DCURL_USE_MBEDTLS=NO
    -DCURL_USE_OPENSSL=NO
    -DCURL_USE_SCHANNEL=YES
    -DCURL_USE_WOLFSSL=NO
    -DCURL_USE_NGHTTP2=YES
    -DCURL_WINDOWS_SSPI=YES
    -DCURL_ZLIB=YES
    -DCURL_ZSTD=NO
    -DENABLE_ARES=NO
    -DENABLE_CURLDEBUG=NO
    -DENABLE_DEBUG=NO
    -DENABLE_IPV6=YES
    -DENABLE_MANUAL=NO
    -DENABLE_THREADED_RESOLVER=NO
    -DENABLE_UNICODE=YES
    -DENABLE_UNIX_SOCKETS=NO
    -DENABLE_WEBSOCKETS=YES
    -DHAVE_POLL_FINE=NO
    -DUSE_IDN2=NO
    -DUSE_MSH3=NO
    -DUSE_NGHTTP2=YES
    -DNGHTTP2_INCLUDE_DIR=${NGHTTP2_INCLUDE_DIR}
    -DNGHTTP2_LIBRARY=${NGHTTP2_LIBRARY_DIR}/nghttp2.lib
    -DNGHTTP2_ROOT=${NGHTTP2_ROOT}
    -DUSE_NGTCP2=NO
    -DUSE_QUICHE=NO
    -DUSE_WIN32_IDN=YES
    -DUSE_WIN32_LARGE_FILES=YES
    -DUSE_WIN32_LDAP=NO
    -DCMAKE_BUILD_TYPE=Release
    -DZLIB_ROOT=${ZLIB_ROOT}
    -DZLIB_LIBRARY=${ZLIB_LIBRARY_PATH}
    -DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIR}
    DEPENDS zlib-install nghttp2-install
    EXCLUDE_FROM_ALL YES
    )

    set(LIBXML_LIBRARY_DIR "${DEST_DIR}/libxml/lib")
    set(LIBXML_INCLUDE_DIR "${DEST_DIR}/libxml/include/libxml2")

    set(CURL_LIBRARY_DIR "${DEST_DIR}/curl/lib")
    set(CURL_INCLUDE_DIR "${DEST_DIR}/curl/include")

    message(STATUS "LIBXML_INCLUDE_PATH=${LIBXML_INCLUDE_DIR}")
    message(STATUS "LIBXML_LIBRARY_PATH=${LIBXML_LIBRARY_DIR}")
    message(STATUS "CURL_INCLUDE_PATH=${CURL_INCLUDE_DIR}")
    message(STATUS "CURL_LIBRARY_PATH=${CURL_LIBRARY_DIR}")
    message(STATUS "ZLIB_LIBRARY_PATH=${ZLIB_LIBRARY_DIR}")

    ExternalProject_Add_StepTargets(libxml install)
    ExternalProject_Add_StepTargets(curl install)
    add_custom_target(WindowsSwiftPMDependencies
    DEPENDS libxml-install curl-install)

    add_custom_command(TARGET WindowsSwiftPMDependencies POST_BUILD
    COMMAND echo Please set the following environment variables for the SwiftPM build:)
    add_custom_command(TARGET WindowsSwiftPMDependencies POST_BUILD
    COMMAND echo:)
    add_custom_command(TARGET WindowsSwiftPMDependencies POST_BUILD
    COMMAND echo LIBXML_INCLUDE_PATH=${LIBXML_INCLUDE_DIR})
    add_custom_command(TARGET WindowsSwiftPMDependencies POST_BUILD
    COMMAND echo LIBXML_LIBRARY_PATH=${LIBXML_LIBRARY_DIR})
    add_custom_command(TARGET WindowsSwiftPMDependencies POST_BUILD
    COMMAND echo CURL_INCLUDE_PATH=${CURL_INCLUDE_DIR})
    add_custom_command(TARGET WindowsSwiftPMDependencies POST_BUILD
    COMMAND echo CURL_LIBRARY_PATH=${CURL_LIBRARY_DIR})
    add_custom_command(TARGET WindowsSwiftPMDependencies POST_BUILD
    COMMAND echo ZLIB_LIBRARY_PATH=${ZLIB_LIBRARY_DIR})
    add_custom_command(TARGET WindowsSwiftPMDependencies POST_BUILD
    COMMAND echo NGHTTP2_INCLUDE_PATH=${NGHTTP2_INCLUDE_DIR})
    add_custom_command(TARGET WindowsSwiftPMDependencies POST_BUILD
    COMMAND echo NGHTTP2_LIBRARY_PATH=${NGHTTP2_LIBRARY_DIR})

    endfunction()

  4. Edit the Package.swift file (to include the nghttp flags and settings)

    Summary

    // swift-tools-version: 6.0
    // The swift-tools-version declares the minimum version of Swift required to build this package.

    import PackageDescription

    let platformsWithThreads: [Platform] = [
    .iOS,
    .macOS,
    .tvOS,
    .watchOS,
    .macCatalyst,
    .driverKit,
    .android,
    .linux,
    .windows,
    ]

    var dispatchIncludeFlags: [CSetting] =
    if let environmentPath = Context.environment["DISPATCH_INCLUDE_PATH"] {
    dispatchIncludeFlags.append(.unsafeFlags([
    "-I(environmentPath)",
    "-I(environmentPath)/Block"
    ]))
    } else {
    dispatchIncludeFlags.append(
    .unsafeFlags([
    "-I/usr/lib/swift",
    "-I/usr/lib/swift/Block"
    ], .when(platforms: [.linux]))
    )
    if let sdkRoot = Context.environment["SDKROOT"] {
    dispatchIncludeFlags.append(.unsafeFlags([
    "-I(sdkRoot)usr\include",
    "-I(sdkRoot)usr\include\Block",
    ], .when(platforms: [.windows])))
    }
    }

    var libxmlIncludeFlags: [CSetting] =
    if let environmentPath = Context.environment["LIBXML_INCLUDE_PATH"] {
    libxmlIncludeFlags = [
    .unsafeFlags([
    "-I(environmentPath)"
    ]),
    .define("LIBXML_STATIC")
    ]
    }

    var curlIncludeFlags: [CSetting] =
    if let environmentPath = Context.environment["CURL_INCLUDE_PATH"] {
    curlIncludeFlags = [
    .unsafeFlags([
    "-I(environmentPath)"
    ]),
    .define("CURL_STATICLIB")
    ]
    }

    var nghttp2IncludeFlags: [CSetting] =
    if let nghttp2Path = Context.environment["NGHTTP2_INCLUDE_PATH"] {
    nghttp2IncludeFlags = [
    .unsafeFlags([
    "-I(nghttp2Path)"
    ]),
    .define("NGHTTP2_STATICLIB")
    ]
    }

    var curlLinkFlags: [LinkerSetting] = [
    .linkedLibrary("libcurl.lib", .when(platforms: [.windows])),
    .linkedLibrary("zlibstatic.lib", .when(platforms: [.windows])),
    .linkedLibrary("nghttp2.lib", .when(platforms: [.windows])),
    ]
    if let environmentPath = Context.environment["CURL_LIBRARY_PATH"] {
    curlLinkFlags.append(.unsafeFlags([
    "-L(environmentPath)"
    ]))
    }
    if let environmentPath = Context.environment["ZLIB_LIBRARY_PATH"] {
    curlLinkFlags.append(.unsafeFlags([
    "-L(environmentPath)"
    ]))
    }
    if let environmentPath = Context.environment["NGHTTP2_LIBRARY_PATH"] {
    curlLinkFlags.append(.unsafeFlags([
    "-L(environmentPath)"
    ]))
    }

    var libxmlLinkFlags: [LinkerSetting] = [
    .linkedLibrary("libxml2s.lib", .when(platforms: [.windows]))
    ]
    if let environmentPath = Context.environment["LIBXML_LIBRARY_PATH"] {
    libxmlLinkFlags.append(.unsafeFlags([
    "-L(environmentPath)"
    ]))
    }

    let coreFoundationBuildSettings: [CSetting] = [
    .headerSearchPath("internalInclude"),
    .define("DEBUG", .when(configuration: .debug)),
    .define("CF_BUILDING_CF"),
    .define("CF_WINDOWS_EXECUTABLE_INITIALIZER", .when(platforms: [.windows])), // Ensure __CFInitialize is run even when statically linked into an executable
    .define("DEPLOYMENT_ENABLE_LIBDISPATCH", .when(platforms: platformsWithThreads)),
    .define("DEPLOYMENT_RUNTIME_SWIFT"),
    .define("HAVE_STRUCT_TIMESPEC"),
    .define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads)),
    .define("_GNU_SOURCE", .when(platforms: [.linux, .android])),
    .define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
    .unsafeFlags([
    "-Wno-shorten-64-to-32",
    "-Wno-deprecated-declarations",
    "-Wno-unreachable-code",
    "-Wno-conditional-uninitialized",
    "-Wno-unused-variable",
    "-Wno-unused-function",
    "-Wno-microsoft-enum-forward-reference",
    "-Wno-int-conversion",
    "-Wno-switch",
    "-fconstant-cfstrings",
    "-fexceptions", // TODO: not on OpenBSD
    "-fdollars-in-identifiers",
    "-fno-common",
    "-fcf-runtime-abi=swift",
    "-include",
    "(Context.packageDirectory)/Sources/CoreFoundation/internalInclude/CoreFoundation_Prefix.h",
    // /EHsc for Windows
    ])
    ] + dispatchIncludeFlags

    // For _CFURLSessionInterface, _CFXMLInterface
    let interfaceBuildSettings: [CSetting] = [
    .headerSearchPath("../CoreFoundation/internalInclude"),
    .define("DEBUG", .when(configuration: .debug)),
    .define("CF_BUILDING_CF"),
    .define("DEPLOYMENT_ENABLE_LIBDISPATCH"),
    .define("HAVE_STRUCT_TIMESPEC"),
    .define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS", .when(platforms: platformsWithThreads)),
    .define("_GNU_SOURCE", .when(platforms: [.linux, .android])),
    .define("_WASI_EMULATED_SIGNAL", .when(platforms: [.wasi])),
    .unsafeFlags([
    "-Wno-shorten-64-to-32",
    "-Wno-deprecated-declarations",
    "-Wno-unreachable-code",
    "-Wno-conditional-uninitialized",
    "-Wno-unused-variable",
    "-Wno-unused-function",
    "-Wno-microsoft-enum-forward-reference",
    "-Wno-int-conversion",
    "-fconstant-cfstrings",
    "-fexceptions", // TODO: not on OpenBSD
    "-fdollars-in-identifiers",
    "-fno-common",
    "-fcf-runtime-abi=swift"
    // /EHsc for Windows
    ])
    ] + dispatchIncludeFlags

    let swiftBuildSettings: [SwiftSetting] = [
    .define("DEPLOYMENT_RUNTIME_SWIFT"),
    .define("SWIFT_CORELIBS_FOUNDATION_HAS_THREADS"),
    .swiftLanguageMode(.v6),
    .unsafeFlags([
    "-Xfrontend",
    "-require-explicit-sendable",
    ])
    ]

    var dependencies: [Package.Dependency] =

    if let useLocalDepsEnv = Context.environment["SWIFTCI_USE_LOCAL_DEPS"] {
    let root: String
    if useLocalDepsEnv == "1" {
    root = ".."
    } else {
    root = useLocalDepsEnv
    }
    dependencies +=
    [
    .package(
    name: "swift-foundation-icu",
    path: "(root)/swift-foundation-icu"),
    .package(
    name: "swift-foundation",
    path: "(root)/swift-foundation")
    ]
    } else {
    dependencies +=
    [
    .package(
    url: " GitHub - swiftlang/swift-foundation-icu ",
    branch: "main"),
    .package(
    url: " GitHub - swiftlang/swift-foundation: The Foundation project ",
    branch: "main")
    ]
    }

    let package = Package(
    name: "swift-corelibs-foundation",
    // Deployment target note: This package only builds for non-Darwin targets.
    platforms: [.macOS("99.9")],
    products: [
    .library(name: "Foundation", type: .dynamic, targets: ["Foundation"]),
    .library(name: "FoundationXML", type: .dynamic, targets: ["FoundationXML"]),
    .library(name: "FoundationNetworking", type: .dynamic, targets: ["FoundationNetworking"]),
    .executable(name: "plutil", targets: ["plutil"]),
    ],
    dependencies: dependencies,
    targets: [
    .target(
    name: "Foundation",
    dependencies: [
    .product(name: "FoundationEssentials", package: "swift-foundation"),
    .product(name: "FoundationInternationalization", package: "swift-foundation"),
    "CoreFoundation"
    ],
    path: "Sources/Foundation",
    exclude: [
    "CMakeLists.txt"
    ],
    swiftSettings: swiftBuildSettings
    ),
    .target(
    name: "FoundationXML",
    dependencies: [
    .product(name: "FoundationEssentials", package: "swift-foundation"),
    "Foundation",
    "CoreFoundation",
    "_CFXMLInterface",
    .target(name: "BlocksRuntime", condition: .when(platforms: [.wasi])),
    ],
    path: "Sources/FoundationXML",
    exclude: [
    "CMakeLists.txt"
    ],
    swiftSettings: swiftBuildSettings
    ),
    .target(
    name: "FoundationNetworking",
    dependencies: [
    .product(name: "FoundationEssentials", package: "swift-foundation"),
    "Foundation",
    "CoreFoundation",
    "_CFURLSessionInterface"
    ],
    path: "Sources/FoundationNetworking",
    exclude: [
    "CMakeLists.txt"
    ],
    swiftSettings: swiftBuildSettings
    ),
    .target(
    name: "CoreFoundation",
    dependencies: [
    .product(name: "_FoundationICU", package: "swift-foundation-icu"),
    .target(name: "BlocksRuntime", condition: .when(platforms: [.wasi])),
    ],
    path: "Sources/CoreFoundation",
    exclude: [
    "BlockRuntime",
    "CMakeLists.txt"
    ],
    cSettings: coreFoundationBuildSettings,
    linkerSettings: [.linkedLibrary("log", .when(platforms: [.android]))]
    ),
    .target(
    name: "BlocksRuntime",
    path: "Sources/CoreFoundation/BlockRuntime",
    exclude: [
    "CMakeLists.txt"
    ],
    cSettings: [
    // For CFTargetConditionals.h
    .headerSearchPath("../include"),
    ]
    ),
    .target(
    name: "_CFXMLInterface",
    dependencies: [
    "CoreFoundation",
    .target(name: "Clibxml2", condition: .when(platforms: [.linux, .android])),
    ],
    path: "Sources/_CFXMLInterface",
    exclude: [
    "CMakeLists.txt"
    ],
    cSettings: interfaceBuildSettings + libxmlIncludeFlags,
    linkerSettings: libxmlLinkFlags
    ),
    .target(
    name: "_CFURLSessionInterface",
    dependencies: [
    "CoreFoundation",
    .target(name: "Clibcurl", condition: .when(platforms: [.linux, .android])),
    ],
    path: "Sources/_CFURLSessionInterface",
    exclude: [
    "CMakeLists.txt"
    ],
    cSettings: interfaceBuildSettings + curlIncludeFlags + nghttp2IncludeFlags,
    linkerSettings: curlLinkFlags
    ),
    .systemLibrary(
    name: "Clibxml2",
    pkgConfig: "libxml-2.0",
    providers: [
    .brew(["libxml2"]),
    .apt(["libxml2-dev"])
    ]
    ),
    .systemLibrary(
    name: "Clibcurl",
    pkgConfig: "libcurl",
    providers: [
    .brew(["libcurl"]),
    .apt(["libcurl"])
    ]
    ),
    .executableTarget(
    name: "plutil",
    dependencies: [
    "Foundation"
    ],
    exclude: [
    "CMakeLists.txt"
    ],
    swiftSettings: [
    .swiftLanguageMode(.v6)
    ]
    ),
    .executableTarget(
    name: "xdgTestHelper",
    dependencies: [
    "Foundation",
    "FoundationXML",
    "FoundationNetworking"
    ],
    swiftSettings: [
    .swiftLanguageMode(.v6)
    ]
    ),
    // swift-corelibs-foundation has a copy of XCTest's sources so:
    // (1) we do not depend on the toolchain's XCTest, which depends on toolchain's Foundation, which we cannot pull in at the same time as a Foundation package
    // (2) we do not depend on a swift-corelibs-xctest Swift package, which depends on Foundation, which causes a circular dependency in swiftpm
    // We believe Foundation is the only project that needs to take this rather drastic measure.
    // We also have a stub for swift-testing for the same purpose, but without an implementation since this package has no swift-testing style tests
    .target(
    name: "XCTest",
    dependencies: [
    "Foundation"
    ],
    path: "Sources/XCTest"
    ),
    .target(
    name: "Testing",
    dependencies: ,
    path: "Sources/Testing"
    ),
    .testTarget(
    name: "TestFoundation",
    dependencies: [
    "Foundation",
    "FoundationXML",
    "FoundationNetworking",
    "XCTest",
    "Testing",
    .target(name: "xdgTestHelper", condition: .when(platforms: [.linux, .android]))
    ],
    resources: [
    .copy("Foundation/Resources")
    ],
    swiftSettings: [
    .define("NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT"),
    .swiftLanguageMode(.v6)
    ]
    ),
    ]
    )

  5. Run cmake -G Ninja -B build -DFOUNDATION_SWIFTPM_DEPS=YES -DFOUNDATION_BUILD_NETWORKING=ON -DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe -DCMAKE_LINKER=link.exe -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON

  6. Run ninja -C build WindowsSwiftPMDependencies

  7. Step 4 provides you with environment variables that you must set in your shell.

  8. RUN swift build -c release

  9. Now you should find the .dll and .lib files in the .build (release) folder.