onekiloparsec / SwiftAA

The most comprehensive collection of accurate astronomical algorithms in (C++, Objective-C and) Swift.
http://www.onekiloparsec.dev/
MIT License
171 stars 31 forks source link

Migrate from Objective-C++ to pure Swift #122

Open alex-vasenin opened 1 month ago

alex-vasenin commented 1 month ago

Swift 5.9 introduced direct interoperability with C++ without relying on Objective-C as a bridge. That means that we can get rid of Objective-C wrappers and improve performance a bit. Backward compatibility isn't much of problem, since starting from 29.04.2024 apps uploaded to the App Store must be build with Xcode 15.

alex-vasenin commented 1 month ago

I tried to port CAARiseTransitSet2 to SwiftAA using native C++ interoperability and I think it's not ready for production.

First, at the moment if one of your dependencies needs cxx-interop you must enable it for entire project (see https://github.com/swiftlang/swift/issues/66156).

Second, enabling cxx-interop for existing project is potentially a code-breaking change. Specifically, in SwiftAA I have to make one testing function which returns Never private because it produces an error in generated SwiftAA-Swift.h file. Another similar error in this file is that compiler can't find definitions of UIColor/NSColor and CLLocation classes (I have to resort to ObjC-style forward-declaring them in one of the header, but it didn't work on the client).

And the third thing is enabling cxx-interop increases compilation duration 3-4 times. Considering one have to enable interop for entire project it's a deal breaker.

The results are here (it's not finished, some headers and ObjC forward declarations are missing from produced framework)

I hope the situation will improve in future.