XCFrameworks dependencies via Cocoapods

Hi! I've been trying to precompile one of our internal modules for a while, but I can't figure out how to get this done.

Info

Let's call the library I'm trying to precompile InternalLib.

InternalLib is a mixed Swift/Objc static library, that depends on SwiftProtobuf and Protobuf.

Our project use InternalLib as dependency.


So far I've successfully done these steps:

Step 1: Archive InternalLib

The Example app in InternalLib fetches the dependencies correctly, and a script generates archives the library from the InternalLib-ExampleApp.xcworkspace.

The result are 2 archives (iOS and simulator), compiled with this xcconfig:

SKIP_INSTALL = NO
BUILD_LIBRARY_FOR_DISTRIBUTION = YES
SWIFT_OPTIMIZATION_LEVEL = -Osize
OTHER_SWIFT_FLAGS = $(inherited) -verify-emitted-module-interface
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1

Step 2: Generate xcframework

The next step is generating the xcframework. For this step we have the following script:

function create_xcframework { 

  for NAME in "InternalLib" "Protobuf" "SwiftProtobuf"
  do 
    xcodebuild -create-xcframework \
      -framework archives/InternalLib-iOS_sim.xcarchive/Products/Library/Frameworks/$NAME.framework \
      -framework archives/InternalLib-iOS.xcarchive/Products/Library/Frameworks/$NAME.framework \
      -output products/universal/$NAME.xcframework
  done

}

..which successfully generates 3 XCFrameworks.

Step 3: Run cocoapods

At this step we regenerate the full project setup, and use cocoapods to connect each module to its dependencies.

I've tried a few configurations: dependencies fetched via cocoapods, and specifying the resulting XCFrameworks as separate Podspecs, in order to create the dependencies by having the InternalLib.xcframework depending on XCFrameworks only.

Both solutions fail in the same terms.


Issues:

  1. Preprocessor flags not available: When I compile, the compiler flags present in InternalLib configuration seem unavailable. In this specific case, the headers are trying to resolve the Protobuf dependencies via local #include "Header.h", instead of going to #include <Protobuf/Header.h>, like so, even if the GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS flag is set in the project's preprocessor flags.
  # #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
  # #import <Protobuf/GPBProtocolBuffers.h>
  # #else
  # #import "GPBProtocolBuffers.h"
  # #endif
  1. Missing symbols: By overriding the headers in order to forcefully use #import <Protobuf/GPBProtocolBuffers.h>, we get to the very end of the project compilation, just to fail with Undefined Symbol SwiftProtobuf.[...], which means the library of which InternalLib depends on was not found.

My questions here are:

  • Why is the preprocessor flag not seen while compiling the app?

  • is this this configuration of having a XCFramework depend on cocoapods libs not supported?

I am not sure if this is the best place to ask these questions, as it's using a 3rd party dependency manager, but maybe someone has tried a similar configuration in their project.

Thanks!

Wonder if you have resolved this yet? I met this case too and now the only way to build and run is comment all of this except ` #import <Protobuf/GPBProtocolBuffers.h>

XCFrameworks dependencies via Cocoapods
 
 
Q