From d9da5401ffce56ca5b3526aca5ca813b4d493840 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Fri, 16 Feb 2024 04:25:40 +0900 Subject: [PATCH 1/4] Set the minimum macOS deployment target to 10.13 for the test target The lit test suite respects `MACOSX_DEPLOYMENT_TARGET` to determine the `-target` option passed to compilers. However, the `SwiftXCTestFunctionalTests` target and the `XCTest` project do not set `MACOSX_DEPLOYMENT_TARGET` in their build settings, so the default value (14.2 in the current Xcode installed on the CI) is used and the macOS version of the CI machine is older than it. This patch fixes the issue by setting `MACOSX_DEPLOYMENT_TARGET` to 10.13, which is currently used as the minimum macOS version requirement in ci.swift.org. --- XCTest.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/XCTest.xcodeproj/project.pbxproj b/XCTest.xcodeproj/project.pbxproj index 27a6a5f2..08bc3a76 100644 --- a/XCTest.xcodeproj/project.pbxproj +++ b/XCTest.xcodeproj/project.pbxproj @@ -561,6 +561,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; GCC_GENERATE_DEBUGGING_SYMBOLS = YES; GCC_OPTIMIZATION_LEVEL = 0; + MACOSX_DEPLOYMENT_TARGET = 10.13; OTHER_CFLAGS = ""; "OTHER_LDFLAGS[sdk=macosx*]" = ( "-framework", @@ -575,6 +576,7 @@ isa = XCBuildConfiguration; buildSettings = { DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + MACOSX_DEPLOYMENT_TARGET = 10.13; OTHER_CFLAGS = ""; "OTHER_LDFLAGS[sdk=macosx*]" = ( "-framework", From a6fc1e22485bd36c2aba44dbb5eb84d399fdba55 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 22 Feb 2024 14:41:18 +0900 Subject: [PATCH 2/4] Don't use CoreFoundation when building with corelibs-foundation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The use of CoreFoundation while building with corelibs-foundation causes an unintentional dependency to the CoreFoundation framework due to the lack of way to distinguish corelibs-foundation's CoreFoundation from CoreFoundation.framework. From macOS 13, CoreFoundation started to depend on CoreServicesInternal, and it causes a transitive dependency from CoreFoundation.framework to Foundation.framework. ┌-> CoreFoundation --[NEW]--> CoreServicesInternal -┐ └-- Foundation <------------- CFNetwork ------------┘ Thus corelibs-xctest started to depend on Foundation.framework unintentionally from macOS 13. This unintentional dependency is problematic because it causes a duplicate loading of the Objective-C classes of Foundation from the corelibs-foundation and Foundation.framework even though we explicitly imports corelibs-foundation by `import SwiftFoundation`. This patch removes the use of CoreFoundation when building with corelibs-foundation based on the `USE_FOUNDATION_FRAMEWORK` definition. --- Sources/XCTest/Public/Asynchronous/XCTWaiter.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/XCTest/Public/Asynchronous/XCTWaiter.swift b/Sources/XCTest/Public/Asynchronous/XCTWaiter.swift index f19b344f..5fa6022e 100644 --- a/Sources/XCTest/Public/Asynchronous/XCTWaiter.swift +++ b/Sources/XCTest/Public/Asynchronous/XCTWaiter.swift @@ -10,7 +10,7 @@ // XCTWaiter.swift // -#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) +#if (os(macOS) || os(iOS) || os(tvOS) || os(watchOS)) && USE_FOUNDATION_FRAMEWORK import CoreFoundation #endif @@ -429,7 +429,7 @@ private extension XCTWaiter { func cancelPrimitiveWait() { guard let runLoop = runLoop else { return } -#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) +#if (os(macOS) || os(iOS) || os(tvOS) || os(watchOS)) && USE_FOUNDATION_FRAMEWORK CFRunLoopStop(runLoop.getCFRunLoop()) #else runLoop._stop() From f7c2f3502b2d99387bacce7d84e06ee7d838dfb9 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 22 Feb 2024 19:25:57 +0900 Subject: [PATCH 3/4] Do not link Foundation.framework given by Clang linker driver The Foundation.framework is usually implicitly linked by the Clang linker driver. However, we do not want to link it in XCTest because we use just built SwiftFoundation instead or we explicitly link it when USE_FOUNDATION_FRAMEWORK is on. --- XCTest.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/XCTest.xcodeproj/project.pbxproj b/XCTest.xcodeproj/project.pbxproj index 08bc3a76..58384c5d 100644 --- a/XCTest.xcodeproj/project.pbxproj +++ b/XCTest.xcodeproj/project.pbxproj @@ -518,6 +518,8 @@ "-framework", SwiftFoundation, "-weak-lswift_Concurrency", + "-nodefaultlibs", + "-lpthread", ); PRODUCT_BUNDLE_PACKAGE_TYPE = FMWK; SKIP_INSTALL = YES; @@ -543,6 +545,8 @@ "-framework", SwiftFoundation, "-weak-lswift_Concurrency", + "-nodefaultlibs", + "-lpthread", ); PRODUCT_BUNDLE_PACKAGE_TYPE = FMWK; SKIP_INSTALL = YES; From c0deeb1bbd51f4eb8e6c4c914cead8cbab3956c6 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Fri, 23 Feb 2024 03:33:03 +0900 Subject: [PATCH 4/4] Get rid of all implicit CoreFoundation dependencies * Disable autolinking of swiftCoreFoundation * Add `-nodefaultlibs` to the linker flags in tests --- Tests/Functional/lit.cfg | 2 ++ XCTest.xcodeproj/project.pbxproj | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Tests/Functional/lit.cfg b/Tests/Functional/lit.cfg index 78d6e1d9..9f384a98 100644 --- a/Tests/Functional/lit.cfg +++ b/Tests/Functional/lit.cfg @@ -72,6 +72,8 @@ if platform.system() == 'Darwin': # to use, due to a limitation in the Swift compiler. See SR-655 # for details. Here, we include the headers from CoreFoundation. '-I', os.path.join(built_products_dir, 'usr', 'local', 'include'), + '-Xclang-linker', '-nodefaultlibs', '-lpthread', + '-Xfrontend', '-disable-autolink-library', '-Xfrontend', 'swiftCoreFoundation' ]) else: # We need to jump through extra hoops to link swift-corelibs-foundation. diff --git a/XCTest.xcodeproj/project.pbxproj b/XCTest.xcodeproj/project.pbxproj index 58384c5d..feb8654a 100644 --- a/XCTest.xcodeproj/project.pbxproj +++ b/XCTest.xcodeproj/project.pbxproj @@ -521,6 +521,7 @@ "-nodefaultlibs", "-lpthread", ); + OTHER_SWIFT_FLAGS = "-Xfrontend -disable-autolink-library -Xfrontend swiftCoreFoundation"; PRODUCT_BUNDLE_PACKAGE_TYPE = FMWK; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx watchos watchsimulator"; @@ -548,6 +549,7 @@ "-nodefaultlibs", "-lpthread", ); + OTHER_SWIFT_FLAGS = "-Xfrontend -disable-autolink-library -Xfrontend swiftCoreFoundation"; PRODUCT_BUNDLE_PACKAGE_TYPE = FMWK; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx watchos watchsimulator";