Skip to content

Add destination C module targets so you can prepare them directly. #7627

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
Jun 3, 2024
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
11 changes: 11 additions & 0 deletions Sources/Build/BuildManifest/LLBuildManifestBuilder+Clang.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,15 @@ extension LLBuildManifestBuilder {
self.addNode(output, toTarget: .test)
}
}

/// Create a llbuild target for a Clang target preparation
func createClangPrepareCommand(
_ target: ClangTargetBuildDescription
) throws {
// Create the node for the target so you can --target it.
// It is a no-op for index preparation.
let targetName = target.llbuildTargetName
let output: Node = .virtual(targetName)
self.manifest.addNode(output, toTarget: targetName)
}
}
5 changes: 4 additions & 1 deletion Sources/Build/BuildManifest/LLBuildManifestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@ public class LLBuildManifestBuilder {
case .swift(let desc):
try self.createSwiftCompileCommand(desc)
case .clang(let desc):
// Need the clang targets for tools
if desc.target.buildTriple == .tools {
// Need the clang targets for tools
try self.createClangCompileCommand(desc)
} else {
// Hook up the clang module target
try self.createClangPrepareCommand(desc)
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions Tests/BuildTests/PrepareForIndexTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,23 @@ class PrepareForIndexTests: XCTestCase {
"outputs:\n\t\(outputs.filter { $0.hasSuffix(".o") }.joined(separator: "\n\t"))"
)
}

func testCModuleTarget() throws {
let (graph, fs, scope) = try trivialPackageGraph()

let plan = try BuildPlan(
destinationBuildParameters: mockBuildParameters(destination: .target, prepareForIndexing: true),
toolsBuildParameters: mockBuildParameters(destination: .host, prepareForIndexing: false),
graph: graph,
fileSystem: fs,
observabilityScope: scope
)
let builder = LLBuildManifestBuilder(plan, fileSystem: fs, observabilityScope: scope)
let manifest = try builder.generatePrepareManifest(at: "/manifest")

// Ensure our C module is here.
let lib = try XCTUnwrap(graph.target(for: "lib", destination: .destination))
let name = lib.getLLBuildTargetName(buildParameters: plan.destinationBuildParameters)
XCTAssertTrue(manifest.targets.keys.contains(name))
}
}