Skip to content

Commit 6b32c64

Browse files
dschaefer2bnbarham
authored andcommitted
Add destination C module targets so you can prepare them directly. (swiftlang#7627)
This allows the C module to be targeted directly with the --target argument. It is a no-op however, since the output of C modules are not required for indexing. (cherry picked from commit 09efb06)
1 parent f8c87c9 commit 6b32c64

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

Sources/Build/BuildManifest/LLBuildManifestBuilder+Clang.swift

+11
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,15 @@ extension LLBuildManifestBuilder {
110110
self.addNode(output, toTarget: .test)
111111
}
112112
}
113+
114+
/// Create a llbuild target for a Clang target preparation
115+
func createClangPrepareCommand(
116+
_ target: ClangTargetBuildDescription
117+
) throws {
118+
// Create the node for the target so you can --target it.
119+
// It is a no-op for index preparation.
120+
let targetName = target.llbuildTargetName
121+
let output: Node = .virtual(targetName)
122+
self.manifest.addNode(output, toTarget: targetName)
123+
}
113124
}

Sources/Build/BuildManifest/LLBuildManifestBuilder.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,12 @@ public class LLBuildManifestBuilder {
141141
case .swift(let desc):
142142
try self.createSwiftCompileCommand(desc)
143143
case .clang(let desc):
144-
// Need the clang targets for tools
145144
if desc.target.buildTriple == .tools {
145+
// Need the clang targets for tools
146146
try self.createClangCompileCommand(desc)
147+
} else {
148+
// Hook up the clang module target
149+
try self.createClangPrepareCommand(desc)
147150
}
148151
}
149152
}

Tests/BuildTests/PrepareForIndexTests.swift

+19
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,23 @@ class PrepareForIndexTests: XCTestCase {
6363
"outputs:\n\t\(outputs.filter { $0.hasSuffix(".o") }.joined(separator: "\n\t"))"
6464
)
6565
}
66+
67+
func testCModuleTarget() throws {
68+
let (graph, fs, scope) = try trivialPackageGraph()
69+
70+
let plan = try BuildPlan(
71+
destinationBuildParameters: mockBuildParameters(destination: .target, prepareForIndexing: true),
72+
toolsBuildParameters: mockBuildParameters(destination: .host, prepareForIndexing: false),
73+
graph: graph,
74+
fileSystem: fs,
75+
observabilityScope: scope
76+
)
77+
let builder = LLBuildManifestBuilder(plan, fileSystem: fs, observabilityScope: scope)
78+
let manifest = try builder.generatePrepareManifest(at: "/manifest")
79+
80+
// Ensure our C module is here.
81+
let lib = try XCTUnwrap(graph.target(for: "lib", destination: .destination))
82+
let name = lib.getLLBuildTargetName(buildParameters: plan.destinationBuildParameters)
83+
XCTAssertTrue(manifest.targets.keys.contains(name))
84+
}
6685
}

0 commit comments

Comments
 (0)