redefinition of module with Xcode 11

I've got a decent size project with 10 or so dependencies. I've just switched to Xcode 11 and moved all the modules I can from using Carthage to the new SPM support in Xcode.


One of my dependencies is https://github.com/iwasrobbed/Down.git a common markdown parser. It includes libcmark, a C library. After cleaning my build folder, the only module map is

./SourcePackages/checkouts/Down/Source/cmark/include/module.modulemap


The first build works, but now find returns

./SourcePackages/checkouts/Down/Source/cmark/include/module.modulemap
./Build/Intermediates.noindex/Down.build/Debug/libcmark.build/libcmark.modulemap


After making a change to the source code and recompiling, the same two modulemaps are there, but I get the error

/Users/mlilback/Library/Developer/Xcode/DerivedData/Rc2Client-bqmhvrpuhrtqjdfbdeqbqzhmotdc/Build/Intermediates.noindex/GeneratedModuleMaps/macosx/libcmark.modulemap:1:8: error: redefinition of module 'libcmark'
module libcmark {
       ^
/Users/mlilback/Library/Developer/Xcode/DerivedData/Rc2Client-bqmhvrpuhrtqjdfbdeqbqzhmotdc/SourcePackages/checkouts/Down/Source/cmark/include/module.modulemap:1:8: note: previously defined here
module libcmark [system][extern_c] {
       ^


This makes no sense to me. Why does it compile the first time? What can I do to avoid constantly having to clean the build folder and wait for a fresh build?

Replies

I am running into exactly the same issue with the same library. Though, mine consistently fails even if I do a clean.

You're running into this issue because the author of the framework has moved the modulemap file and your carthage directory has not been cleaned. This means there are two modulemap files present, which causes this error to occur.


Remove the file, or delete the entire directory

Test on Xcode 13 RC.

Release notes:

Fixed a dependency ordering issue involving frameworks with public and private module maps which could result in “redefinition of module” errors. (72123120)