Skip to content

Bifurcate SwiftPM library locations #7212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Sources/PackageLoading/ManifestLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1081,14 +1081,15 @@ public final class ManifestLoader: ManifestLoaderProtocol {
for toolsVersion: ToolsVersion
) -> [String] {
var cmd = [String]()
let runtimePath = self.toolchain.swiftPMLibrariesLocation.manifestLibraryPath
let libraryPath = self.toolchain.swiftPMLibrariesLocation.manifestLibraryPath
let modulesPath = self.toolchain.swiftPMLibrariesLocation.manifestModulesPath
cmd += ["-swift-version", toolsVersion.swiftLanguageVersion.rawValue]
// if runtimePath is set to "PackageFrameworks" that means we could be developing SwiftPM in Xcode
// which produces a framework for dynamic package products.
if runtimePath.extension == "framework" {
cmd += ["-I", runtimePath.parentDirectory.parentDirectory.pathString]
if modulesPath.extension == "framework" {
cmd += ["-I", modulesPath.parentDirectory.parentDirectory.pathString]
} else {
cmd += ["-I", runtimePath.pathString]
cmd += ["-I", modulesPath.pathString]
}
#if os(macOS)
if let sdkRoot = self.toolchain.sdkRootPath ?? self.sdkRoot() {
Expand Down
24 changes: 22 additions & 2 deletions Sources/PackageModel/ToolchainConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,18 @@ public struct ToolchainConfiguration {
extension ToolchainConfiguration {
public struct SwiftPMLibrariesLocation {
public var manifestLibraryPath: AbsolutePath
public var manifestModulesPath: AbsolutePath
public var pluginLibraryPath: AbsolutePath

public init(manifestLibraryPath: AbsolutePath, manifestLibraryMinimumDeploymentTarget: PlatformVersion? = nil, pluginLibraryPath: AbsolutePath, pluginLibraryMinimumDeploymentTarget: PlatformVersion? = nil) {
public var pluginModulesPath: AbsolutePath

public init(
manifestLibraryPath: AbsolutePath,
manifestModulesPath: AbsolutePath? = nil,
manifestLibraryMinimumDeploymentTarget: PlatformVersion? = nil,
pluginLibraryPath: AbsolutePath,
pluginModulesPath: AbsolutePath? = nil,
pluginLibraryMinimumDeploymentTarget: PlatformVersion? = nil
) {
#if os(macOS)
if let manifestLibraryMinimumDeploymentTarget {
self.manifestLibraryMinimumDeploymentTarget = manifestLibraryMinimumDeploymentTarget
Expand All @@ -102,7 +111,18 @@ extension ToolchainConfiguration {
#endif

self.manifestLibraryPath = manifestLibraryPath
if let manifestModulesPath {
self.manifestModulesPath = manifestModulesPath
} else {
self.manifestModulesPath = manifestLibraryPath
}

self.pluginLibraryPath = pluginLibraryPath
if let pluginModulesPath {
self.pluginModulesPath = pluginModulesPath
} else {
self.pluginModulesPath = pluginLibraryPath
}
}

public init(root: AbsolutePath, manifestLibraryMinimumDeploymentTarget: PlatformVersion? = nil, pluginLibraryMinimumDeploymentTarget: PlatformVersion? = nil) {
Expand Down
12 changes: 11 additions & 1 deletion Sources/PackageModel/UserToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,19 @@ public final class UserToolchain: Toolchain {

// this tests if we are debugging / testing SwiftPM with SwiftPM
if localFileSystem.exists(applicationPath.appending("swift-package")) {
// Newer versions of SwiftPM will emit modules to a "Modules" subdirectory, but we're also staying compatible with older versions for development.
let modulesPath: AbsolutePath
if localFileSystem.exists(applicationPath.appending("Modules")) {
modulesPath = applicationPath.appending("Modules")
} else {
modulesPath = applicationPath
}

return .init(
manifestLibraryPath: applicationPath,
pluginLibraryPath: applicationPath
manifestModulesPath: modulesPath,
pluginLibraryPath: applicationPath,
pluginModulesPath: modulesPath
)
}
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/Workspace/DefaultPluginScriptRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {

// Get access to the path containing the PackagePlugin module and library.
let pluginLibraryPath = self.toolchain.swiftPMLibrariesLocation.pluginLibraryPath
let pluginModulesPath = self.toolchain.swiftPMLibrariesLocation.pluginModulesPath

// if runtimePath is set to "PackageFrameworks" that means we could be developing SwiftPM in Xcode
// which produces a framework for dynamic package products.
Expand Down Expand Up @@ -196,10 +197,10 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {

// if runtimePath is set to "PackageFrameworks" that means we could be developing SwiftPM in Xcode
// which produces a framework for dynamic package products.
if pluginLibraryPath.extension == "framework" {
commandLine += ["-I", pluginLibraryPath.parentDirectory.parentDirectory.pathString]
if pluginModulesPath.extension == "framework" {
commandLine += ["-I", pluginModulesPath.parentDirectory.parentDirectory.pathString]
} else {
commandLine += ["-I", pluginLibraryPath.pathString]
commandLine += ["-I", pluginModulesPath.pathString]
}
#if os(macOS)
if let sdkRoot = self.toolchain.sdkRootPath ?? self.sdkRoot() {
Expand Down