"Unable to find module dependency" with custom PRODUCT_MODULE_NAME

Hi! Here is a brief introduction at first. I am developing a framework and our project has following structure: All frameworks are static ones. PublicAPI framework contains the only declarations that are visible to users, while ModuleX frameworks are internal modules. During build process we archive all targets and libtool all internal module binaries into PublicAPI one. This way we distribute our framework as a single xcframework package and hide all internal modules from users.

Here is the problem part. All these frameworks exist in separate projects that have single static library target. I want to add new targets with different settings, say SWIFT_ACTIVE_COMPILATION_CONDITIONS or else. So project would look like this Also I would like both regular and extended targets to build frameworks with same module name, so that neither users (that use PublicAPI framework) nor I would have to change imports in my code. My idea was to set PRODUCT_MODULE_NAME in extended targets to the same value as in regular ones. But when I build PublicAPIExtended target I get an error Unable to find module dependency 'Module1' although derived data contains Module1Extended.framework with Module1 module inside. What did I do wrong? Is it possible to build project like this at all?

And another thing - I also tried to build a scheme containing both PublicAPI and PublicAPIExtended targets and got different error even prior to build:

error: Multiple commands produce '<ExtractAppIntentsMetadata Path(_str: "/Users/antonprotko/Library/Developer/Xcode/DerivedData/test-acncglphufkosyhjzbwrbzalsnlh/Build/Products/Debug") bar/Metadata.appintents>'
    note: Target 'bar copy' (project 'bar'): ExtractAppIntentsMetadata
    note: Target 'bar' (project 'bar'): ExtractAppIntentsMetadata

Can I fix it somehow?

Here is example project with similar targets - foo/foo_copy and bar/bar_copy share the same sources with different compilation conditions. bar targets depend on foo targets and building bar_copy fails with Unable to find module dependency: 'foo' https://drive.google.com/file/d/1Cj5cIw8U0LJ5Xt9ZnhbKIo240kbrizLE/view?usp=sharing

"Unable to find module dependency" with custom PRODUCT_MODULE_NAME
 
 
Q