0

My library is composed by two modules:

  • The library core in Swift
  • A module in C which includes CHTMLSAXParser

This is the structure

enter image description here

Now in order to compile it in SPM I need to create two targets:

import PackageDescription

let package = Package(
    name: "MyLib",
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "MyLib",
            targets: ["MyLib"]),
    ],
    dependencies: [],
    targets: [
        .target(
            name: "CHTMLSAXParser",
            dependencies: []),
        .target(
            name: "MyLib",
            dependencies: ["CHTMLSAXParser"])
    ]
)

This is pretty straightforward: in MyLib a source swift file call import CHTMLSAXParser and everything works fine.

However I don't know what's the correct way to replicate the same behaviour with CocoaPods podspec file.

Any idea?

danielemm
  • 1,636
  • 1
  • 14
  • 24
  • You want a podspec and a subpodspec. What have you tried? – Larme Nov 16 '20 at 17:16
  • I've tried with subpodspec but it does not work https://gist.github.com/malcommac/31aea9a80bd5670ae0a8f606681003ea It just can't recognize the module in my main lib: ` - ERROR | [MyLib/Core] xcodebuild: /.../EscapeSpecialCharacters.swift:22:8: error: no such module 'CHTMLSAXParser'` – danielemm Nov 16 '20 at 17:30

1 Answers1

1

I've discovered mixed Swift/ObjC modules limitation does not apply to CocoaPods. So in order to solve the problem:

  1. I've created a single podspec package which includes both C and Swift files
  2. Used #if canImport(CHTMLSAXParser)? to avoid importing it when no necessary (under cocoapods) without generating a compiler error.

More infos here

danielemm
  • 1,636
  • 1
  • 14
  • 24