Swift Package Manager Public Headers with Complicated Layouts

2.4k views Asked by At

I have a sample Swift Package Manager package (let's call it TestPackage), that is structured in the following way:

TestPackage/
  Sources/
    TestPackage/
      Services/
        Services.h
        Services.m
      TestPackageUI/
        UIComponent1.h
        UIComponent1.m
        UIComponent2.h
        UIComponent2.m
      include/
        TestPackage.h (umbrella header)

The contents of my TestPackage.h look something like this:

/// Umbrella header

/// Services
#import "Services.h" // (or "Services/Services.h")

/// TestPackageUI
#import "Component1.h" // (or "TestPackageUI/Component1.h")
#import "Component2.h" // (or "TestPackageUI/Component2.h")

What I want is that users of this package can do import this package into objc/swift and use the Services and TestPackageUI. They could do something such as:

Objective-C:

@import TestPackage;
/// or
#import <TestPackage.h>

Swift:

import TestPackage

The SPM Usage documentation says:

In case of complicated include layouts or headers that are not compatible with modules, a custom module.modulemap can be provided in the include directory.

So I added a module.modulemap in the include directory with the following content:

module TestPackage {
  header "TestPackage.h"
  export *
}

But when I try to use this package, the umbrella header TestPackage.h cannot find the header files it includes. Note that these sub-directories are added as headerSearchPaths in the C Settings of the target. I would like to maintain the same project structure. Can anyone help with the correct way to write a modulemap that works with this layout? Thanks in advance.

0

There are 0 answers