Skip to content

Commit b0768f3

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 b0768f3

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ public final class SwiftTargetBuildDescription {
546546
}
547547

548548
result.append("-c")
549-
result.append(contentsOf: self.sources.map(\.pathString))
549+
// FIXME: Eliminate side effect.
550+
try result.append("@\(self.writeFileList().pathString)")
550551

551552
result.append("-I")
552553
result.append(self.buildParameters.buildPath.pathString)
@@ -578,9 +579,8 @@ public final class SwiftTargetBuildDescription {
578579

579580
// FIXME: Handle WMO
580581

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

585585
result.append("-I")
586586
result.append(self.buildParameters.buildPath.pathString)
@@ -631,9 +631,8 @@ public final class SwiftTargetBuildDescription {
631631
// FIXME: Handle WMO
632632

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

638637
result.append("-I")
639638
result.append(self.buildParameters.buildPath.pathString)
@@ -761,6 +760,20 @@ public final class SwiftTargetBuildDescription {
761760
return path
762761
}
763762

763+
private func writeFileList() throws -> AbsolutePath {
764+
let path = self.tempsPath.appending(component: "sources.filelist")
765+
let contents = self.sources.map { $0.pathString.spm_shellEscaped() }.joined(separator: "\n")
766+
try self.fileSystem.writeFileContents(path, string: contents)
767+
return path
768+
}
769+
770+
private func writeFileList(for target: Target) throws -> AbsolutePath {
771+
let path = self.tempsPath.appending(component: "\(target.name)-sources.filelist")
772+
let contents = target.sources.paths.map { $0.pathString.spm_shellEscaped() }.joined(separator: "\n")
773+
try self.fileSystem.writeFileContents(path, string: contents)
774+
return path
775+
}
776+
764777
/// Generates the module map for the Swift target and returns its path.
765778
private func generateModuleMap() throws -> AbsolutePath {
766779
let path = self.tempsPath.appending(component: moduleMapFilename)

0 commit comments

Comments
 (0)