Swift 5.5+ error, argument list is too long

Hello, we have a large(17000+ source files in main target + many packages) mixed(Swift+ObjC) project. When we build it on Xcode 12.5.1, everything is ok. When we tried to build it on Xcode 13+, getting compile error "Argument list too long.” We researched and understood that the problem is a buffer(ARG_MAX) overflow when the compiler passes the path to all source files to ARG_MAX.

error: unable to invoke subcommand: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver (Argument list too long)
Command CompileSwiftSources failed with a nonzero exit code

GitHub - RenatGafarov/LargeProjectExample - project example with error

7 Likes

Does this workaround work for this project? Swift Compilation - Reaching ARG_MAX limit causing Xcode build failure - #15 by Angel

Actually it looks like Xcode already sets that even without the setting in this case. But I found if you set OTHER_SWIFT_FLAGS = -disallow-use-new-driver it works around this issue, sounds like a bug in Swift where it's unpacking the response file and not just forwarding it along to the new driver. Note as of Swift 5.6 this flag is deprecated, but maybe a fix for this will land before its removal

I've had a PR open that attempts to fix this: Propagate response files correctly to the new driver. by allevato · Pull Request #39493 · apple/swift · GitHub

4 Likes

Update: the fix has been merged into main and the 5.6 release branch.

2 Likes

Thanks, I will check in next Xcode beta