Skip to content

Commit 240f501

Browse files
authored
Only include the platform PrivateFrameworks directory as a runtime, not build-time, search path (#9518)
This constrains a behavior I landed in #8199 so that it only includes the `PrivateFrameworks` directory from Xcode's platform directory (when present) as a **runtime** framework search path (via `DYLD_FRAMEWORK_PATH`) and no longer includes it as a _build-time_ framework search path (via `-F <path>`). ### Motivation: This is a follow-up to a change I made in #8199. Those changes had an undesirable side effect of including private frameworks in all builds, and means that when those frameworks are present at build time, they're included in client builds and can be `import`'ed or linked. Exposing those frameworks to clients at _build-time_ was not intended, and can cause unexpected results or failures if (for example) those private frameworks themselves contain unresolvable module imports. However, platform private frameworks directories _should_ continue to be included in runtime framework search paths, so they can be located and loaded when referenced by public frameworks/libraries. ### Modifications: - Introduce separate properties for build-time vs. runtime framework and library search paths, so the two categories can be differentiated by callers. - Omit the private frameworks search path from the new build-time frameworks property. - Adopt the relevant new properties at both build and runtime usage sites. ### Result: After this change, I validated that: - a local package build no longer contains the private frameworks search path entry at build time, using `swift build --build-tests --verbose`, and - a local package test operation still includes the search path, using `env DYLD_PRINT_ENV=1 swift test`.
1 parent f7ff31e commit 240f501

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

Sources/Commands/Utilities/TestingSupport.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,10 @@ enum TestingSupport {
242242
// Since XCTestHelper targets macOS, we need the macOS platform paths here.
243243
if let sdkPlatformPaths = try? SwiftSDK.sdkPlatformPaths(for: .macOS) {
244244
// appending since we prefer the user setting (if set) to the one we inject
245-
for frameworkPath in sdkPlatformPaths.frameworks {
245+
for frameworkPath in sdkPlatformPaths.runtimeFrameworkSearchPaths {
246246
env.appendPath(key: "DYLD_FRAMEWORK_PATH", value: frameworkPath.pathString)
247247
}
248-
for libraryPath in sdkPlatformPaths.libraries {
248+
for libraryPath in sdkPlatformPaths.runtimeLibrarySearchPaths {
249249
env.appendPath(key: "DYLD_LIBRARY_PATH", value: libraryPath.pathString)
250250
}
251251
}

Sources/PackageModel/SwiftSDKs/SwiftSDK.swift

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,10 @@ public struct SwiftSDK: Equatable {
593593
#if os(macOS)
594594
do {
595595
let sdkPaths = try SwiftSDK.sdkPlatformPaths(for: darwinPlatform, environment: environment)
596-
extraCCFlags.append(contentsOf: sdkPaths.frameworks.flatMap { ["-F", $0.pathString] })
597-
extraSwiftCFlags.append(contentsOf: sdkPaths.frameworks.flatMap { ["-F", $0.pathString] })
598-
extraSwiftCFlags.append(contentsOf: sdkPaths.libraries.flatMap { ["-I", $0.pathString] })
599-
extraSwiftCFlags.append(contentsOf: sdkPaths.libraries.flatMap { ["-L", $0.pathString] })
596+
extraCCFlags.append(contentsOf: sdkPaths.buildTimeFrameworkSearchPaths.flatMap { ["-F", $0.pathString] })
597+
extraSwiftCFlags.append(contentsOf: sdkPaths.buildTimeFrameworkSearchPaths.flatMap { ["-F", $0.pathString] })
598+
extraSwiftCFlags.append(contentsOf: sdkPaths.buildTimeLibrarySearchPaths.flatMap { ["-I", $0.pathString] })
599+
extraSwiftCFlags.append(contentsOf: sdkPaths.buildTimeLibrarySearchPaths.flatMap { ["-L", $0.pathString] })
600600
xctestSupport = .supported
601601
} catch {
602602
xctestSupport = .unsupported(reason: String(describing: error))
@@ -628,11 +628,21 @@ public struct SwiftSDK: Equatable {
628628
///
629629
/// - SeeAlso: ``sdkPlatformPaths(for:environment:)``
630630
public struct PlatformPaths {
631-
/// Paths of directories containing auxiliary platform frameworks.
632-
public var frameworks: [Basics.AbsolutePath]
631+
/// Paths of directories containing auxiliary platform frameworks which
632+
/// should be included as framework search paths at build time.
633+
public var buildTimeFrameworkSearchPaths: [Basics.AbsolutePath]
633634

634-
/// Paths of directories containing auxiliary platform libraries.
635-
public var libraries: [Basics.AbsolutePath]
635+
/// Paths of directories containing auxiliary platform libraries which
636+
/// should be included as library search paths at build time.
637+
public var buildTimeLibrarySearchPaths: [Basics.AbsolutePath]
638+
639+
/// Paths of directories containing auxiliary platform frameworks which
640+
/// should be included as framework search paths at runtime.
641+
public var runtimeFrameworkSearchPaths: [Basics.AbsolutePath]
642+
643+
/// Paths of directories containing auxiliary platform libraries which
644+
/// should be included as library search paths at runtime.
645+
public var runtimeLibrarySearchPaths: [Basics.AbsolutePath]
636646
}
637647

638648
/// Returns `macosx` sdk platform framework path.
@@ -641,10 +651,10 @@ public struct SwiftSDK: Equatable {
641651
environment: Environment = .current
642652
) throws -> (fwk: Basics.AbsolutePath, lib: Basics.AbsolutePath) {
643653
let paths = try sdkPlatformPaths(for: .macOS, environment: environment)
644-
guard let frameworkPath = paths.frameworks.first else {
654+
guard let frameworkPath = paths.buildTimeFrameworkSearchPaths.first else {
645655
throw StringError("could not determine SDK platform framework path")
646656
}
647-
guard let libraryPath = paths.libraries.first else {
657+
guard let libraryPath = paths.buildTimeLibrarySearchPaths.first else {
648658
throw StringError("could not determine SDK platform library path")
649659
}
650660
return (fwk: frameworkPath, lib: libraryPath)
@@ -682,7 +692,12 @@ public struct SwiftSDK: Equatable {
682692
components: "Developer", "usr", "lib"
683693
)
684694

685-
let sdkPlatformFrameworkPath = PlatformPaths(frameworks: [frameworksPath, privateFrameworksPath], libraries: [librariesPath])
695+
let sdkPlatformFrameworkPath = PlatformPaths(
696+
buildTimeFrameworkSearchPaths: [frameworksPath /* omit privateFrameworksPath */],
697+
buildTimeLibrarySearchPaths: [librariesPath],
698+
runtimeFrameworkSearchPaths: [frameworksPath, privateFrameworksPath],
699+
runtimeLibrarySearchPaths: [librariesPath]
700+
)
686701
_sdkPlatformFrameworkPath[darwinPlatform] = sdkPlatformFrameworkPath
687702
return sdkPlatformFrameworkPath
688703
}

0 commit comments

Comments
 (0)