Skip to content
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

Fix package access modifier in XCBuild support #7258

Merged
merged 37 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8f6bfe8
Fix `package` access modifier in XCBuild support
MaxDesiatov Jan 16, 2024
582cd2b
Fix formatting, remove excessive `print`, reduce the diff
MaxDesiatov Jan 16, 2024
9b9d0ed
Enable `testPackageNameFlagXCBuild` only on macOS
MaxDesiatov Jan 16, 2024
796c1b1
Fix CMake build
MaxDesiatov Jan 16, 2024
82a22b3
Address PR feedback
MaxDesiatov Jan 16, 2024
2f60251
Add missing `SwiftDriver` dependency to `XCBuildSupport`
MaxDesiatov Jan 16, 2024
427b518
Update BuildParameters.swift
MaxDesiatov Jan 16, 2024
eea30f4
Merge branch 'main' into maxd/fix-xcbuild-package-name
MaxDesiatov Jan 17, 2024
46d01e5
Replace `package` modifier with `@testable` at place of use
MaxDesiatov Jan 19, 2024
bb2f876
Merge branch 'main' of github.com:apple/swift-package-manager into ma…
MaxDesiatov Jan 19, 2024
6e49171
Replace `package` with `@_spi(SwiftPMInternal)`
MaxDesiatov Jan 19, 2024
42c868a
Fix remaining use of `package var`
MaxDesiatov Jan 19, 2024
6bbf6e2
Fix use of `package func`
MaxDesiatov Jan 19, 2024
031ead4
Add required `@_spi(SwiftPMInternal)` on imports
MaxDesiatov Jan 19, 2024
44d7267
Update `SourceKitLSPAPI/CMakeLists.txt`
MaxDesiatov Jan 22, 2024
4d4a8f4
Update `XCBuildSupport/CMakeLists.txt`
MaxDesiatov Jan 22, 2024
e23f9c7
Update `swift-bootstrap/CMakeLists.txt`
MaxDesiatov Jan 22, 2024
553f559
Update `SwiftSDKTool/CMakeLists.txt`
MaxDesiatov Jan 23, 2024
95ff5da
Update `swift-experimental-sdk/CMakeLists.txt`
MaxDesiatov Jan 24, 2024
e83dc69
Update `swift-build/CMakeLists.txt`
MaxDesiatov Jan 26, 2024
35d949b
Update `swift-package/CMakeLists.txt`
MaxDesiatov Jan 26, 2024
3be01c3
Update `swift-run/CMakeLists.txt`
MaxDesiatov Jan 26, 2024
1565886
Update `swift-test/CMakeLists.txt`
MaxDesiatov Jan 26, 2024
e293b7e
Merge branch 'main' of github.com:apple/swift-package-manager into ma…
MaxDesiatov Feb 16, 2024
c57d3f5
Clean up `DriverSupport` imports
MaxDesiatov Feb 16, 2024
398dd3e
More cleanups
MaxDesiatov Feb 16, 2024
7749bab
Add `DriverSupport` missing in `swift-bootstrap` CMake
MaxDesiatov Feb 16, 2024
df2daf5
Add `SwiftDriver` as `PRIVATE` requirement to `target_link_libraries`
MaxDesiatov Feb 17, 2024
888e657
Merge branch 'main' of github.com:apple/swift-package-manager into ma…
MaxDesiatov Feb 21, 2024
8124f79
Merge branch 'main' of github.com:apple/swift-package-manager into ma…
MaxDesiatov Feb 23, 2024
f9b7f1a
Reduce diff to `main`
MaxDesiatov Feb 23, 2024
af4e9e6
Add `@_spi(SwiftPMInternal)` on `isPackageNameSupported`
MaxDesiatov Feb 23, 2024
3d7fab2
Reduce diff to `main`
MaxDesiatov Feb 23, 2024
2f7e094
Add missing `SwiftDriver` requirement to `swift-bootstrap/CMakeLists.…
MaxDesiatov Feb 23, 2024
7ca0f81
Define `DISABLE_XCBUILD_SUPPORT` in `swift-bootstrap/CMakeLists.txt`
MaxDesiatov Feb 23, 2024
79f68c3
Remove unused imports
MaxDesiatov Feb 23, 2024
b13d173
Merge branch 'main' into maxd/fix-xcbuild-package-name
MaxDesiatov Feb 23, 2024
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
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -349,7 +349,7 @@ let package = Package(
.target(
/** Support for building using Xcode's build system */
name: "XCBuildSupport",
dependencies: ["SPMBuildCore", "PackageGraph"],
dependencies: ["DriverSupport", "SPMBuildCore", "PackageGraph"],
exclude: ["CMakeLists.txt", "CODEOWNERS"]
),
.target(
Expand Down
36 changes: 21 additions & 15 deletions Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
//===----------------------------------------------------------------------===//

import Basics

import Foundation
import PackageGraph
import PackageLoading
import PackageModel

@_spi(SwiftPMInternal)
import SPMBuildCore

#if USE_IMPL_ONLY_IMPORTS
Expand Down Expand Up @@ -419,18 +422,6 @@ public final class SwiftTargetBuildDescription {
try self.fileSystem.writeIfChanged(path: path, string: content)
}

private func packageNameArgumentIfSupported(with pkg: ResolvedPackage, packageAccess: Bool) -> [String] {
let flag = "-package-name"
if pkg.manifest.usePackageNameFlag,
DriverSupport.checkToolchainDriverFlags(flags: [flag], toolchain: self.buildParameters.toolchain, fileSystem: self.fileSystem) {
if packageAccess {
let pkgID = pkg.identity.description.spm_mangledToC99ExtendedIdentifier()
return [flag, pkgID]
}
}
return []
}

private func macroArguments() throws -> [String] {
var args = [String]()

Expand All @@ -450,7 +441,14 @@ public final class SwiftTargetBuildDescription {
#endif

// If we're using an OSS toolchain, add the required arguments bringing in the plugin server from the default toolchain if available.
if self.buildParameters.toolchain.isSwiftDevelopmentToolchain, DriverSupport.checkSupportedFrontendFlags(flags: ["-external-plugin-path"], toolchain: self.buildParameters.toolchain, fileSystem: self.fileSystem), let pluginServer = try self.buildParameters.toolchain.swiftPluginServerPath {
if self.buildParameters.toolchain.isSwiftDevelopmentToolchain,
DriverSupport.checkSupportedFrontendFlags(
flags: ["-external-plugin-path"],
toolchain: self.buildParameters.toolchain,
fileSystem: self.fileSystem
),
let pluginServer = try self.buildParameters.toolchain.swiftPluginServerPath
{
let toolchainUsrPath = pluginServer.parentDirectory.parentDirectory
let pluginPathComponents = ["lib", "swift", "host", "plugins"]

Expand Down Expand Up @@ -631,7 +629,10 @@ public final class SwiftTargetBuildDescription {
args += ["-user-module-version", version.description]
}

args += self.packageNameArgumentIfSupported(with: self.package, packageAccess: self.target.packageAccess)
args += self.package.packageNameArgument(
target: self.target,
isPackageNameSupported: self.buildParameters.driverParameters.isPackageAccessModifierSupported
)
args += try self.macroArguments()

// rdar://117578677
Expand All @@ -656,7 +657,12 @@ public final class SwiftTargetBuildDescription {

result.append("-module-name")
result.append(self.target.c99name)
result.append(contentsOf: packageNameArgumentIfSupported(with: self.package, packageAccess: self.target.packageAccess))
result.append(
contentsOf: self.package.packageNameArgument(
target: self.target,
isPackageNameSupported: self.buildParameters.driverParameters.isPackageAccessModifierSupported
)
)
if !scanInvocation {
result.append("-emit-dependencies")

Expand Down
13 changes: 10 additions & 3 deletions Sources/CoreCommands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand All @@ -23,8 +23,11 @@ import SPMBuildCore
import Workspace

#if USE_IMPL_ONLY_IMPORTS
@_implementationOnly import DriverSupport
@_implementationOnly
@_spi(SwiftPMInternal)
import DriverSupport
#else
@_spi(SwiftPMInternal)
import DriverSupport
#endif

Expand Down Expand Up @@ -757,7 +760,11 @@ public final class SwiftTool {
enableParseableModuleInterfaces: options.build.shouldEnableParseableModuleInterfaces,
explicitTargetDependencyImportCheckingMode: options.build.explicitTargetDependencyImportCheck.modeParameter,
useIntegratedSwiftDriver: options.build.useIntegratedSwiftDriver,
useExplicitModuleBuild: options.build.useExplicitModuleBuild
useExplicitModuleBuild: options.build.useExplicitModuleBuild,
isPackageAccessModifierSupported: DriverSupport.isPackageNameSupported(
toolchain: toolchain,
fileSystem: self.fileSystem
)
),
linkingParameters: .init(
linkerDeadStrip: options.linker.linkerDeadStrip,
Expand Down
11 changes: 8 additions & 3 deletions Sources/DriverSupport/DriverSupportUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2022 Apple Inc. and the Swift project authors
// Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand All @@ -20,7 +20,7 @@ import struct TSCBasic.ProcessResult
public enum DriverSupport {
private static var flagsMap = ThreadSafeBox<[String: Set<String>]>()

// This checks _frontend_ supported flags, which are not necessarily supported in the driver.
/// This checks _frontend_ supported flags, which are not necessarily supported in the driver.
public static func checkSupportedFrontendFlags(
flags: Set<String>,
toolchain: PackageModel.Toolchain,
Expand Down Expand Up @@ -54,7 +54,7 @@ public enum DriverSupport {
// This checks if given flags are supported in the built-in toolchain driver. Currently
// there's no good way to get the supported flags from it, so run `swiftc -h` directly
// to get the flags and cache the result.
public static func checkToolchainDriverFlags(
static func checkToolchainDriverFlags(
flags: Set<String>,
toolchain: PackageModel.Toolchain,
fileSystem: FileSystem
Expand Down Expand Up @@ -83,4 +83,9 @@ public enum DriverSupport {
return false
}
}

@_spi(SwiftPMInternal)
public static func isPackageNameSupported(toolchain: PackageModel.Toolchain, fileSystem: FileSystem) -> Bool {
DriverSupport.checkToolchainDriverFlags(flags: ["-package-name"], toolchain: toolchain, fileSystem: fileSystem)
}
}
2 changes: 1 addition & 1 deletion Sources/PackageModel/Target/SwiftTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand All @@ -25,13 +25,15 @@ extension BuildParameters {
enableParseableModuleInterfaces: Bool = false,
explicitTargetDependencyImportCheckingMode: TargetDependencyImportCheckingMode = .none,
useIntegratedSwiftDriver: Bool = false,
useExplicitModuleBuild: Bool = false
useExplicitModuleBuild: Bool = false,
isPackageAccessModifierSupported: Bool = false
) {
self.canRenameEntrypointFunctionName = canRenameEntrypointFunctionName
self.enableParseableModuleInterfaces = enableParseableModuleInterfaces
self.explicitTargetDependencyImportCheckingMode = explicitTargetDependencyImportCheckingMode
self.useIntegratedSwiftDriver = useIntegratedSwiftDriver
self.useExplicitModuleBuild = useExplicitModuleBuild
self.isPackageAccessModifierSupported = isPackageAccessModifierSupported
}

/// Whether to enable the entry-point-function-name feature.
Expand All @@ -45,11 +47,16 @@ extension BuildParameters {
/// `.swiftmodule`s.
public var enableParseableModuleInterfaces: Bool

/// Whether to use the integrated Swift driver rather than shelling out
/// Whether to use the integrated Swift Driver rather than shelling out
/// to a separate process.
public var useIntegratedSwiftDriver: Bool

/// Whether to use the explicit module build flow (with the integrated driver).
public var useExplicitModuleBuild: Bool

/// Whether the version of Swift Driver used in the currently selected toolchain
/// supports `-package-name` options.
@_spi(SwiftPMInternal)
public var isPackageAccessModifierSupported: Bool
}
}
1 change: 1 addition & 0 deletions Sources/SPMBuildCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_library(SPMBuildCore
Plugins/PluginMessages.swift
Plugins/PluginScriptRunner.swift
PrebuildCommandResult.swift
ResolvedPackage+Extensions.swift
Triple+Extensions.swift
XCFrameworkMetadata.swift)
# NOTE(compnerd) workaround for CMake not setting up include flags yet
Expand Down
25 changes: 25 additions & 0 deletions Sources/SPMBuildCore/ResolvedPackage+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import struct PackageGraph.ResolvedPackage
import struct PackageGraph.ResolvedTarget

extension ResolvedPackage {
@_spi(SwiftPMInternal)
public func packageNameArgument(target: ResolvedTarget, isPackageNameSupported: Bool) -> [String] {
if self.manifest.usePackageNameFlag, target.packageAccess {
["-package-name", self.identity.description.spm_mangledToC99ExtendedIdentifier()]
} else {
[]
}
}
}
Loading