Unable to import IOKit in an iOS framework

66 Views Asked by At

I've written a DriverKit driver for iPadOS for a USB device. It's working fine. I'm trying to package up the app-side code in an SDK for it in a framework. The framework includes both Swift and C/Objective-C. The primary code creating a class to communicate with the driver is Swift, but there are some C-style headers, including some that are shared with the driver target, mostly for shared data types (enums and structs).

Both the Swift and C/Objective-C code use IOKit APIs and types.

The problem I'm running into is that IOKit is non-modular on iPadOS, and thus can't be imported directly in Swift, nor in a standard module-defining framework. In an app target (rather than a framework target) this can be worked around by importing <IOKit/IOKitLib.h> in the bridging header. The equivalent of doing this in a framework would be to import IOKit in the umbrella header, which effectively serves as the bridging header in a framework. However, doing that provokes a "include of non-modular header inside framework module..." error.

My first thought was to turn on the CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES build setting. Turning that setting on does not make the error go away.

My next thought was to also disable the DEFINES_MODULE setting, but that has two breaking effects:

  1. The framework can't be imported into Swift code (e.g. in an app) because it no longer defines a module.
  2. The framework still doesn't compile, because the framework's own Swift code no longer sees any of the bridged types imported in the umbrella header.

Has anyone run into and solved this problem? In short, is there a way to create a framework that imports IOKit on iPadOS and is itself importable in Swift?

0

There are 0 best solutions below