Why do I get the error Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 even though it's an ABI Stability?

Question: Question:

In the environment of Xcode 11.2.1, where it import Parchment

Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2

I got the error.

When I updated and built Xcode, I got the error Module compiled with Swift 5.0.1 cannot be imported by the Swift 5.1.2 compiler

Refer to the above page

$ carthage update --platform ios --cache-builds

Then, the compilation passed successfully.

Now that it's an ABI Stability , I don't understand why modules compiled with Swift 5.1 cannot be imported into Swift 5.1.2 .

why is it?

(The error came from the import Parchment part, but I'm guessing that this library was probably the first to be imported at compile time, and any library could have this error).

Answer: Answer:

This is because Module Stability is not enabled in the build settings for that library.

ABI Stability in Swift 5 is divided into two parts, one is ABI Stability and the other is Module Stability .

ABI Stability was made possible with Swift 5.0. This means that you can "link" binaries generated by different versions of the compiler.
This eliminates the need to bundle the Standard Library with each app.

Module Stability, on the other hand, was implemented in Swift 5.1. This means that you can "import" modules (≈ frameworks, libraries) generated by different versions of the compiler.

In order for Swift to make frameworks and libraries available (= import), "modules" are required, and until now, a file called *.swiftmodule was responsible for that.

To use an object or function from another library from the source code, you need to "import" it and call the function through a public API.
*.swiftmodule (= module) is what describes this public interface and makes it importable.
( *.swiftmodule file is a header file in C or Objective-C. As an equivalent of a module, when importing a C or Objective-C library into Swift, a modulemap file that can convert the header file to a module is used. , I will omit it because it is not related to this case.)

This *.swiftmodule file is (and still is not) compatible between the versions of the compiler it generated.
That's why Swift 5.1 adopted a text-based module description file called the *.swiftinterface file, which allows compatibility between compiler versions.

This means that in Swift 5.0, ABI Stability allows you to link libraries generated by different versions of the compiler, but you can't import them, so you can't effectively benefit from ABI Stability for third-party libraries .
(Because it fails at the import stage, it does not reach the link stage)

Together with Swift 5.1's Module Stability, you can finally use it in any library without worrying about the version of the compiler you built.

However, the *.swiftinterface required for Module Stability will not be generated unless each library builds with the settings enabled.
The flag BUILD_LIBRARY_FOR_DISTRIBUTION must be set to YES to output the *.swiftinterface interface.

Most libraries do not yet have that setting enabled, so a normal build with Carthage will not generate a *.swiftinterface file.

This is why modules compiled with Swift 5.1 cannot be imported with Swift 5.1.2.
(Since the Swift Standard Library was Swift 5.0, it has been possible to avoid embedding because Module Stability is enabled as a Private function for modules provided by Apple before we can use Module Stability. Because it was

reference:
https://swift.org/blog/abi-stability-and-more/
https://forums.swift.org/t/plan-for-module-stability/14551

Scroll to Top