Redefinition of module issue

We have a Vapor project that we have been building fine for a while and then all of a sudden yesterday we started getting build errors complaining about redefinition of module. We are currently using Xcode 11.3.1 and Swift 5.1.3.

This is a SPM project where the errors happen regardless of if we build using swift build or running the project in Xcode. The same error is happening on our CI, on my machine and also on a colleagues machine and it all started happening yesterday without any obvious changes to the repo other than a few small code changes, no package settings etc.

When running swift build this is what we currently see:

% swift build                                     
/Users/dale/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/module.modulemap:1:8: error: redefinition of module 'AppleTextureEncoder'
module AppleTextureEncoder [system] [extern_c] {
       ^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/module.modulemap:1:8: note: previously defined here
module AppleTextureEncoder [system] [extern_c] {
       ^
/Users/dale/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/module.modulemap:7:8: error: redefinition of module 'Compression'
module Compression [system] [extern_c] {
       ^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/module.modulemap:7:8: note: previously defined here
module Compression [system] [extern_c] {
       ^
/Users/dale/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/module.modulemap:13:8: error: redefinition of module 'Darwin'
module Darwin [system] [extern_c] [no_undeclared_includes] {
       ^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/module.modulemap:13:8: note: previously defined here
module Darwin [system] [extern_c] [no_undeclared_includes] {
       ^
/Users/dale/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/module.modulemap:1712:8: error: redefinition of module 'asl'
module asl [system] [extern_c] {
       ^
...

There have been suggestions on the Vapor discord to remove the command line tools but this seems an unsustainable solution, especially on our CI. Does anyone have any clues as to what's going on here?

The redefinition of module error is due to swift including both Xcode and CommandLineTools at the same time. This is visible by generating a project with swift package generate-xcodeproj and look at OTHER_CFLAGS containing -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include.

We diff an old generated project and that line wasn't there.

Suspiciously enough, this is added only to targets somehow linked to SwiftNIO, targets that don't have a Vapor dependency don't have that include line.

Question is what would cause swift build to look in that additional path or spm to suddenly add that include when generating the project?

1 Like

It wasted couple of hours for me too.

1 Like

@pankajsoni19 did you manage to find a solution at all?

i renamed the /library/developer/commandtools folder to /library/developer/commandtools-orig
no actual solutions as of yet.

Added a post to SwiftPM category as that's library what's causing the issue - Building with a dependency that uses system libraries no longer works

Raised on Brew's GitHub on the issue that seems to have been the root of this - https://github.com/Homebrew/brew/issues/5068#issuecomment-612011788

1 Like

A work around for anyone else having this issue; if you are building from an Xcode project you can go into the build settings of each target and remove -I /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include from Other C Flags and Other Swift Flags and the project will build again.

EDIT: I should note these weren't there for us originally, it appears this was caused by a change in homebrew 2.2.12. @0xTim has the links to more information about the issue above.

1 Like