SwiftUI: Command SwiftCompile failed with a nonzero exit code

I have a SwiftUI app that I've been working on in XCode 16.1. The project builds and runs in the simulators, on my mac and on my iPhone/iPad without any issues. I'm also able to build my unit test project and run them without any errors. The project has zero warnings in it.

When I go to the Edit Schemes options and change the Run scheme to be a Release build with the Debug Executable unchecked I get a compiler error:

Command SwiftCompile failed with a nonzero exit code

I've attempted this Release Run with the following target devices in XCode:

  • My iPhone 15 Pro Max (iOS 18.2 Beta 3)
  • MacBook Air (M1) (15.2 Beta)
  • iPhone 16 Simulator (iOS 18.1)
  • Any iOS Simulator Device (arm64, x86_64)

All 3 of these target have the same issue. Normally I would just debug the error from the logs but when I look at the build output I can't see any information in the log to tell me what happened. It looks like the source files are sent into the SwiftCompiler and the compiler fails without bubbling up the issue.

I've provided the full error log export as a Gist HERE due to it's size. Is there anything in the log I'm missing? Is there a way for me to turn on more verbose logging during compilation of a Release Build?

I created a brand new Multiplatform App in XCode and I added all of my source files to it. No project configuration settings were changed. I could build it successfully with the debug configuration. I then changed it to the Release configuration and experienced the same error. I can create another fresh project and make the same release configuration with none of my source files in it and get a successful build. I

t seems there is something wrong with my source files and the release configuration but the compiler doesn't indicate what. I'm lost at this point as I can't figure out how to get a release build and can't seem to find any indication as to why.

That’s an interesting failure you’ve got there. Normally when I see this error it’s because the compiler has out’n’out crashed, and there’s at least some diagnostic info in the full build log. But in this case there’s just nothing. The compiler seems to have failed but produced no diagnostics.

Does the problem reproduce if you do a Product > Archive? That also creates a Release build, but it might be sufficiently different to either work, or yield more useful diagnostics.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I had not tried that actually so I just did and received a ton of compiler errors. I uploaded a new GIST of the errors. Why do I not receive these during a normal Run while in the Debug config?

I have done some additional testing. Since all of the Archive compiler errors I'm getting now exist within the #Preview macros used in the Views I removed them all. Once I deleted all of the #Preview macros in the app I could delete the SampleData.swift and PreviewContainer.swift files that the compiler wasn't finding.

Now those files don't exist and I can continue to build and run the app normally. However Release build still fail with the same compiler error and the Archive command fails with the same Command SwiftCompile failed with a nonzero exit code build error. Looking at the log (here) it looks like the same result as my Release builds - no details.

I don't understand why Archive was failing to build with all the #Preview macros - I'll have to circle back around and look at that later. At the moment though, both Release builds and Archive is failing with the same nonzero exit code failure.

The Swift compiler can build in a variety of different ways depending on how it’s invoked. And Xcode will definitely invoke things differently depending on whether you’re building to run or building to archive. I’ve not looked into the gory details here. If you want to do that, it’s all visible in the full build log.

I’d rather focus on this:

At the moment though, both Release builds and Archive is failing with the same nonzero exit code failure.

Well, that’s consistent at least |-:

This is one of those cases where you have to decide whether it’s worth your time diving into the rabbit hole. I see two paths forward:

  • If you don’t need an immediate answer and you’re willing to share your source code with Apple, you could take your test project and put that in a bug report. If you do that, please post your bug number, just for the record.

  • If you really need to get this sorted quickly, or you can’t share all your code with Apple, you can do more to investigate this at your end. See the second half of this reply.

The former is quick and easy. The latter is a lot more work, but in the process of isolating the issue you might come across a workaround.


If you decide to dig into this further, my suggestion is that you take the last few commands from your full build log and run them from Terminal. Use $? to see the exit status:

% true ; echo $?
0
% false ; echo $?
1

If that replicates the problem, and I have every reason to believe it will, you can take the failing command and tweak it to further isolate the issue.

These commands are super long, so it’s usually best to put each one into a script file so that you can edit them easily. Once you’ve nailed down the replication, start reformatting it for human consumption (-:

Notably, each command passes a lot of files to the compiler (65 by my count). An obvious isolation step is to remove files and see if that fixes the problem. If you do that, remember to remove each instance of the file. For example, the command contains:

  • …/ColorsAllowed.swift

  • -o …/ColorsAllowed.o

  • -index-unit-output-path …/ColorsAllowed.o

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I have been able to fully reproduce this issue in a sample app. The following code will build, and run on both a simulator and a device. It will also work in XCode preview. When I attempt to archive it or run a Release config, it fails with the nonzero error.

import SwiftUI

class MyModel {
    var name: String
    var children: [MyModel] = []
    
    init(name: String) { self.name = name }
}

struct MyModelPicker: View {
    private var items: [MyModel] = []
    
    init() {
        let foo = MyModel(name: "Foo")
        let bar = MyModel(name: "Bar")
        
        let people = MyModel(name: "People")
        let johnDoe = MyModel(name: "John Doe")
        let maryJane = MyModel(name: "Mary Jane")
        let childDoe = MyModel(name: "Child of Doe")
        
        johnDoe.children.append(childDoe)
        people.children.append(contentsOf: [ johnDoe, maryJane ])
        foo.children.append(bar)
        items = [ foo, people ]
    }
    var body: some View {
        List {
            ForEach(items, id: \.name) { item in
                getRowForUserList(item)
            }
        }
    }
    
    @ViewBuilder func getRowForUserList(_ list: MyModel) -> some View {
        if list.children.isEmpty {
            Text(list.name)
        } else {
            getRowForParent(list)
        }
    }
    
    @ViewBuilder func getRowForParent(_ list: MyModel) -> some View {
        DisclosureGroup(isExpanded: .constant(true)) {
            ForEach(list.children, id: \.name) { child in
                getRowForUserList(child)
            }
        } label: {
            Text(list.name)
        }
    }
}

struct ContentView: View {
    var body: some View {
        VStack {
            MyModelPicker()
        }
    }
}

#Preview {
    ContentView()
}

With this reproducible, I submitted bug report FB15926480 with this example project included. Within the getRowForParent function there is the following loop:

ForEach(list.children, id: \.name) { child in
    getRowForUserList(child)
}

Commenting out the getRowForuserList function call will allow archiving to complete successfully. It seems to be an issue with recursion of the views.

After some additional debugging, I have found that replacing the usage of @ViewBuilder with dedicated structs allows for archive builds to be created. I can copy the implementation of each ViewBuilder as-is with no changes and past them into structs. Release configuration and Archiving compiles successfully.

The revised code is below - again with no implementation changes other than pulling the code out of ViewBuilder and into a struct.

import SwiftUI

@Observable class MyModel {
    var name: String
    var children: [MyModel] = []
    
    init(name: String) { self.name = name }
}

struct MyModelPicker: View {
    private var items: [MyModel] = []
    
    init() {
        let foo = MyModel(name: "Foo")
        let bar = MyModel(name: "Bar")
        
        let people = MyModel(name: "People")
        let johnDoe = MyModel(name: "John Doe")
        let maryJane = MyModel(name: "Mary Jane")
        let childDoe = MyModel(name: "Child of Doe")
        
        johnDoe.children.append(childDoe)
        people.children.append(contentsOf: [ johnDoe, maryJane ])
        foo.children.append(bar)
        items = [ foo, people ]
    }
    var body: some View {
        List {
            ForEach(items, id: \.name) { item in
                RowView(list: item)
            }
        }
    }
}

struct RowView: View {
    @Bindable var list: MyModel
    
    var body: some View {
        if list.children.isEmpty {
            Text(list.name)
        } else {
            ParentRowView(list: list)
        }
    }
}

struct ParentRowView: View {
    @Bindable var list: MyModel
    
    var body: some View {
        DisclosureGroup(isExpanded: .constant(true)) {
            ForEach(list.children, id: \.name) { child in
                RowView(list: child)
            }
        } label: {
            Text(list.name)
        }
    }
}

struct ContentView: View {
    var body: some View {
        VStack {
            MyModelPicker()
        }
    }
}

#Preview {
    ContentView()
}

I have updated my bug report to indicate this. It seems this is an issue with @ViewBuilder being able to recursively construct views.

With this reproducible, I submitted bug report FB15926480 with this example project included.

Thanks!

I took a look and it’s definitely landed with the right people. And I tried building your project myself and, yep, the Product > Archive fails for me as well.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I have a similar problem. Just trying to develop an AUv3 extension. My own development worked well, but when i switched from Debug builds to Release or Archive, both fail with the same Swift Compiler Error, as mentioned above.

I then tried to just compile the default AUV3 effect project template with these settings in Release or Archive mode:

And it fails as well. Building only works in Debug mode. All builds had the Macbook as the target platform. No simulator or external device.

I am using the latest Xcode 16.2 on an M1 Macbook with Sequoia 15.2.

This is the error log:


Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
Rename failed: /Users/anz/Library/Developer/Xcode/DerivedData/testing_build-fdofkvyzbyrzwfcisfoadodybwrs/Build/Intermediates.noindex/ArchiveIntermediates/testing_build/IntermediateBuildFilesPath/testing_build.build/Release/testing_buildExtension.build/Objects-normal/arm64/Parameters-a6d3ca7d.o.tmp -> /Users/anz/Library/Developer/Xcode/DerivedData/testing_build-fdofkvyzbyrzwfcisfoadodybwrs/Build/Intermediates.noindex/ArchiveIntermediates/testing_build/IntermediateBuildFilesPath/testing_build.build/Release/testing_buildExtension.build/Objects-normal/arm64/Parameters.o: No such file or directory
Rename failed: /Users/anz/Library/Developer/Xcode/DerivedData/testing_build-fdofkvyzbyrzwfcisfoadodybwrs/Build/Intermediates.noindex/ArchiveIntermediates/testing_build/IntermediateBuildFilesPath/testing_build.build/Release/testing_buildExtension.build/Objects-normal/arm64/ObservableAUParameter-ee5a1ee7.o.tmp -> /Users/anz/Library/Developer/Xcode/DerivedData/testing_build-fdofkvyzbyrzwfcisfoadodybwrs/Build/Intermediates.noindex/ArchiveIntermediates/testing_build/IntermediateBuildFilesPath/testing_build.build/Release/testing_buildExtension.build/Objects-normal/arm64/ObservableAUParameter.o: No such file or directory
0  swift-frontend           0x0000000108276a9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000108274cf0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000108277068 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000018cd4ae04 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018cd13f70 pthread_kill + 288
5  libsystem_c.dylib        0x000000018cc20908 abort + 128
6  libsystem_malloc.dylib   0x000000018cb29ea0 malloc_vreport + 896
7  libsystem_malloc.dylib   0x000000018cb2da24 malloc_report + 64
8  libsystem_malloc.dylib   0x000000018cb4c184 find_zone_and_free + 528
9  swift-frontend           0x000000010785dccc HandleInlinedLandingPad(llvm::InvokeInst*, llvm::BasicBlock*, llvm::ClonedCodeInfo&) + 1016
10 swift-frontend           0x0000000107859f2c llvm::InlineFunction(llvm::CallBase&, llvm::InlineFunctionInfo&, bool, llvm::AAResults*, bool, llvm::Function*) + 26900
11 swift-frontend           0x00000001059684bc llvm::InlinerPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) + 4228
12 swift-frontend           0x00000001079a14c0 llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) + 348
13 swift-frontend           0x00000001079a2e34 llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) + 332
14 swift-frontend           0x00000001079a22c8 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 2320
15 swift-frontend           0x0000000107fae420 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 224
16 swift-frontend           0x0000000105969fa8 llvm::ModuleInlinerWrapperPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 644
17 swift-frontend           0x0000000107fae420 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 224
18 swift-frontend           0x000000010320d040 swift::performLLVMOptimizations(swift::IRGenOptions const&, llvm::Module*, llvm::TargetMachine*, llvm::raw_pwrite_stream*) + 6200
19 swift-frontend           0x000000010320e2f8 swift::performLLVM(swift::IRGenOptions const&, swift::DiagnosticEngine&, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, llvm::StringRef, llvm::vfs::OutputBackend&, swift::UnifiedStatsReporter*) + 2352
20 swift-frontend           0x0000000103215520 (anonymous namespace)::LLVMCodeGenThreads::Thread::run() + 156
21 swift-frontend           0x0000000103215478 (anonymous namespace)::LLVMCodeGenThreads::runThread(void*) + 12
22 libsystem_pthread.dylib  0x000000018cd142e4 _pthread_start + 136
23 libsystem_pthread.dylib  0x000000018cd0f0fc thread_start + 8
Command SwiftCompile failed with a nonzero exit code
SwiftUI: Command SwiftCompile failed with a nonzero exit code
 
 
Q