Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRDB 3 and Xcode 10.2 #482

Closed
groue opened this issue Feb 20, 2019 · 15 comments

Comments

Projects
None yet
4 participants
@groue
Copy link
Owner

commented Feb 20, 2019

Xcode 10.2 does not compile GRDB 3 correctly. You will see warnings. There is no guarantee of correct behavior.

This is currently no plan to ship a version of GRDB 3 which supports Swift 5 and Xcode 10.2, and this is why this issue is flagged with the wontfix label. This is due to difficulties brought by the backward compatibility with Xcode 9.3, Swift 4.0, and the lack of SE-0212 which makes long-run maintenance hazardous. See this post for more information.

All known development efforts are currently targeted on the upcoming GRDB 4, which targets iOS 9.0+ / macOS 10.9+ / watchOS 2.0+ • Swift 4.2+ / Xcode 10.0+.

Yet a pull request which brings support for Xcode 10.2 and Swift 5 to GRDB 3, without breaking backward compatibility, will be warmly welcomed. This issue will then be updated accordingly.

@groue groue added the wontfix label Feb 20, 2019

groue added a commit that referenced this issue Feb 20, 2019

@gereons

This comment has been minimized.

Copy link

commented Feb 20, 2019

Thanks for the heads-up!

@groue groue changed the title GRDB 3.6.2 and Xcode 10.2 beta GRDB 3.7.0 and Xcode 10.2 beta Mar 9, 2019

@groue groue changed the title GRDB 3.7.0 and Xcode 10.2 beta GRDB 3 and Xcode 10.2 beta Mar 9, 2019

@groue groue changed the title GRDB 3 and Xcode 10.2 beta GRDB 3 and Xcode 10.2 Apr 2, 2019

@gereons

This comment has been minimized.

Copy link

commented Apr 5, 2019

Questions related to this issue: are there any known issues with running GRBD 3.7.x using Xcode 10.2 in Swift 4.2 mode? If not, what's your opinion on adding a corresponding swiftversion specification to the podspec? This would make migration of apps to Swift 5 a little easier, afaict.

@groue

This comment has been minimized.

Copy link
Owner Author

commented Apr 10, 2019

Hello @gereons,

Questions related to this issue: are there any known issues with running GRBD 3.7.x using Xcode 10.2 in Swift 4.2 mode?

I am concerned about GRBD 3.7.x + Xcode 10.2 in Swift 4.2 mode because I see warnings around hashValue and hash(into:) pairs:

#if swift(>=4.2)
public func hash(into hasher: inout Hasher) { ... }
#else
public var hashValue: Int { ... }
#endif

This kind of code is necessary for GRDB 3, which has to support Xcode 9.3 and Swift 4. Unfortunately, it does not compile smoothly with the Swift 5 compiler, regardless of the mode. It looks that the obsolete hashValue will be compiled instead of the hash(into:) method, sometimes. I don't know exactly when. I'm not positively sure how to fix this.

If not, what's your opinion on adding a corresponding swiftversion specification to the podspec?

We can't do that in a GRDB 3 release, because this would be a breaking change.

When I wrote this issue, the context was different: Xcode 10.2 was still in beta. I chose to focus on the GRDB 4 development, because this was the "best value" strategy: support for Xcode 10.0 up to Xcode 10.2, Swift 4.2 up to Swift 5, some little breaking changes, and the opportunity to migrate to SQLCipher 4.

Unfortunately, GRDB 4 is late.

And you are concerned, because you can not write your podspec in a way that it declares a dependency on GRDB 4. You're stuck, and you don't exactly know how to support Xcode 10.2. And I don't have any ready-made solution for you right now.

GRDB 4 is late, and I foresee a few more weeks until it ships.

I wrote, above:

Yet a pull request which brings support for Xcode 10.2 and Swift 5 to GRDB 3, without breaking backward compatibility, will be warmly welcomed. This issue will then be updated accordingly.

This remains very true. I did not do the full analysis of the hashValue/hash(into:) problem. But someone else can do it. If this is done with the expected care, we'll be able to ship 3.7.1 which does not remove anything and adds support for Xcode 10.2.

@groue

This comment has been minimized.

Copy link
Owner Author

commented Apr 10, 2019

I did not do the full analysis of the hashValue/hash(into:) problem.

I started, though, in the feature/xcode-10.2 branch. But I am not sure at all it is correct, and that it really supports all versions of Xcode from 9.3, and all versions of Swift from 4.0. A second eye could help. An eagle eye, please.

@gereons

This comment has been minimized.

Copy link

commented Apr 10, 2019

Thanks for the detailed reply!

I've just done a quick experiment: I'm forcing usage of Swift 4.2 for GRDB in my Podfile using the ruby snippet below, and I've removed the usual inhibit_all_warnings! directive. The main app as well as a few other Pods I'm using are using Swift 5. GRDB compiles cleanly, with only a few warnings about "redundant public specifier in a public extension", and my app seems to work fine and all GRDB-related unit tests pass. In particular, I'm not seeing any warnings related to hash/hashValue, not even when I remove the SWIFT_VERSION hackery. (In that case, compilation of GRDB fails with a couple of errors related to @autoclosures and a few deprecation warnings).

This seems to indicate to me that adding s.swift_version = 4.2 to a GRDB 3 release should be possible without breaking anything, or am I missing something?

Also, to clarify: my concern is not that I'm in a hurry to migrate to GRDB 4. What my suggestion would achieve, IMHO, is just that I could migrate my pod to Swift 5 before GRDB 4 is released, and without my users having to do the version hack.

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if ['GRDB.swift'].include? target.name
      target.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '4.2'
      end
    end
  end

end
@groue

This comment has been minimized.

Copy link
Owner Author

commented Apr 10, 2019

@gereons

No, s.swift_version = 4.2, is not a solution, because GRDB 3 is supposed to work with Swift 4 (yes, Swift 4.0), and I try to do my best to follow the constraints of semantic versioning. SemVer is the very reason why you can update your CocoaPods, get bug fixes and improvements, without breaking your apps. I expect libraries I trust to be committed to SemVer, and GRDB is no exception: if I can avoid a glaring mistake, I avoid it. Dropping support for Swift 4.0 is such a mistake.

SemVer recommends that breaking changes only happen in major releases. The next one is GRDB 4. It contains all the breaking changes I had to hold up until they became possible. Check #479 for the list of those breaking changes. Requiring Swift 4.2+ is one of them.

Yes, quick experiments don't reveal any trouble. Mine either. But quick experiments are just that: quick. And GRDB is not just for you, or me. "It works on my machine" is not the principle that drives this library.

Here are the options I'm aware of:

  • Wait for GRDB 4
  • Fork GRDB 3, add s.swift_version = 4.2 in your fork
  • Perform more than a quick experiment, and send a pull request which (sorry to repeat myself), does not break anything but adds support for Xcode 10.2 and Swift 5. As told above, the feature/xcode-10.2 branch may be a good starting point.
  • Suggest any alternative I did not think about, as long as it respects other users and the constraints of semantic versioning.
@RobinThrift

This comment has been minimized.

Copy link

commented Apr 17, 2019

Thanks a lot for the heads up! I have switched to the GRDB 4 branch and so far have had no issues whatsoever. Great work as usual 😉

@danthorpe

This comment has been minimized.

Copy link

commented May 9, 2019

For others who are using the GRDB-4.0 branch - is there some special Cocoapods magic required here?

After following comments from CocoaPods/CocoaPods#8118 (comment), my Podfile looks something like this :

platform :ios, '12.1'

pre_install do |installer|
  installer.analysis_result.specifications.each do |s|
    s.swift_version = '5.0' unless s.swift_version
  end
end

def grdb
  pod 'GRDB.swift', 
    :git => 'https://github.com/groue/GRDB.swift.git', 
    :branch => 'GRDB-4.0'
end

target 'Database' do
  use_frameworks!  
  grdb
end

and using CP version 1.7.0.rc.1 it fails with the usual:

$ bundle exec pod install
Analyzing dependencies
Pre-downloading: GRDB.swift from https://github.com/groue/GRDB.swift.git, branch GRDB-4.0
Downloading dependencies
Installing GRDB.swift (3.7.0)
[!] Unable to determine Swift version for the following pods:

  • GRDB.swift does not specify a Swift version and none of the targets (Database) integrating it have the SWIFT_VERSION attribute set. Please contact the author or set the SWIFT_VERSION attribute in at least one of the targets that integrate this pod.

Would it be possible to update the podspec on the GRDB-4.0 branch to set the swift_version to 5, and to also update the version number in the podspec? Happy to submit a PR if that helps? Or is there something else I can do locally (my target already specifies Swift version 5) to get CP to install GRDB without having to maintain a fork through v4 development? 🧐

@groue

This comment has been minimized.

Copy link
Owner Author

commented May 9, 2019

Hello @danthorpe,

The CocoaPods error says:

GRDB.swift does not specify a Swift version and none of the targets (Database) integrating it have the SWIFT_VERSION attribute set. Please contact the author or set the SWIFT_VERSION attribute in at least one of the targets that integrate this pod.

You have contacted the author. But the fix is to set SWIFT_VERSION in your targets.

For more context, see #410

@danthorpe

This comment has been minimized.

Copy link

commented May 9, 2019

Hi @groue, thanks for the quick response.

I have SWIFT_VERSION set in my targets, but still see this error. Hence I'm wondering if there is some other CP magic needed.

However now that swift_versions is available, can the original decision (referenced in #410 and #375) of not specifying compatible swift versions in the library's podspec be revisited?

@danthorpe

This comment has been minimized.

Copy link

commented May 9, 2019

Ah ha! Found the necessary cocoapods magic after looking at this issue: CocoaPods/CocoaPods#8653 (This is perhaps also because I'm using CocoaPods Rome as I don't want to be constantly rebuilding my dependencies)

target 'Database' do
  use_frameworks!
  # Force CP to recognise my target's swift version
  current_target_definition.swift_version = '5.0'
  grdb
end

Updating here, just in case someone else finds it useful.

@groue

This comment has been minimized.

Copy link
Owner Author

commented May 10, 2019

However now that swift_versions is available, can the original decision (referenced in #410 and #375) of not specifying compatible swift versions in the library's podspec be revisited?

Very good idea! It will be 4.2 and 5.

And thank you for sharing your workaround :-)

@groue

This comment has been minimized.

Copy link
Owner Author

commented May 21, 2019

@danthorpe, you wrote:

However now that swift_versions is available

Well, not yet. CocoaPods/CocoaPods#8191 is in the 1.7.0 milestone, which has not shipped yet.

Does this mean we can't use it right now?

Well, when I search for swift_versions (with a final s) in the published CocoaPods, I only find a few that specify multiple versions. Those few pods have very barely no Github stars at all.

Two possible interpretations:

  1. The feature is not ready, and one should not publish a pod with multiple swift_versions because it won't work with users who do not use a prerelease version of CocoaPods 1.7.0.
  2. The feature is ready, but very few CocoaPods do support multiple swift versions.

The safest is 1. I prefer waiting for the release of CocoaPods 1.7.0 before I upgrade GRDB podspec with multiple Swift version. Of course, I may be wrong.

@groue

This comment has been minimized.

Copy link
Owner Author

commented May 23, 2019

GRDB 4.0.0 has shipped, with support for Xcode 10.2. The Migration Guide will help you upgrading your applications to GRDB 4.

@groue groue closed this May 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.