Skip to content

Commit 4eb57e1

Browse files
committed
[Explicit Module Builds] Avoid adding cross-target input dependencies to intermediate build artifact jobs.
For a given target, in the Explicit Module Build world, swift-driver produces jobs to build the main module and jobs to build all module dependencies. cross-target dependencies should be added as explicit inputs to a target's main module build job, but not intermediate build dependency jobs. Always adding cross-target dependencies as inputs can lead to cycles in the build manifest when multiple targets share common intermediate module dependencies.
1 parent 4ad7651 commit 4eb57e1

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Sources/Build/ManifestBuilder.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ extension LLBuildManifestBuilder {
206206
if buildParameters.useExplicitModuleBuild {
207207
commandLine.append("-experimental-explicit-module-build")
208208
}
209+
209210
var driver = try Driver(args: commandLine, fileSystem: target.fs)
210211
let jobs = try driver.planBuild()
211212
let resolver = try ArgsResolver(fileSystem: target.fs)
@@ -218,22 +219,35 @@ extension LLBuildManifestBuilder {
218219
let jobInputs = job.inputs.map { $0.resolveToNode() }
219220
let jobOutputs = job.outputs.map { $0.resolveToNode() }
220221

222+
// Add target dependencies as inputs to the main module build command.
223+
//
224+
// Jobs for a target's intermediate build artifacts, such as PCMs or
225+
// modules built from a .swiftinterface, do not have a
226+
// dependency on cross-target build products. If multiple targets share
227+
// common intermediate dependency modules, such dependencies can lead
228+
// to cycles in the resulting manifest.
229+
var manifestNodeInputs = jobInputs
230+
if !job.inputs.contains(where: { $0.type == .swiftInterface }) &&
231+
!job.outputs.contains(where: { $0.type == .pcm }) {
232+
manifestNodeInputs = (inputs + jobInputs).uniqued()
233+
}
234+
221235
let moduleName = target.target.c99name
222236
let description = job.description
223237
if job.kind.isSwiftFrontend {
224238
manifest.addSwiftFrontendCmd(
225239
name: jobOutputs.first!.name,
226240
moduleName: moduleName,
227241
description: description,
228-
inputs: (inputs + jobInputs).uniqued(),
242+
inputs: manifestNodeInputs,
229243
outputs: jobOutputs,
230244
args: arguments
231245
)
232246
} else {
233247
manifest.addShellCmd(
234248
name: jobOutputs.first!.name,
235249
description: description,
236-
inputs: (inputs + jobInputs).uniqued(),
250+
inputs: manifestNodeInputs,
237251
outputs: jobOutputs,
238252
args: arguments
239253
)

0 commit comments

Comments
 (0)