Xcode 13 compiling error - corrupted ModuleCache.noIndex - Xcode 12 working fine

Description:

Precompile bridging header fails (see attached "build_error.png") The failure is happening on Compile Swift source files (arm64) -> Precompile bridging header (arm64)

Please list the steps you took to reproduce the issue:

  • build / run project

workaround:

  1. Delete "ModuleCache.noindex" in the "DerivedData" folder
  2. Remove the Header Search Paths in Build settings which refer the custom CMake C/C++ libraries
  3. run build
  4. build will fail because of missing headers
  5. revert the changes to the Header Search Paths in Build settings
  6. run build -> successful

-- This seems to be required each time the content of ModuleCache.noindex gets in a bad state

things we tried:

  • clean build (on project itself and on the third party project)
  • removing the third party CMake Xcode project seems to not have problem building the bridging header
  • delete the "derived_data" folder
  • reinstall Xcode

What version of Xcode are you using?

  • Xcode Version 13.1 (13A1030d)

Environment:

  • project is working fine with Xcode 12.5.1 running Mac OS 11
  • project fails with same error with Xcode 13.0 and 13.1 running Mac OS 11 or Mac OS 12
  • fails on M1 and x86 Mac minis
  • project includes a third party C/C++ Xcode project which is generated by CMake
  • project consists of objective-c and swift code

Initially I reported the problem on Stackoverflow (without success): https://stackoverflow.com/questions/69811551/xcode-13-build-failure-xcode-12-working-fine-could-not-build-module-darwin

What did you expect to happen?

  • project builds successful without workaround

What actually happened? Precompile bridging header fails (see attached "build_error.png") excerpt of the error log:

<module-includes>:392:9: note: in file included from <module-includes>:392:
#import "netinet6/ipsec.h"
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.0.sdk/usr/include/netinet6/ipsec.h:132:2: error: unknown type name 'uuid_string_t'; did you mean 'io_string_t'?
        uuid_string_t wake_uuid;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.0.sdk/usr/include/device/device_types.h:89:33: note: 'io_string_t' declared here
typedef char                    io_string_t[512];

I am also experiencing this bug every time I change between debug/release or between macOS/iOS targets in my project. Neither Clean Build Folder, nor deleting Derived Data nor just deleting ModuleCache.noIndex helps. The steps above do fix the compilation, until the next time I change targets or debug/release. I'm on macOS 12.3 and Version 13.3 (13E113) now with no improvement. Do you have a FB number for this?

In my case, I had added a path to my copy of /Libraries/pybind to the project’s Header Search Paths, and the pybind headers have files complex.h and attr.h which conflict with usr/include. When Xcode tried building Darwin, using Header Search Paths it got the wrong version of the files and failed: removing the search path temporarily allowed Darwin to build and be cached. I worked around the problem in my project by removing pybind from my Header Search Paths entirely, adding those header files to the project, and enabling Use Header Maps so my code using pybind could find them. (Renaming those two header files would work, too, if I wanted to edit the library source code.)

Xcode 13 compiling error - corrupted ModuleCache.noIndex - Xcode 12 working fine
 
 
Q