4

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.

B. Morfe
  • 61
  • 4
  • 2
    Package's `Target` have `publicHeadersPath` property. Please use it. Please stop editing module maps. Generation of correct module maps is SPM responsibility. – Cy-4AH Apr 05 '22 at 10:25
  • I don’t see how editing that property helps with my problem. All I can do with that is change the directory where my public headers are placed—in other words, some directory other than include. I also don’t want my implementation files to be made public. Furthermore, the SPM usage guidelines advises that you to create a custom module map if you have complicated layouts, so why is it that you recommend I don’t? – B. Morfe Apr 06 '22 at 12:07
  • 1
    Put implementation files into other folder and they will not be public, doesn't need to create complicated layout. – Cy-4AH Apr 06 '22 at 14:58
  • 2
    That is what I want to avoid doing, hence why I want to get it working with the current layout. – B. Morfe Apr 07 '22 at 01:33

0 Answers0