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

Make the precompiled binaries work across multiple swift compiler versions #4

Closed
cormacrelf opened this issue Aug 19, 2021 · 2 comments · Fixed by #6
Closed

Make the precompiled binaries work across multiple swift compiler versions #4

cormacrelf opened this issue Aug 19, 2021 · 2 comments · Fixed by #6

Comments

@cormacrelf
Copy link
Owner

At the moment, the binaries only work with Swift 5.4.2, specifically the one that comes with Xcode 12.5.1 (current stable Xcode):

Apple Swift version 5.4.2 (swiftlang-1205.0.28.2 clang-1205.0.19.57)

This is fine, as long as you use Xcode 12.5.1.

But if you attempt to link them with Swift code in the Xcode 13 beta, it errors out with:

... error: failed to build module 'CiteprocRsKit'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.4.2 (swiftlang-1205.0.28.2 clang-1205.0.19.57)', while this compiler is 'Apple Swift version 5.5 (swiftlang-1300.0.29.102 clang-1300.0.28.1)'). Please select a toolchain which matches the SDK.

@cormacrelf
Copy link
Owner Author

cormacrelf commented Aug 19, 2021

rI think this is basically it -- the usual (but unstable) way would be to use @_exported import CiteprocRs, but it appears this doesn't work with module stability. Module stability is the thing needed to get compiled code compiled with one version of swiftc to work on a later version.

It appears to be the same as this: there is actually a second error, No such module 'CiteprocRs', which occurs within the .swiftinterface file on the line @_exported import CiteprocRs.

For now I think this might be impossible, so I will just track Xcode stable and just make a new breaking release when Apple releases 13.0. One swiftc version at a time.

Edit: the root cause is that we can't use @_implementationOnly (which does work with module stability), because we need to re-export a few very-tedious-to-rewrite-in-Swift enums, e.g. CiteprocRs.CRErrorCode.

@cormacrelf
Copy link
Owner Author

I've figured this out, and can make this work with just SPM. The binary xcframework can be limited to just the Rust ffi library, if you build one manually with the correct lipo incantations and xcodebuild -create-xcframework. Then all the swift ABI/module stability issues simply disappear, as different swift compilers get access to the Swift source code.

I've also been testing it for usability and have some improvements to the JSON reference encoding part, I didn't realise Swift had Encodable/JSONEncoder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant