Skip to content

Commit 2dd4dfc

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 faa4700 commit 2dd4dfc

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Sources/Build/ManifestBuilder.swift

Lines changed: 17 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,36 @@ 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 : [Node] = []
230+
if buildParameters.useExplicitModuleBuild && !driver.isExplicitMainModuleJob(job: job) {
231+
manifestNodeInputs = jobInputs
232+
} else {
233+
manifestNodeInputs = (inputs + jobInputs).uniqued()
234+
}
235+
221236
let moduleName = target.target.c99name
222237
let description = job.description
223238
if job.kind.isSwiftFrontend {
224239
manifest.addSwiftFrontendCmd(
225240
name: jobOutputs.first!.name,
226241
moduleName: moduleName,
227242
description: description,
228-
inputs: (inputs + jobInputs).uniqued(),
243+
inputs: manifestNodeInputs,
229244
outputs: jobOutputs,
230245
args: arguments
231246
)
232247
} else {
233248
manifest.addShellCmd(
234249
name: jobOutputs.first!.name,
235250
description: description,
236-
inputs: (inputs + jobInputs).uniqued(),
251+
inputs: manifestNodeInputs,
237252
outputs: jobOutputs,
238253
args: arguments
239254
)

0 commit comments

Comments
 (0)