XCFramework cannot import other XCFramework module

Thanks in advance, any help greatly appreciated.

I created an XCFramework from a C Library (say a libc.a and corresponding “include” folder with header files) , lets call it C.xcframework. I want to interact with it from Swift, so I created a modulemap and corresponding header file, like this:

modulemap


/// Expose C for Swift usage

module C {

header "shim.h"

}

shim.h


#ifndef shim_h

#define shim_h

// A shim header to bridge C to a Swift modulemap

#include <libc/header.h>

#endif /* shim_h */

As this is a C library, to offer a better interface to my Swift App, I decided I wanted to wrap it in a Swift Framework, let’s call it S framework. This S framework imports C.xcframework within the “Embedded Frameworks” section. The wrapper can now do import C and have access to all the functions exported by the modulemap without any issues. I created all sort of cool functions to wrap my C library and everything is tested and working. Excellent!

Now it is time for my App to make use of the S framework. To do so, I decided to create another S.xcframework. So I went ahead and archived the different architectures (iOS and iOS simulator). This time the compiler, as it is Swift code, created a Modules folder with the generated Modulemap for S and corresponding interface files. From this two archives I created a S.xcframework with the usual CLI command, referencing both architectures.

My App now imports S.xcframwork, and when I go and do the import S, I receive two build errors:

  • Failed to build module S
  • No such module C.

The last one is actually reported from module S, at the ios-simulator.swiftinterface file:


import Foundation

import C // !Error here, No such module C

@_exported import S

import Swift

So it seems like the imported S.xcframework cannot be built because it doesn’t have C. I went ahead and added C.xcframework to my project as well, again under the Frameworks section. And to my surprise, now the App can actually do import C without problem, but still fails when building with the same error. So for some reason the xcframework is not visible to the other xcframework.

Any guidance on how to solve this problem?

Thanks again!

Using @_implementationOnly import C in your framework may resolve this.

Thanks a lot for jumping in Boris.

I tried that, but I realized that I still need to reference some of the structures inside the C library (so they are used by public methods in the Swift wrapper framework). I guess I could wrap them as well so that nothing is exposed.

Is there any way I could maybe expose C as a submodule inside S?

Terms of Service

Privacy Policy

Cookie Policy