Skip to content

Commit ad1edc2

Browse files
committed
Revert "Revert "Support macros when cross-compiling (#7118)" (#7352)" (#7353)
Reverts #7352. Modified to build tests for the host triple when any macros are added to test modules directly as dependencies. (cherry picked from commit cb3b085) # Conflicts: # CHANGELOG.md # Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift # Sources/Build/BuildManifest/LLBuildManifestBuilder.swift # Sources/Build/BuildPlan/BuildPlan.swift # Sources/Commands/SwiftTestCommand.swift # Sources/Commands/Utilities/PluginDelegate.swift # Sources/Commands/Utilities/TestingSupport.swift # Sources/PackageGraph/ModulesGraph+Loading.swift # Sources/PackageGraph/ModulesGraph.swift # Sources/SPMTestSupport/MockBuildTestHelper.swift # Sources/SPMTestSupport/MockPackageGraphs.swift # Sources/SPMTestSupport/PackageGraphTester.swift # Sources/SPMTestSupport/ResolvedTarget+Mock.swift # Tests/BuildTests/ClangTargetBuildDescriptionTests.swift # Tests/BuildTests/CrossCompilationBuildPlanTests.swift # Tests/SourceKitLSPAPITests/SourceKitLSPAPITests.swift
1 parent 9afe748 commit ad1edc2

File tree

53 files changed

+1393
-462
lines changed

Some content is hidden

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

53 files changed

+1393
-462
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ Swift 6.0
2727

2828
`// swift-tools-version:` can now be specified on subsequent lines of `Package.swift`, for example when first few lines are required to contain a licensing comment header.
2929

30+
* [#7118]
31+
32+
Macros cross-compiled by SwiftPM with Swift SDKs are now correctly built, loaded, and evaluated for the host triple.
33+
3034
Swift 5.10
3135
-----------
36+
3237
* [#7010]
3338

3439
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.
3540

36-
* [7101]
41+
* [#7101]
3742

3843
Binary artifacts are now cached along side repository checkouts so they do not need to be re-downloaded across projects.
3944

Sources/Basics/Collections/IdentifiableSet.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,22 @@ public struct IdentifiableSet<Element: Identifiable>: Collection {
4747
}
4848

4949
public subscript(id: Element.ID) -> Element? {
50-
self.storage[id]
50+
get {
51+
self.storage[id]
52+
}
53+
set {
54+
self.storage[id] = newValue
55+
}
5156
}
5257

5358
public func index(after i: Index) -> Index {
5459
Index(storageIndex: self.storage.elements.index(after: i.storageIndex))
5560
}
5661

62+
public mutating func insert(_ element: Element) {
63+
self.storage[element.id] = element
64+
}
65+
5766
public func union(_ otherSequence: some Sequence<Element>) -> Self {
5867
var result = self
5968
for element in otherSequence {

Sources/Build/BuildDescription/ClangTargetBuildDescription.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public final class ClangTargetBuildDescription {
5353

5454
/// Path to the bundle generated for this module (if any).
5555
var bundlePath: AbsolutePath? {
56-
guard !resources.isEmpty else {
56+
guard !self.resources.isEmpty else {
5757
return .none
5858
}
5959

@@ -133,7 +133,7 @@ public final class ClangTargetBuildDescription {
133133
self.target = target
134134
self.toolsVersion = toolsVersion
135135
self.buildParameters = buildParameters
136-
self.tempsPath = buildParameters.buildPath.appending(component: target.c99name + ".build")
136+
self.tempsPath = target.tempsPath(buildParameters)
137137
self.derivedSources = Sources(paths: [], root: tempsPath.appending("DerivedSources"))
138138

139139
// We did not use to apply package plugins to C-family targets in prior tools-versions, this preserves the behavior.
@@ -225,7 +225,7 @@ public final class ClangTargetBuildDescription {
225225
if self.buildParameters.triple.isDarwin() {
226226
args += ["-fobjc-arc"]
227227
}
228-
args += try buildParameters.targetTripleArgs(for: target)
228+
args += try self.buildParameters.tripleArgs(for: target)
229229

230230
args += optimizationArguments
231231
args += activeCompilationConditions

Sources/Build/BuildDescription/ProductBuildDescription.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
322322
// setting is the package-level right now. We might need to figure out a better
323323
// answer for libraries if/when we support specifying deployment target at the
324324
// target-level.
325-
args += try self.buildParameters.targetTripleArgs(for: self.product.targets[self.product.targets.startIndex])
325+
args += try self.buildParameters.tripleArgs(for: self.product.targets[self.product.targets.startIndex])
326326

327327
// Add arguments from declared build settings.
328328
args += self.buildSettingsFlags
@@ -357,7 +357,7 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
357357
// Library search path for the toolchain's copy of SwiftSyntax.
358358
#if BUILD_MACROS_AS_DYLIBS
359359
if product.type == .macro {
360-
args += try ["-L", buildParameters.toolchain.hostLibDir.pathString]
360+
args += try ["-L", defaultBuildParameters.toolchain.hostLibDir.pathString]
361361
}
362362
#endif
363363

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2015-2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import struct Basics.AbsolutePath
14+
import struct PackageGraph.ResolvedModule
15+
16+
import SPMBuildCore
17+
18+
extension ResolvedModule {
19+
func tempsPath(_ buildParameters: BuildParameters) -> AbsolutePath {
20+
let suffix = buildParameters.suffix(triple: self.buildTriple)
21+
return buildParameters.buildPath.appending(component: "\(self.c99name)\(suffix).build")
22+
}
23+
}

0 commit comments

Comments
 (0)