yonaskolb / XcodeGen

A Swift command line tool for generating your Xcode project
MIT License
6.88k stars 809 forks source link

Build error with targets depending on XCTest in module verification #1386

Closed vincentisambart closed 10 months ago

vincentisambart commented 10 months ago

After updating to XcodeGen 2.36.0, in our project building a framework (named TestingCore here) that depends on XCTest fails during "Verify Modularization":

VerifyModule [app-derived-data]/Build/Products/Debug-iphonesimulator/TestingCore.framework (in target 'TestingCore' from project 'MyApp')
    cd [project-directory]
    /Applications/Xcode-14.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/modules-verifier [app-derived-data]/Build/Products/Debug-iphonesimulator/TestingCore.framework --clang /Applications/Xcode-14.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang --diagnostic-filename-map [app-derived-data]/Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/TestingCore.build/TestingCore-diagnostic-filename-map.json --sdk /Applications/Xcode-14.3.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.4.sdk --intermediates-directory [app-derived-data]/Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/TestingCore.build/VerifyModule --target arm64-apple-ios15.0-simulator --language objective-c --language objective-c++ --standard gnu11 --standard gnu++14

[app-derived-data]/Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/TestingCore.build/VerifyModule/TestingCore_objective-c++_arm64-apple-ios15.0-simulator_gnu++14/Test/Test.framework/Headers/Test.h:1:9: error: (fatal) could not build module 'TestingCore'
[app-derived-data]/Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/TestingCore.build/VerifyModule/TestingCore_objective-c_arm64-apple-ios15.0-simulator_gnu11/Test/Test.framework/Headers/Test.h:1:9: error: (fatal) could not build module 'TestingCore'
[app-derived-data]/Build/Products/Debug-iphonesimulator/TestingCore.framework/Headers/TestingCore-Swift.h:263:9: error: (fatal) module 'XCTest' not found

[app-derived-data]/Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/TestingCore.build/VerifyModule/TestingCore_objective-c++_arm64-apple-ios15.0-simulator_gnu++14/Test/Test.framework/Headers/Test.h:1:9: (fatal) could not build module 'TestingCore'

[app-derived-data]/Build/Intermediates.noindex/MyApp.build/Debug-iphonesimulator/TestingCore.build/VerifyModule/TestingCore_objective-c_arm64-apple-ios15.0-simulator_gnu11/Test/Test.framework/Headers/Test.h:1:9: (fatal) could not build module 'TestingCore'

[app-derived-data]/Build/Products/Debug-iphonesimulator/TestingCore.framework/Headers/TestingCore-Swift.h:263:9: (fatal) module 'XCTest' not found

We are using Xcode 14.3.1, but it also happens with Xcode 15 beta 5.

It seems to be caused by the changes in #1385 (issue #1349) that update default settings to the latest recommended settings. More precisely, the cause seems to be the enabling of what is called the "module verifier". It seems that module verifier does not like targets that are not test targets and link to XCTest. A user also mentions this problem on the Swift forums.

If someone has the same problem, the only way I found to make it work is to explicitly disable the module verifier for all targets that depend on XCTest and are not test targets.

targets:
  MyTestHelperFramework:
    settings:
      base:
        ENABLE_MODULE_VERIFIER: false

XcodeGen could disable the module verifier by default on all non-test targets depending on XCTest, but such hidden behavior could cause problems in the long run so I'm not sure it would be a good idea. Anyway I thought having a issue explaining the problem and workaround would be a good thing to have, even if the issue is just closed.

yonaskolb commented 10 months ago

Thank you for the report @vincentisambart 🙏
I've removed the addition of this build setting entirely, as seems this is causing issues anyway in various setups. https://github.com/yonaskolb/XcodeGen/pull/1387

yonaskolb commented 10 months ago

Resolved in XcodeGen 2.36.1