# Swift Compilation - Reaching ARG\_MAX limit causing Xcode build failure

**URL:** <https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494>\
**Category:** Using Swift\
**Created:** [August 16, 2017, 10:17am UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494 "2017-08-16T10:17:47Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhargav\_gurlanka](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bhargav_gurlanka/32/2697_2.png) [@bhargav\_gurlanka](https://forums.swift.org/u/bhargav_gurlanka)\
**Post date:** [August 16, 2017, 10:17am UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/1 "2017-08-16T10:17:47Z")

</div>

We have moderately complex Swift project with around 2,000 Swift files in a  
single module.

Most of the Swift source files are deeply nested inside directories and 90%  
of these files have absolute paths with more than 150 characters (assuming  
project is in "/Volumes/Macintosh HD2/Project" folder)

Because Swift compiler (Xcode 8.3.2) takes the absolute paths of all source  
files while compiling, the ARG\_MAX limit is reached and build fails with:

Build operation failed without specifying any errors. Individual build  
tasks may have failed for unknown reasons.

One possible cause is if there are too many (possibly zombie) processes; in  
this case, rebooting may fix the problem.

Some individual build task failures (up to 12) may be listed below.

Have anybody experienced this issue before?

We temporarily fixed this issue by renaming longer folder names to shorter  
ones.

I'm assuming that breaking this monolithic module into smaller ones might  
fix the issue, but are there any other better solutions?

---

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrose/32/408_2.png) [@jrose](https://forums.swift.org/u/jrose)\
**Post date:** [August 16, 2017, 5:51pm UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/2 "2017-08-16T17:51:30Z")

</div>

You're not the only person to run into this. rdar://problem/33635183 \<rdar://problem/33635183\> tracks the issue within Apple, and since it would need Xcode-side changes as well there's no point in having a report at bugs.swift.org \<[Issues · apple/swift · GitHub](http://bugs.swift.org/&gt;%5C). I'm afraid we don't have a workaround right now other than what you've mentioned.

Jordan

> **···**
>
> > On Aug 16, 2017, at 03:17, bhargav gurlanka via swift-users \<swift-users@swift.org\> wrote:
> > 
> > We have moderately complex Swift project with around 2,000 Swift files in a single module.
> > 
> > Most of the Swift source files are deeply nested inside directories and 90% of these files have absolute paths with more than 150 characters (assuming project is in "/Volumes/Macintosh HD2/Project" folder)
> > 
> > Because Swift compiler (Xcode 8.3.2) takes the absolute paths of all source files while compiling, the ARG\_MAX limit is reached and build fails with:
> > 
> > Build operation failed without specifying any errors. Individual build tasks may have failed for unknown reasons.
> > 
> > One possible cause is if there are too many (possibly zombie) processes; in this case, rebooting may fix the problem.
> > 
> > Some individual build task failures (up to 12) may be listed below.
> > 
> > Have anybody experienced this issue before?
> > 
> > We temporarily fixed this issue by renaming longer folder names to shorter ones.
> > 
> > I'm assuming that breaking this monolithic module into smaller ones might fix the issue, but are there any other better solutions?
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-users mailing list  
> > swift-users@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-users](https://lists.swift.org/mailman/listinfo/swift-users)

---

<div class="post-metadata">

**Author:** ![chkpnt](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/chkpnt/32/2381_2.png) [@chkpnt](https://forums.swift.org/u/chkpnt)\
**Post date:** [February 20, 2018, 8:47pm UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/3 "2018-02-20T20:47:52Z")

</div>

Are there any news concerning this radar?

Last month, when I didn't know this thread, I've filed a bug (36711458): you may want to link those issues.

There is also a demonstration at [GitHub - chkpnt/ManyFiles: Demonstration for Apple Bug Report 36711458](https://github.com/chkpnt/ManyFiles)

Gregor

---

<div class="post-metadata">

**Author:** ![anandabits](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/anandabits/32/355_2.png) [@anandabits](https://forums.swift.org/u/anandabits)\
**Post date:** [March 21, 2018, 4:54pm UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/4 "2018-03-21T16:54:59Z")

</div>

I'm working on a project that's bumping up against this issue and trying to figure out if there are any workarounds.

This project builds when it is cloned to a very short path off of the root of the hard drive. I have created a symlink at `/x` to the actual path and tried setting `SRCROOT` to `/x` in my build configuration. This works, but Xcode is still passing the fully resolved paths to the `swiftc`. Is there any way to get Xcode to use the shorter paths that go through the symlink?

---

<div class="post-metadata">

**Author:** ![davidharris](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/davidharris/32/16265_2.png) [@davidharris](https://forums.swift.org/u/davidharris)\
**Post date:** [June 7, 2018, 3:52pm UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/5 "2018-06-07T15:52:01Z")

</div>

We're hitting this on a project too, somewhere around 1600 Swift files. Deleting about 30 of these gets rid of the error. Symlinking to get shorter paths we couldn't get to work, and even unnesting some dependencies didn't seem to help too much, so not sure what our best recourse is. Splitting this up into frameworks won't work on this project either, as it's already heavily modularized; this is just the heaviest module.

---

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [June 7, 2018, 7:05pm UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/6 "2018-06-07T19:05:35Z")

</div>

Some great work has been done on this recently by @dabelknap. Soon `swiftc` should support passing parameters via response files (i.e., `swiftc @foo.txt` where `foo.txt` contains the arguments) just as `clang` and many other compilers do. Then it'll be up to Xcode to adopt that support to write arguments out to a response file when necessary.

PRs are here: [apple/swift#15853](https://github.com/apple/swift/pull/15853) (already merged), [apple/swift#16362](https://github.com/apple/swift/pull/16362) (under review).

---

<div class="post-metadata">

**Author:** ![bitomule](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bitomule/32/12317_2.png) [@bitomule](https://forums.swift.org/u/bitomule)\
**Post date:** [February 1, 2019, 12:39pm UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/7 "2019-02-01T12:39:24Z")

</div>

Is there any update on this? I see the PR was merged but it's still not available on Xcode 10.1 and I don't see anything related on Xcode 10.2 beta changelog.

---

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [February 1, 2019, 2:01pm UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/8 "2019-02-01T14:01:31Z")

</div>

Xcode 10.1 fixed long command lines passed to `swiftc`, but missed an additional patch to make sure that frontend subprocesses spawned by `swiftc` also used args files as needed. This ends up hitting the merge-modules action that's used when you compile without whole-module-optimization, and this was patched in [apple/swift#19449](https://github.com/apple/swift/pull/19449).

Xcode 10.2 _should_ have the change; I don't know what branch the beta's toolchain was cut from but the patch is present from `swift-5.0-branch-11-16-2018` on.

In the meantime, with Xcode 10.1, you can force whole-module-optimization on to get around the issue (assuming it's the merge-modules action causing the issue).

---

<div class="post-metadata">

**Author:** ![bitomule](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bitomule/32/12317_2.png) [@bitomule](https://forums.swift.org/u/bitomule)\
**Post date:** [February 2, 2019, 8:59am UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/9 "2019-02-02T08:59:05Z")

</div>

Tried with whole module optimization on Xcode 10.1 and still getting the same error:

error: unable to spawn process (Argument list too long)

I'll try with latest Xcode 10.2 beta but I have to fix a dependency still being built with Swift 3.2.

The issue rdar is here: [rdar://35879960: swiftc: make it support @file/-filelist](http://www.openradar.me/35879960)

---

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [February 2, 2019, 4:57pm UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/10 "2019-02-02T16:57:33Z")

</div>

Sorry, I wasn't thinking about the Xcode part! The _compiler_ feature is present in Swift 5.0, but _Xcode_ appears to still need to be updated to write its command line arguments to a `@params` file in order for it to work.

To make sure that the issue is addressed properly, you may want to update your radar to emphasize that it's not a Swift compiler issue anymore, but that Xcode specifically needs to add support for the new behavior.

---

<div class="post-metadata">

**Author:** ![bitomule](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bitomule/32/12317_2.png) [@bitomule](https://forums.swift.org/u/bitomule)\
**Post date:** [February 3, 2019, 10:35am UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/11 "2019-02-03T10:35:27Z")

</div>

Thank you! Hope it gets fixed soon.

---

<div class="post-metadata">

**Author:** ![lascorbe](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lascorbe/32/7219_2.png) [@lascorbe](https://forums.swift.org/u/lascorbe)\
**Post date:** [May 24, 2019, 10:29am UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/12 "2019-05-24T10:29:41Z")

</div>

We've filed a new radar to see if the Xcode folks add support for the behavior:

[http://www.openradar.me/50886131](http://www.openradar.me/50886131)

---

<div class="post-metadata">

**Author:** ![davidharris](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/davidharris/32/16265_2.png) [@davidharris](https://forums.swift.org/u/davidharris)\
**Post date:** [May 25, 2019, 7:56pm UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/13 "2019-05-25T19:56:25Z")

</div>

For what it's worth, we were able to get the command length down a ton by removing a lot of things that were stored as environment variables on our CI machines. All of the environment variables seem to be prepended to any command, and those were by far the majority of the length for us.

---

<div class="post-metadata">

**Author:** ![Keith](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/keith/32/291_2.png) [@Keith](https://forums.swift.org/u/Keith)\
**Post date:** [May 25, 2019, 10:38pm UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/14 "2019-05-25T22:38:24Z")

</div>

If limiting the environment helps you can try passing `-UseSanitizedBuildSystemEnvironment=YES` to xcodebuild

---

<div class="post-metadata">

**Author:** ![Angel](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/angel/32/19778_2.png) [@Angel](https://forums.swift.org/u/Angel)\
**Post date:** [July 9, 2019, 5:52am UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/15 "2019-07-09T05:52:46Z")

</div>

Xcode 11 beta 3 added a flag to use an unlimited number of Swift files. You have to add USE\_SWIFT\_RESPONSE\_FILE to YES in Build Settings - User Defined section. But this only works if you use the New Build System.  
Tested on a dummy project with 2000 files inside an extra long path and it's working.

---

<div class="post-metadata">

**Author:** ![jp-dubey07](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jp-dubey07](https://forums.swift.org/u/jp-dubey07)\
**Post date:** [November 7, 2019, 4:21pm UTC](https://forums.swift.org/t/swift-compilation-reaching-arg-max-limit-causing-xcode-build-failure/6494/16 "2019-11-07T16:21:08Z")

</div>

> [@Angel](#):
>
> YES

Awesome!!
