Skip to content

Commit 97ba0c8

Browse files
[System] Use a larger limit for when to use response file
Drop the baseline number used by `xarg` when determining if a response file is needed when generating command. macOS on apple silicon actually has a really large limit when it comes to command-line limit and less response file means faster build and build logs easier to read.
1 parent 049acb8 commit 97ba0c8

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

Sources/SwiftDriver/Utilities/System.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,15 @@ func quoteArgument(_ argument: String) -> String {
6262
#if canImport(Darwin) || os(Linux) || os(Android) || os(OpenBSD) || os(FreeBSD)
6363
// Adapted from llvm::sys::commandLineFitsWithinSystemLimits.
6464
func commandLineFitsWithinSystemLimits(path: String, args: [String]) -> Bool {
65-
let upperBound = sysconf(Int32(_SC_ARG_MAX))
66-
guard upperBound != -1 else {
65+
let systemLimit = sysconf(Int32(_SC_ARG_MAX))
66+
guard systemLimit != -1 else {
6767
// The system reports no limit.
6868
return true
6969
}
7070
// The lower bound for ARG_MAX on a POSIX system
71-
let lowerBound = Int(_POSIX_ARG_MAX)
72-
// This the same baseline used by xargs.
73-
let baseline = 128 * 1024
71+
let posixLimit = Int(_POSIX_ARG_MAX)
7472

75-
var effectiveArgMax = max(min(baseline, upperBound), lowerBound)
73+
var effectiveArgMax = max(systemLimit, posixLimit)
7674
// Conservatively assume environment variables consume half the space.
7775
effectiveArgMax /= 2
7876

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ final class SwiftDriverTests: XCTestCase {
17661766
}
17671767

17681768
func testUsingResponseFiles() throws {
1769-
let manyArgs = (1...20000).map { "-DTEST_\($0)" }
1769+
let manyArgs = (1...200000).map { "-DTEST_\($0)" }
17701770
// Needs response file
17711771
do {
17721772
let source = try AbsolutePath(validating: "/foo.swift")
@@ -1879,7 +1879,7 @@ final class SwiftDriverTests: XCTestCase {
18791879
// The jobs below often take large command lines (e.g., when passing a large number of Clang
18801880
// modules to Swift). Ensure that they don't regress in their ability to pass response files
18811881
// from the driver to the frontend.
1882-
let manyArgs = (1...20000).map { "-DTEST_\($0)" }
1882+
let manyArgs = (1...200000).map { "-DTEST_\($0)" }
18831883

18841884
// Compile + separate emit module job
18851885
do {

0 commit comments

Comments
 (0)