4

Background: I'm converting a large old mixed language codebase to a framework. I'm having problems, so I thought I'd start with a minimal test project to see how things work. I ran into more problems. This is Swift 5.0 with Xcode 10.2.1.

I created a new iOS framework project called TestFramework. TestFramework has the following source files:

  • OCTest.[hm], with a single private class
  • OCPublic.[hm], with a single public class. It calls OCTest.
  • STest.swift, with a single public class. It calls both OCPublic and OCTest.

I also have the following two umbrella headers, in the same folder as the source files:

  • TestFramework.h, which is the one Xcode created automatically. I only added #import "OCPublic.h".
  • TestFramework_Private.h. It has two lines:

    #include "TestFramework.h"
    #include "OCTest.h"
    

They all reside in the TestFramework folder, along with Info.plist and everything else Xcode creates automatically.

I managed to make this compile, build a framework package with carthage build --archive and use the resulting framework successfully in a test app with the following module maps and build settings:

  • TestFramework/module.modulemap exists and is empty.
  • TestFramework/module.private.modulemap exists with these lines:

    module TestFramework_Private {
        umbrella header "TestFramework_Private.h"
        export *
    }
    
  • Both MODULEMAP_FILE and MODULEMAP_PRIVATE_FILE in build settings are unset.

  • SWIFT_INCLUDE_PATHS is $(PROJECT_DIR)/TestFramework.
  • DEFINES_MODULE is true.

If I add any content (framework module TestFramework { … }) to module.modulemap or try to make MODULEMAP_FILE or MODULEMAP_PRIVATE_FILE point to their files (with the values TestFramework/module.modulemap and TestFramework/module.private.modulemap) I get various build errors (can't find TestFramework_Private, redefinition of module TestFramework, etc.)

If I remove the empty main module map, I get No such module 'TestFramework_Private' where STest.swift tries to import it.

If I try to move the private things into a separate folder and change SWIFT_INCLUDE_PATHS and MODULEMAP_PRIVATE_FILE I get more build errors.

Are there some values for the MODULEMAP* settings that should work, with or without content inside the main module map? What should I do if I wanted to move things into different folders?

Juri Pakaste
  • 1,402
  • 10
  • 15

1 Answers1

3

It seems at least some of my problems were caused by this:

When building a framework that has module maps in both the source and the install directories that define the same module, the compiler will show a redefinition message. (28638816)

Workaround: Rename the module map file in the source directory to a non-default name (the default name is module.modulemap or module.map), and set the Module Map File build setting to the renamed module map.

Renaming my module map file to anything other than module.modulemap — the name used in, for example, all over Clang documentation — made it possible to point MODULEMAP_FILE at it, and allowed me to move the headers to a different location etc.

Community
  • 1
  • 1
Juri Pakaste
  • 1,402
  • 10
  • 15