Sqlite.swift: XCode 9.0 Beta : Compile Error

Created on 8 Jun 2017  路  22Comments  路  Source: stephencelis/SQLite.swift

After updating to XCode 9 Beta, the following Compiler Error occurred (SQlite.swift 0.11.2). How can I solve it?
2017-06-08 11 44 23

Most helpful comment

Nice catch, @thebluepotato. Replacing all lines
import CSQLite
with
import SQLite3
Got everything compiling.

All 22 comments

Fully acknowledge that I have no idea what I am doing. But given that it is complaining about files not found I figured it would be worth starting there.

So looking in the app bundles for Xcode 8.3.3 vs Xcode 9.0.0 I found this:

Xcode Version 8.3.3 (8E3004b)

/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/AppleTVOS.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/AppleTVSimulator.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/iPhoneOS.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/iPhoneSimulator.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/MacOSX.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/WatchOS.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/WatchSimulator.sdk/usr/include/sys/_symbol_aliasing.h

Xcode Version 9.0 beta (9M136h)

/Applications/Xcode-beta.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode-beta.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode-beta.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/sys/_symbol_aliasing.h
/Applications/Xcode-beta.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/sys/_symbol_aliasing.h

The thing that seems to be different is the fact that it is _not_ included in /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain like it is on 8.3.3.

This could be a red herring but I thought I'd point it out.

I don't know if it's merely a fun fact, but the Xcode 9.0 beta 1 release notes state :

SQLite APIs can now be imported into Swift under the module name SQLite3

If only had a brief look, but it seems to be a very "raw" import, meaning all functions are prefixed with sqlite3_ to the point it seems it's more "ease of access" to the API than a real native Swift port. Maybe this will evolve to a real Swift syntax, but I guess it could be an option here for now to base SQLite.swift on the "official" API using import SQLite3 instead of having to resort to custom modulemaps, which would probably solve the issue presented here.

Nice catch, @thebluepotato. Replacing all lines
import CSQLite
with
import SQLite3
Got everything compiling.

that is very fascinating.

@bridger Glad it helped! However for me, replacing all CSQLite import statements with SQLite3 did solve the current issue but raised the one mentioned in #663, namely an issue with map. Have you been able to fix that one?

I haven't got that map error. Maybe that comes from trying to use Swift 4? I'm using Xcode 9 but I'm letting SQLite.swift continue using Swift 3.2. The compiler can mix and match targets with different Swift versions now so there is no need to convert SQLite.swift to Swift 4 prematurely. It won't keep you from using Swift 4 in your main project.

For anyone using CocoaPods, here is a snippet to add to your post_install do section of your Podfile. It will go over the directory structure for SQLite.swift and apply @bridger's fix.
puts 'Patching SQLite.swft to fix for XCode 9 Beta https://github.com/stephencelis/SQLite.swift/issues/664#issuecomment-307282095' Dir.glob('Pods/SQLite.swift/Sources/SQLite/**/*.swift').each { |path| begin text = File.read(path) text = text.gsub(/import CSQLite/, 'import SQLite3') File.open(path, 'w') { |file| file.puts text } rescue Exception puts "Unable to patch #{path}: #{$!}" end }

@rygood Thanks for the snippet, pod files seems to be readonly. getting multiple errors like the following.

Unable to patch Pods/SQLite.swift/Sources/SQLite/Typed/Collation.swift: Permission denied - Pods/SQLite.swift/Sources/SQLite/Typed/Collation.swift

Yep, files in the "Pods" project are locked. Maybe this can be circumvented by script?
Before addressing the Swift 4 mapissue (which frankly I believe is only a misinterpretation by the interpreter of join the object and join() the function), a specific swift4 branch could already:

  • Replace import CSQLite with import SQLite3
  • Remove all the modulemaps

Snippet wont edit locked file. I'm using a fork for now.

pod 'SQLite.swift', :inhibit_warnings => true, :git => 'https://github.com/spronin/SQLite.swift.git'

My work around for the locked files is nuking the Pods/ directory and doing a fresh pod install the script is able to modify the files on the first install.

@thebluepotato would you mind setting up a PR for this (swift4 branch)? Unfortunately I don't have much time to maintain SQLite.swift at the moment.

I've set up the necessary updates (and fixed the map issue), I just need someone to create a swift-4 branch here so my PR can point to there. pod lib lint fails for now but installing from git and compiling work in my project. All tests passed, except those for SQLCipher (untested).

NB : about the map issue, I think Swift 4 is stricter between single-tuple and multiple arguments, meaning that if you map a collection of tuples, the argument is the tuple, not the tuples sub-components (will be clearer once you see the code).

@thebluepotato branch created

@jberkel Thanks! PR #668 created.

there's now a swift-4 branch available

Thank you @rygood
Your solution works fine.

First I removed SQLite from my podfile, so I could uninstall it.
I deleted the following lines:

use_frameworks!
  pod 'SQLite.swift'

Then $ pod install
Now SQLite has been removed.

Then I put SQLite back and also put the code you made for us.

use_frameworks!
  pod 'SQLite.swift'

  post_install do
      Dir.glob('Pods/SQLite.swift/Sources/SQLite/**/*.swift').each { |path|
          begin
              text = File.read(path)
              text = text.gsub(/import CSQLite/, 'import SQLite3')
              File.open(path, 'w') { |file| file.puts text }
              rescue Exception
              puts "Unable to patch #{path}: #{$!}"
          end
      }
  end

Then $ pod install
Now SQLite has been installed and those lines containing 'import CSQLite' were replaced by 'import SQLite3'.
It worked fine.
Many thanks from Brazil

With Xcode 9GM I no longer have any errors or warnings compiling this. I'm using version 0.11.3, so maybe it was just an issue with the beta Xcode only?

There will be 0.11.4 soon, with the swift4 changes (#725).
@joshfriend interesting, maybe it broke too many things so they rolled some changes back

On an unrelated project, I saw these errors merely because my Xcode 9 (release, not beta) wasn't located at exactly /Applications/Xcode.app, rather Xcode 8 was there while Xcode 9 was at /Applications/Xcode Nein.app. I didn't go changing any SQLite imports to fix it, just renamed the app. Maybe this is applicable to you guys.

@aleczadikian this should no longer by an issue (with the release branch and upcoming 0.11.4)

Closed with 0.11.4

Was this page helpful?
0 / 5 - 0 ratings