Cocoapods: How to use modulemap?

Created on 8 May 2016  路  7Comments  路  Source: CocoaPods/CocoaPods

Report

What did you do?

I'm wrapping around CommonCrypto in a Swift framework. It is CommonCrypto.swift, and I use a modulemap https://github.com/onmyway133/CommonCrypto.swift/blob/master/Sources/CCommonCrypto/module.modulemap

All is fine when I build and test the framework. But when I try to use this framework in a project, I get these errors

/Users/khoa/XcodeProject3/CommonCryptoSwift/Example/CommonCryptoSwiftDemo/DerivedData/CommonCryptoSwiftDemo/Build/Intermediates/Pods.build/Debug-iphonesimulator/CommonCryptoSwift.build/unextended-module.modulemap:6:8: Expected module name
/Users/khoa/XcodeProject3/CommonCryptoSwift/Sources/Crypto.swift:10:8: Could not build Objective-C module 'CCommonCrypto'

unextended-module modulemap 2016-05-08 22-19-32

Here is my podspec https://github.com/onmyway133/CommonCrypto.swift/blob/master/CommonCryptoSwift.podspec

I have HEADER_SEARCH_PATHS and SWIFT_INCLUDE_PATHS as this is needed for the framework, and module_map to tell Cocoapods where is the module map is

s.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2', 'SWIFT_INCLUDE_PATHS' => '${PODS_ROOT}/Sources/CCommonCrypto' }
s.module_map = 'Sources/CCommonCrypto/module.modulemap'

pod install is OK

Analyzing dependencies
Fetching podspec for `CommonCryptoSwift` from `../../`
Downloading dependencies
Installing CommonCryptoSwift 0.1.0 (was 0.1.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total
pod installed.

I must miss something, please help :)

Most helpful comment

@onmyway133 Hey, thank you for sharing your knowledge.
Using local development pod works if you replace
$(PODS_ROOT)/CommonCryptoSwift/Sources/CCommonCrypto with $(PODS_TARGET_SRCROOT)/Sources/CCommonCrypto.

PODS_TARGET_SRCROOT is set correctly for local pods.

All 7 comments

This bug might come from also having the module map in the list of source files -- can you please try removing it form there?

@segiddins thanks for your reply.

I changed the podspec to include swift files only. After pod deintegrate and pod install again, the same error appears

s.source_files = 'Sources/**/*.swift'

The use case for the modulemap attribute is setting a custom module map for the module the Pod defines, not for other modules you might want to use, such as CommonCrypto in this case. Your custom module map should be made available via SWIFT_INCLUDE_PATHS, but you should not set is as the module map of the Pod itself.

@neonichu thanks, it works now https://github.com/onmyway133/CommonCrypto.swift/blob/master/CommonCryptoSwift.podspec

s.source_files = 'Sources/**/*.swift'
s.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2', 'SWIFT_INCLUDE_PATHS' => '$(PODS_ROOT)/CommonCryptoSwift/Sources/CCommonCrypto' }
s.preserve_paths = 'Sources/CCommonCrypto/module.modulemap'

One thing that I'd like to mention is that Local Pod does not work https://github.com/CocoaPods/CocoaPods/issues/809, I have to use git other than path https://github.com/onmyway133/CommonCrypto.swift/blob/master/Example/CommonCryptoSwiftDemo/Podfile

pod 'CommonCryptoSwift', :git => 'https://github.com/onmyway133/CommonCrypto.swift'

I have my answer here http://stackoverflow.com/questions/25248598/importing-commoncrypto-in-a-swift-framework/37125785#37125785. Hope it helps someone

Thanks for the detailed follow-up :+1:

IIRC, we have an existing issue for the problem of not being able to reference custom modulemaps when using a development Pod, but I can't find it right now.

I wonder if the solution could be similar to what swiftpm does, making the CCommonCrypto its own Pod.

@onmyway133 Hey, thank you for sharing your knowledge.
Using local development pod works if you replace
$(PODS_ROOT)/CommonCryptoSwift/Sources/CCommonCrypto with $(PODS_TARGET_SRCROOT)/Sources/CCommonCrypto.

PODS_TARGET_SRCROOT is set correctly for local pods.

Don't feel that the remote & local paths are mutually exclusive. You can include both!

s.xcconfig = { 'SWIFT_INCLUDE_PATHS' => '$(PODS_ROOT)/CommonCryptoSwift/Sources/CCommonCrypto $(PODS_TARGET_SRCROOT)/Sources/CCommonCrypto }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

5SMNOONMS5 picture 5SMNOONMS5  路  3Comments

dawnnnnn picture dawnnnnn  路  3Comments

intelliot picture intelliot  路  3Comments

pallaviMN picture pallaviMN  路  3Comments

steffendsommer picture steffendsommer  路  3Comments