Sqlite.swift: Build failing with Xcode 7.3 beta

Created on 5 Feb 2016  Â·  33Comments  Â·  Source: stephencelis/SQLite.swift

My configuration is:

  • Using latest Xcode 7.3 beta (7D129n)
  • Using latest version of Cocoapods (0.39.0)
  • with Podfile:

```
use_frameworks!

target 'app' do

pod 'SQLite.swift'

end
```

I tried with or without xcode-select -s [PATH_TO_XCODE_BETA] or xcode-select -s [PATH_TO_XCODE], but they both failed by following reason:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/module.modulemap:1:8: error: redefinition of module 'Compression'
module Compression [system] [extern_c] {
       ^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/include/module.modulemap:1:8: note: previously defined here
module Compression [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/module.modulemap:6:8: error: redefinition of module 'Darwin'
module Darwin [system] [extern_c] {
       ^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/include/module.modulemap:6:8: note: previously defined here
module Darwin [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/module.modulemap:1478:8: error: redefinition of module 'os'
module os [system] [extern_c] {
       ^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/include/module.modulemap:1599:8: note: previously defined here
module os [system] [extern_c] {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/module.modulemap:1494:8: error: redefinition of module 'libkern'
module libkern [system] [extern_c] {
       ^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/include/module.modulemap:1615:8: note: previously defined here
module libkern [system] [extern_c] {
       ^
<unknown>:0: error: could not build Objective-C module 'SQLite'
cocoapods

Most helpful comment

The behavior for this appears to have changed in the final version of Xcode 7.3, at least for AppleTV (haven't tested iOS yet).

Previously, for AppleTV using iPhoneOS.platform worked fine. However as of 7.3, when building for device the platform in the path needs to be AppleTVOS.platform and when building for simulator, the path needs to be AppleTVSimulator.platform.

If the platforms don't match, it results in the above "redefinition of module" errors. I suspect this is likely affecting iOS as well.

All 33 comments

Hello,

Try the following:

  • Update Xcode to the latest 7.3 beta 3 (7D141l)
  • Change the path to sqlite3.h in podstuff/module.modulemap by replacing Xcode.app with Xcode-beta.app.

You may need to clean everything before Xcode notices the change, though.

solved. thanks @groue !

The behavior for this appears to have changed in the final version of Xcode 7.3, at least for AppleTV (haven't tested iOS yet).

Previously, for AppleTV using iPhoneOS.platform worked fine. However as of 7.3, when building for device the platform in the path needs to be AppleTVOS.platform and when building for simulator, the path needs to be AppleTVSimulator.platform.

If the platforms don't match, it results in the above "redefinition of module" errors. I suspect this is likely affecting iOS as well.

I can confirm that it's the same on iOS. I can build and run on the device, but running through the simulator gives me the redefinition of module errors like you said.

+1 to what cjwirth and shnhrrsn said

For your information, GRDB.swift could solve this issue by moving the SQLite C functions declarations in a separate module, which depends on both the target (OSX framework or iOS framework) _and_ the platform (device, simulator):

I wish it was simpler, but at least it works.

The module map is only necessary for CocoaPods, which makes this kind of ceremony pretty unfortunate. I think half of it can be simplified using separate spec.ios and spec.osx flags, though.

I don't know if this is still true, @stephencelis. Since 7.3 betas, Xcode has gotten very picky when you include a header from an SDK which is not the one you build for. It used to work, yes. But now it looks like this is the root of all this issue of SQLite.swift. But maybe I have missed something.

@groue My hope is that CocoaPods will eventually be able to distinguish between iOS and iOS Simulator module maps. E.g.,

spec.osx.module_map = 'path/to/osx/module.modulemap'
spec.ios.module_map = 'path/to/ios/module.modulemap'
spec.ios.simulator.module_map = 'path/to/ios_simulator/module.modulemap'
# ...

Actually, even GRDB _tests_ won't run in the simulator unless I pick the exact header for the iPhoneSimulator platform .../iPhoneSimulator.platform/... (and of course CocoaPods is not involved).

Don't you have this issue as well?

Filed an issue here: https://github.com/CocoaPods/CocoaPods/issues/5071

In the meantime, installing the project manually or using Carthage are temporary fixes, while I'll accept PRs with @groue's solution above @cjwirth's solution below (I don't have time to carve out a solution for CocoaPods right now).

_Edit:_ This solution appears to be less invasive: https://github.com/stephencelis/SQLite.swift/issues/349#issuecomment-199859137

Actually, even GRDB _tests_ won't run in the simulator unless I pick the exact header for the iPhoneSimulator platform .../iPhoneSimulator.platform/... (and of course CocoaPods is not involved).

Don't you have this issue as well?

@groue The framework tests run fine. SQLite.swift uses an SDK root-relative header.

The framework tests run fine. SQLite.swift uses an SDK root-relative header

OK so I guess that you don't test against the SQLite.swift _framework_, but you embed SQLite.swift _sources_ in your test target. I get it.

OK so I guess that you don't test against the SQLite.swift _framework_, but you embed SQLite.swift sources in your test target. I get it.

I'm probably not communicating very well, but nope, I test against the framework itself and everything works just fine. Feel free to check out the repo!

@groue your suggestion works for me, thanks. Are you going to be making a PR with that change?

I don't have 7.3 on the machine I have right now yet, so I can't guarantee that it will work.

I took a different approach when I added CocoaPods support to Swifter. I basically copied the technique from this article. 👈 There is a script in there that also tries to get the correct SDK root for the version of Xcode that is being used. You can take that part out if you just want to support Official Xcode.app

Basically, it came down to making 3 different module map files, and in the Build Settings, changed which one it was looking at based on the configuration. It worked in 7.2 on an app we currently have released to the app store.

Plus, we wouldn't have to do that whole #if (OSX) import SQLiteOSX ... dance

@cjwirth That looks like a more elegant solution to the problem! It achieves what I was hoping a spec.ios.simulator.module_map scope would allow. Thanks for the link! Anyone with the time to contribute a PR will see a quick merge and version bump! :smile:

Are you going to be making a PR with that change?

@brandenr: No, I'm maintaining GRDB.swift, another SQLite lib, and was just there to communicate a working solution (among others).

OK, I just installed Xcode 7.3 and confirmed that the technique does still work -- I created a new project with Swifter as a CocoaPod, and I was still able to install, build, and import it.

It's getting kind of late (UTC+9), but if nobody has it done by tomorrow morning, I'll see if I can put it together.

Thanks for testing that. I'm giving it a shot to make a PR with that suggestion.

Thanks @brandenr!

Sorry, while I was able to get @groue's solution in in a few minutes, I seem to be unable to figure out how to get @cjwirth's solution done. I seem to be down to I can't get the module map file to be able to specify the umbrella header bit and then if I take that out, I can't get FTS4 to find _SQLiteRegisterTokenizer that's located by using the umbrella header to the bridging header

Using @groue's method, I've made myself a branch I'm currently using. It also supports tvOS

pod 'SQLite.swift', :git => 'https://github.com/brandenr/SQLite.swift.git', :commit => '33ced0255e99e85b7ad65288dc777f6bb9c53687'

It has to paste that import into multiple places, so if someone can figure out @cjwirth's method, that'd be better.

@brandenr, thanks for sharing. I've tested your commit on my AppleTV app on Xcode 7.3 and works great.

https://github.com/stephencelis/SQLite.swift/pull/379 Pull request for platform related inclusions of header files.

@eneko Can you test the following branch on an actual Apple TV? I want to make sure the architectures are right.

pod 'SQLite.swift',
  git: 'https://github.com/stephencelis/SQLite.swift.git',
  branch: 'cocoapods-xcode-7-3'

Thanks!

Would those having issues try this solution? https://github.com/stephencelis/SQLite.swift/issues/380

@brandenr Can you provide more info on the platform you're building for (simulator and/or device) and/or provide a repo exhibiting the issue?

Oh, sorry, I had taken a second screenshot, but apparently pasted in the first. I built for iPhone 6S plus iOS 9.3 simulator in Xcode 7.3

https://www.dropbox.com/s/zfvic93x7w6bcye/Screenshot%202016-03-23%2011.38.59.png?dl=0

@brandenr Using the branch/pod mentioned in #380? Can you hold option and select
Clean Build Folder… from the Product menu after running pod install?

Having same problem. See attachment.
screen shot 2016-03-24 at 10 39 53

Was this page helpful?
0 / 5 - 0 ratings

Related issues

WDDong picture WDDong  Â·  7Comments

bitflying picture bitflying  Â·  5Comments

justdan0227 picture justdan0227  Â·  7Comments

hansrajgavali picture hansrajgavali  Â·  3Comments

DiamondYuan picture DiamondYuan  Â·  3Comments