Skip to content

Commit 61eb42c

Browse files
committed
Merge branch 'maxd/packagegraph-value-types' of github.com:apple/swift-package-manager into maxd/cross-compile-macros
# Conflicts: # Sources/Build/BuildDescription/ClangTargetBuildDescription.swift # Sources/Build/BuildDescription/ProductBuildDescription.swift # Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift # Sources/Build/BuildPlan/BuildPlan+Product.swift # Sources/Build/BuildPlan/BuildPlan.swift # Sources/PackageGraph/Resolution/ResolvedTarget.swift # Sources/PackageGraph/ResolvedProduct.swift
2 parents 790311f + 9ba50be commit 61eb42c

File tree

134 files changed

+3293
-2310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+3293
-2310
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Swift Next
77

88
On macOS, `swift build` and `swift run` now produce binaries that allow backtraces in debug builds. Pass `SWIFT_BACKTRACE=enable=yes` environment variable to enable backtraces on such binaries when running them.
99

10+
* [7101]
11+
12+
Binary artifacts are now cached along side repository checkouts so they do not need to be re-downloaded across projects.
13+
1014
Swift 5.9
1115
-----------
1216

@@ -378,3 +382,4 @@ Swift 3.0
378382
[#6276]: https://github.com/apple/swift-package-manager/pull/6276
379383
[#6540]: https://github.com/apple/swift-package-manager/pull/6540
380384
[#6663]: https://github.com/apple/swift-package-manager/pull/6663
385+
[#7101]: https://github.com/apple/swift-package-manager/pull/7101

CMakeLists.txt

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,17 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
cmake_minimum_required(VERSION 3.15.1)
9+
cmake_minimum_required(VERSION 3.19)
1010

1111
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
1212

1313
project(SwiftPM LANGUAGES C Swift)
1414

15-
set(SWIFT_VERSION 5)
16-
set(CMAKE_Swift_LANGUAGE_VERSION ${SWIFT_VERSION})
17-
if(CMAKE_VERSION VERSION_LESS 3.16)
18-
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-swift-version$<SEMICOLON>${SWIFT_VERSION}>)
19-
set(CMAKE_LINK_LIBRARY_FLAG "-l")
20-
endif()
21-
22-
add_compile_options(-DUSE_IMPL_ONLY_IMPORTS)
23-
15+
set(CMAKE_Swift_LANGUAGE_VERSION 5)
2416
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
2517

26-
if(CMAKE_VERSION VERSION_LESS 3.16 AND CMAKE_SYSTEM_NAME STREQUAL Windows)
27-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
28-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
29-
else()
30-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
31-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
32-
endif()
18+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
19+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
3320
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
3421

3522
option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)
@@ -44,6 +31,8 @@ if(BUILD_SHARED_LIBS)
4431
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
4532
endif()
4633

34+
add_compile_options(-DUSE_IMPL_ONLY_IMPORTS)
35+
4736
if(FIND_PM_DEPS)
4837
find_package(SwiftSystem CONFIG REQUIRED)
4938
find_package(TSC CONFIG REQUIRED)

Documentation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ We’ve designed the system to make it really easy to share packages on services
1919
* [Package manifest specification](PackageDescription.md)
2020
* [Getting Started with Plugins](Plugins.md)
2121
* [Package discovery with Package Collections](PackageCollections.md)
22-
* [Package Registry service specification](Registry.md)
22+
* [Package Registry service specification](PackageRegistry/Registry.md)
2323
* [Using SwiftPM as a library](libSwiftPM.md)
2424
* [Using Module Aliasing](ModuleAliasing.md)
2525

Documentation/ReleaseNotes/5.9.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SwiftPM 5.9 Release Notes
2+
3+
## Cross compilation
4+
5+
SwiftPM now supports cross compilation based on the Swift SDK bundle format. While the feature is still considered experimental, we invite users to try it out and provide feedback.
6+
7+
## Package registry
8+
9+
SwiftPM can now publish to a registry following the specification defined in SE-0391, as well as support signed packages, which may be required by a registry. Trust-on-first-use (TOFU) validation checks can now use signing identities in addition to fingerprints, and are enforced for source archives as well as package manifests.
10+
11+
## Embedded resources
12+
13+
Basic support for a new `.embedInCode` resource rule which allows embedding the contents of the resource into the executable code by generating a byte array
14+
15+
```
16+
struct PackageResources {
17+
static let best_txt: [UInt8] = [104,101,108,108,111,32,119,111,114,108,100,10]
18+
}
19+
```
20+
21+
## Other improvements
22+
23+
The `CompilerPluginSupport` module enables defining macro targets. Macro targets allow authoring and distributing custom Swift macros as APIs in a library.
24+
25+
Packages can use the new `package` access modifier, allowing access of symbols in another target / module within the same package without making them public. SwiftPM automatically sets the new compiler configuration to ensure this feature works out-of-the-box for packages.
26+
27+
The `allowNetworkConnections(scope:reason:)` setting gives a command plugin permissions to access the network. Permissions can be scoped to Unix domain sockets as well as local or remote IP connections, with an option to limit by port. For non-interactive use cases, the `--allow-network-connections` command-line flag allows network connections for a particular scope.
28+
29+
When a package contains a single target, sources may be distributed anywhere within the `./Sources` directory. If sources are placed in a subdirectory under `./Sources/<target>`, or there is more than one target, the existing expectation for sources apply
30+
31+
Build tool plugins can be used with C-family targets
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// swift-tools-version:4.2
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "EmptyTestsPkg",
6+
targets: [
7+
.target(
8+
name: "EmptyTestsPkg",
9+
dependencies: []),
10+
.testTarget(
11+
name: "EmptyTestsPkgTests",
12+
dependencies: ["EmptyTestsPkg"]),
13+
]
14+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
struct EmptyTests {
2+
3+
var text = "Hello, World!"
4+
var bool = false
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import XCTest
2+
@testable import EmptyTestsPkg

Sources/Basics/Archiver/Archiver.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public protocol Archiver {
2323
/// - archivePath: The `AbsolutePath` to the archive to extract.
2424
/// - destinationPath: The `AbsolutePath` to the directory to extract to.
2525
/// - completion: The completion handler that will be called when the operation finishes to notify of its success.
26+
@available(*, noasync, message: "Use the async alternative")
2627
func extract(
2728
from archivePath: AbsolutePath,
2829
to destinationPath: AbsolutePath,
@@ -35,6 +36,7 @@ public protocol Archiver {
3536
/// - directory: The `AbsolutePath` to the archive to extract.
3637
/// - destinationPath: The `AbsolutePath` to the directory to extract to.
3738
/// - completion: The completion handler that will be called when the operation finishes to notify of its success.
39+
@available(*, noasync, message: "Use the async alternative")
3840
func compress(
3941
directory: AbsolutePath,
4042
to destinationPath: AbsolutePath,
@@ -46,6 +48,7 @@ public protocol Archiver {
4648
/// - Parameters:
4749
/// - path: The `AbsolutePath` to the archive to validate.
4850
/// - completion: The completion handler that will be called when the operation finishes to notify of its success.
51+
@available(*, noasync, message: "Use the async alternative")
4952
func validate(
5053
path: AbsolutePath,
5154
completion: @escaping (Result<Bool, Error>) -> Void
@@ -57,8 +60,25 @@ extension Archiver {
5760
from archivePath: AbsolutePath,
5861
to destinationPath: AbsolutePath
5962
) async throws {
60-
try await withCheckedThrowingContinuation {
61-
self.extract(from: archivePath, to: destinationPath, completion: $0.resume(with:))
63+
try await safe_async {
64+
self.extract(from: archivePath, to: destinationPath, completion: $0)
65+
}
66+
}
67+
68+
public func compress(
69+
directory: AbsolutePath,
70+
to: AbsolutePath
71+
) async throws {
72+
try await safe_async {
73+
self.compress(directory: directory, to: to, completion: $0)
74+
}
75+
}
76+
77+
public func validate(
78+
path: AbsolutePath
79+
) async throws -> Bool {
80+
try await safe_async {
81+
self.validate(path: path, completion: $0)
6282
}
6383
}
6484
}

Sources/Basics/AuthorizationProvider.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public protocol AuthorizationProvider {
2323
}
2424

2525
public protocol AuthorizationWriter {
26+
@available(*, noasync, message: "Use the async alternative")
2627
func addOrUpdate(
2728
for url: URL,
2829
user: String,
@@ -31,9 +32,34 @@ public protocol AuthorizationWriter {
3132
callback: @escaping (Result<Void, Error>) -> Void
3233
)
3334

35+
@available(*, noasync, message: "Use the async alternative")
3436
func remove(for url: URL, callback: @escaping (Result<Void, Error>) -> Void)
3537
}
3638

39+
public extension AuthorizationWriter {
40+
func addOrUpdate(
41+
for url: URL,
42+
user: String,
43+
password: String,
44+
persist: Bool = true
45+
) async throws {
46+
try await safe_async {
47+
self.addOrUpdate(
48+
for: url,
49+
user: user,
50+
password: password,
51+
persist: persist,
52+
callback: $0)
53+
}
54+
}
55+
56+
func remove(for url: URL) async throws {
57+
try await safe_async {
58+
self.remove(for: url, callback: $0)
59+
}
60+
}
61+
}
62+
3763
public enum AuthorizationProviderError: Error {
3864
case invalidURLHost
3965
case notFound

Sources/Basics/Concurrency/ConcurrencyHelpers.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import _Concurrency
1314
import Dispatch
1415
import class Foundation.NSLock
1516
import class Foundation.ProcessInfo
@@ -46,6 +47,34 @@ extension DispatchQueue {
4647
)
4748
}
4849

50+
/// Bridges between potentially blocking methods that take a result completion closure and async/await
51+
public func safe_async<T, ErrorType: Error>(_ body: @Sendable @escaping (@Sendable @escaping (Result<T, ErrorType>) -> Void) -> Void) async throws -> T {
52+
try await withCheckedThrowingContinuation { continuation in
53+
// It is possible that body make block indefinitely on a lock, sempahore,
54+
// or similar then synchrously call the completion handler. For full safety
55+
// it is essential to move the execution off the swift concurrency pool
56+
DispatchQueue.sharedConcurrent.async {
57+
body {
58+
continuation.resume(with: $0)
59+
}
60+
}
61+
}
62+
}
63+
64+
/// Bridges between potentially blocking methods that take a result completion closure and async/await
65+
public func safe_async<T>(_ body: @escaping (@escaping (Result<T, Never>) -> Void) -> Void) async -> T {
66+
await withCheckedContinuation { continuation in
67+
// It is possible that body make block indefinitely on a lock, sempahore,
68+
// or similar then synchrously call the completion handler. For full safety
69+
// it is essential to move the execution off the swift concurrency pool
70+
DispatchQueue.sharedConcurrent.async {
71+
body {
72+
continuation.resume(with: $0)
73+
}
74+
}
75+
}
76+
}
77+
4978
#if !canImport(Darwin)
5079
// As of Swift 5.7 and 5.8 swift-corelibs-foundation doesn't have `Sendable` annotations yet.
5180
extension URL: @unchecked Sendable {}

Sources/Basics/Dictionary+Extensions.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import OrderedCollections
14-
1513
extension Dictionary {
1614
@inlinable
1715
@discardableResult
@@ -36,15 +34,3 @@ extension Dictionary {
3634
}
3735
}
3836
}
39-
40-
/*
41-
extension OrderedDictionary {
42-
public subscript(key: Key, `default` `default`: Value) -> Value {
43-
set {
44-
self[key] = newValue
45-
} get {
46-
self[key] ?? `default`
47-
}
48-
}
49-
}
50-
*/

Sources/Basics/FileSystem/TemporaryFile.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public func withTemporaryDirectory<Result>(
6666
/// return value for the `withTemporaryDirectory` function.
6767
///
6868
/// - Throws: An error when creating directory and rethrows all errors from `body`.
69+
@discardableResult
6970
public func withTemporaryDirectory<Result>(
7071
fileSystem: FileSystem = localFileSystem,
7172
dir: AbsolutePath? = nil,

Sources/Build/BuildDescription/ClangTargetBuildDescription.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Basics
1414
import PackageLoading
1515
import PackageModel
16-
import class PackageGraph.ResolvedTarget
16+
import struct PackageGraph.ResolvedTarget
1717
import struct SPMBuildCore.BuildParameters
1818
import struct SPMBuildCore.BuildToolPluginInvocationResult
1919
import struct SPMBuildCore.PrebuildCommandResult
@@ -27,7 +27,7 @@ public final class ClangTargetBuildDescription {
2727

2828
/// The underlying clang target.
2929
public var clangTarget: ClangTarget {
30-
target.underlyingTarget as! ClangTarget
30+
target.underlying as! ClangTarget
3131
}
3232

3333
/// The tools version of the package that declared the target. This can
@@ -45,7 +45,7 @@ public final class ClangTargetBuildDescription {
4545

4646
/// The list of all resource files in the target, including the derived ones.
4747
public var resources: [Resource] {
48-
self.target.underlyingTarget.resources + self.pluginDerivedResources
48+
self.target.underlying.resources + self.pluginDerivedResources
4949
}
5050

5151
/// Path to the bundle generated for this module (if any).
@@ -54,7 +54,7 @@ public final class ClangTargetBuildDescription {
5454
return .none
5555
}
5656

57-
if let bundleName = self.target.underlyingTarget.potentialBundleName {
57+
if let bundleName = target.underlying.potentialBundleName {
5858
return self.buildParameters.bundlePath(named: bundleName, target: self.target)
5959
} else {
6060
return .none
@@ -124,7 +124,7 @@ public final class ClangTargetBuildDescription {
124124
fileSystem: FileSystem,
125125
observabilityScope: ObservabilityScope
126126
) throws {
127-
guard target.underlyingTarget is ClangTarget else {
127+
guard target.underlying is ClangTarget else {
128128
throw InternalError("underlying target type mismatch \(target)")
129129
}
130130

Sources/Build/BuildDescription/PluginDescription.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public final class PluginDescription: Codable {
5050
testDiscoveryTarget: Bool = false,
5151
fileSystem: FileSystem
5252
) throws {
53-
guard target.underlyingTarget is PluginTarget else {
53+
guard target.underlying is PluginTarget else {
5454
throw InternalError("underlying target type mismatch \(target)")
5555
}
5656

Sources/Build/BuildDescription/ProductBuildDescription.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
241241
// Support for linking tests against executables is conditional on the tools
242242
// version of the package that defines the executable product.
243243
let executableTarget = try product.executableTarget
244-
if let target = executableTarget.underlyingTarget as? SwiftTarget,
244+
if let target = executableTarget.underlying as? SwiftTarget,
245245
self.toolsVersion >= .v5_5,
246246
self.buildParameters.driverParameters.canRenameEntrypointFunctionName,
247247
target.supportsTestableExecutablesFeature
@@ -291,7 +291,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
291291
// When deploying to macOS prior to macOS 12, add an rpath to the
292292
// back-deployed concurrency libraries.
293293
if useStdlibRpath, buildTriple.isMacOSX {
294-
let macOSSupportedPlatform = self.package.platforms.getDerived(for: .macOS, usingXCTest: product.isLinkingXCTest)
294+
let macOSSupportedPlatform = self.package.getDerived(for: .macOS, usingXCTest: product.isLinkingXCTest)
295295
if macOSSupportedPlatform.version.major < 12 {
296296
let backDeployedStdlib = try buildParameters.toolchain.macosSwiftStdlib
297297
.parentDirectory

Sources/Build/BuildDescription/SharedTargetBuildDescription.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct SharedTargetBuildDescription {
5353
additionalFileRules: additionalFileRules,
5454
defaultLocalization: target.defaultLocalization,
5555
targetName: target.name,
56-
targetPath: target.underlyingTarget.path,
56+
targetPath: target.underlying.path,
5757
observabilityScope: observabilityScope
5858
)
5959
let pluginDerivedResources = derivedResources

0 commit comments

Comments
 (0)