Skip to content

Commit ca904ed

Browse files
committed
Build: migrate to file lists for driver invocations
When invoking the driver use file lists rather than passing all the sources on the command line. This is particularly import for Windows where the command line limit is 32k. With deep dependency sets and large projects, it is possible to overrun this limit and fail to invoke the command. The driver itself will invoke the frontend using response files if the invocation will overflow the command line limit.
1 parent 0d43a5e commit ca904ed

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,8 @@ public final class SwiftTargetBuildDescription {
578578

579579
// FIXME: Handle WMO
580580

581-
for source in self.target.sources.paths {
582-
result.append(source.pathString)
583-
}
581+
// FIXME: Eliminate side effect.
582+
try result.append("@\(self.writeFileList(for: self.target).pathString)")
584583

585584
result.append("-I")
586585
result.append(self.buildParameters.buildPath.pathString)
@@ -631,9 +630,8 @@ public final class SwiftTargetBuildDescription {
631630
// FIXME: Handle WMO
632631

633632
result.append("-c")
634-
for source in self.target.sources.paths {
635-
result.append(source.pathString)
636-
}
633+
// FIXME: Eliminate side effect.
634+
try result.append("@\(self.writeFileList(for: self.target).pathString)")
637635

638636
result.append("-I")
639637
result.append(self.buildParameters.buildPath.pathString)
@@ -677,6 +675,13 @@ public final class SwiftTargetBuildDescription {
677675
self.buildParameters.triple.isDarwin() && self.target.type == .library
678676
}
679677

678+
private func writeFileList(for target: ResolvedTarget) throws -> AbsolutePath {
679+
let path = self.tempsPath.appending(component: "\(target.name)-sources.filelist")
680+
let contents = target.sources.paths.map { $0.pathString.spm_shellEscaped() }.joined(separator: "\n")
681+
try self.fileSystem.writeFileContents(path, string: contents)
682+
return path
683+
}
684+
680685
private func writeOutputFileMap() throws -> AbsolutePath {
681686
let path = self.tempsPath.appending("output-file-map.json")
682687
let masterDepsPath = self.tempsPath.appending("master.swiftdeps")

0 commit comments

Comments
 (0)