Xcode 12 Build failed, error: circular reference

Our project compiles and runs fine on Xcode 11.

However, when I compile with Xcode 12, it tells me <unkown>0: error: circular reference

The specific information is as follows:
<unknown>:0: error: merge-module command failed with exit code 1 (use -v to see invocation)

and

<unknown>:0: error: circular reference Command MergeSwiftModule failed with a nonzero exit code

Please see my attachments for specific errors.

Other than that, I can't get any more error messages.



Answered by ForumsContributor in
Just to suggest the obvious, have you cleaned the build folder?

I get that sort of error on a client project when running UI tests after the second time.
@jlilest

Yes, we cleaned up the build directory DerivedData, including using Xcode's Clean Build (Command + Shift + K, Command + Option + Shift + K), and we still get this error.

This error is only available in Xcode 12 Release up to and including Beta.
Faced same error on stage MergeSwiftModule

Did you try change the project setting SWIFT_COMPILATION_MODE from Incremental to the Whole Module?
@DoxxerApple

Yeah, this worked for me.
But I would like to know why, after all, the whole module compilation is too slow.
Accepted Answer
I solved the problem, I think it was an xcode12 bug.

Old Codes:
Code Block
extension UIWindow.Level {
private static var statusBarRawValue: RawValue { UIWindow.Level.statusBar.rawValue }
}

New Codes:
Code Block
extension UIWindow.Level {
private static var statusBarRawValue: CGFloat { UIWindow.Level.statusBar.rawValue }
}

Hi @wkKevin,

I think this error is logical. I ran the same issue after upgrading my XCode to XCode 12.

In my case, I reference the same type to the the type that is using it:
Code Block swift
class OnboardingStep: NavigationFlowStep<StepInput.OnboardingWelcome> {
struct InitialData {
var onboardingList: ListTitles
var featuredTitle: Product
var welcomeScreenTitle: Product
}
....


and in OnboardingStepInput.swift I have this InitialData reference there:
Code Block language
struct StepInput {
...
typealias OnboardingWelcome = (
     availableSteps: [OnboardingScreen],
    initialData: OnboardingStep.InitialData
   )
...

and in your code here, it has similar pattern:
Code Block swift
extension UIWindow.Level {
private static var statusBarRawValue: RawValue { UIWindow.Level.statusBar.rawValue }
}

it references itself. Maybe not the best explanation that I can come up with, but I think you've got my point.


my project was successfully builded and deployed the device, but when I want to archive to project for AppStore, I faced same error. including using Xcode's Clean Build (Command + Shift + K ), Updated dependencies and change SWIFT_COMPILATION_MODE from Incremental to the Whole Module, the project was archived successfully using Xcode 13.3, but was not archived using Xcode 14.0. Please help me

Xcode 12 Build failed, error: circular reference
 
 
Q