0

Summary: How do I make a podspec that includes a project itself using a Podfile?

I've build a Mac framework and as part of the workspace I use a cocoapod library, OpenSSL-Universal. The linked library is all written in C, whereas my project is in Swift, so I created a directory called SwiftSSL and in that I put a module.modulemap file like so:

module SwiftSSL {
header "../Pods/Headers/Public/OpenSSL-Universal/openssl/ssl.h"
header "../Pods/Headers/Public/OpenSSL-Universal/openssl/crypto.h"
export *
}

That let's me import SwiftSSL in my project and not use a bridging header file.

It seems to work fine via my unit tests. Now I want to turn this whole thing into a pod of its own, but I can't for the life of me figure out how to write the podfile so that the calling projects don't need to also include OpenSSL-Universal in their installations.

I tried adding these lines to my podspec:

s.source_files = "**/*.{h,swift}"
s.exclude_files = "Classes/Exclude"
s.preserve_paths = "SwiftSSL/module.modulemap"
s.xcconfig = {
"SWIFT_INCLUDE_PATHS" => "$(SRCROOT)/SwiftSSL/**",
'HEADER_SEARCH_PATHS' => "$(SRCROOT)/Pods/Headers/Public/OpenSSL-Universal",
'LIBRARY_SEARCH_PATHS' => "$(SRCROOT)/Pods/OpenSSL-Universal/lib-macros"
}

But when I pod spec lint my file I get tons of build errors:

-> SwiftHttp2 (0.0.1)
- ERROR | [OSX] xcodebuild: Returned an unsuccessful exit code. You can use --verbose for more information.
- NOTE | [OSX] xcodebuild: :1:9: note: in file included from :1:
- NOTE | [OSX] xcodebuild: Target Support Files/SwiftHttp2/SwiftHttp2-umbrella.h:13:9: note: in file included from Target Support Files/SwiftHttp2/SwiftHttp2-umbrella.h:13:
- ERROR | [OSX] xcodebuild: SwiftHttp2/Pods/OpenSSL-Universal/include-macos/openssl/aes.h:55:11: error: 'openssl/opensslconf.h' file not found
- NOTE | [OSX] xcodebuild: :0: error: could not build Objective-C module 'SwiftHttp2'
- NOTE | [OSX] xcodebuild: ld: warning: directory not found for option '-LPods/OpenSSL-Universal/lib-macros'
- NOTE | xcodebuild: clang: error: linker command failed with exit code 1 (use -v to see invocation)
- NOTE | [OSX] xcodebuild: error: cannot parse the debug map for "/Users/scott/Library/Developer/Xcode/DerivedData/App-cwmkyklahssytecgweyweofvxvis/Build/Products/Release/SwiftHttp2/SwiftHttp2.framework/Versions/A/SwiftHttp2": No such file or directory
- ERROR | [OSX] xcodebuild: /Users/scott/Library/Developer/Xcode/DerivedData/App-cwmkyklahssytecgweyweofvxvis/Build/Products/Release/SwiftHttp2/SwiftHttp2.framework/Modules/module.modulemap:9:12: error: header 'SwiftHttp2-Swift.h' not found
- ERROR | [OSX] xcodebuild: /var/folders/vn/nlxdstyj57q667x6_c5kl72m0000gp/T/CocoaPods-Lint-20180105-63782-3kwgth-SwiftHttp2/App/main.swift:1:8: error: could not build Objective-C module 'SwiftHttp2'
- NOTE | [OSX] xcodebuild: ld: warning: directory not found for option '-LOpenSSL-Universal/lib-macros'
- NOTE | [OSX] xcodebuild: error: cannot parse the debug map for "/Users/scott/Library/Developer/Xcode/DerivedData/App-cwmkyklahssytecgweyweofvxvis/Build/Products/Release/App.app/Contents/MacOS/App": No such file or directory

Gargoyle
  • 9,590
  • 16
  • 80
  • 145

1 Answers1

0

It should be sufficient to define the dependency with one additional line in the podspec:

s.dependency 'OpenSSL-Universal'

See more about creating CocoaPods here and here.

Paul Beusterien
  • 27,542
  • 6
  • 83
  • 139
  • Thanks, that solved all but one of the errors. Now it says `Encountered an unknown error (The 'Pods-App' target has transitive dependencies that include static binaries` – Gargoyle Jan 06 '18 at 18:58
  • With CocoaPods 1.4, you can add `s.static_framework = true` to your podspec to allow static framework dependencies. – Paul Beusterien Jan 06 '18 at 23:32
  • I upgraded to the 1.4.0 prelease of cocoapods but now I get tons of errors around things like `error: cannot load underlying module for 'XCTest'` – Gargoyle Jan 06 '18 at 23:38
  • Weird. Try removing ~/Library/Developer/Xcode/DerivedData/, pod deintegrate, pod install, and restarting Xcode – Paul Beusterien Jan 06 '18 at 23:41
  • Did what you said. Full Xcode test suite still runs fine, but the pod lint throws all those errors. For each of my swift files it's saying it can't find the .o of the file down the derived data `Pods.build/Release/SwiftHttp2.build/Objects-normal/x86_64` directory – Gargoyle Jan 06 '18 at 23:46