rockbruno / SwiftInfo

📊 Extract and analyze the evolution of an iOS app's code.
https://swiftrocks.com
MIT License
1.15k stars 58 forks source link

Enable Module Stability #68

Open rockbruno opened 3 years ago

rockbruno commented 3 years ago

https://twitter.com/rockbruno_/status/1375472185943470082

We can now enable module stability so new versions don't need to be built.

andre-alves commented 3 years ago

I tried some things but couldn't make it work...

    @swift build \
        -c release \
        --disable-sandbox \
        --build-path "$(BUILDDIR)" \
        -Xswiftc \
        -emit-module-interface \
        -Xswiftc \
        -enable-library-evolution \
        -Xswiftc \
        -swift-version \
        -Xswiftc 5

Note: I had to force -swift-version, otherwise it prints a warning:

<unknown>:0: warning: module interfaces are only supported with Swift language version 5 or later (currently using -swift-version 4.2)

(probably because PathKit dependency is still using // swift-tools-version:4.2)

Then, I moved the generated .swiftinterface files inside swiftinfo/include and changed my Xcode version with xcode-select but got other errors:

./Infofile.swift:1:8: error: failed to build module 'SwiftInfoCore' from its module interface; the compiler that produced it, 'Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)', may have used features that aren't supported by this compiler, 'Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)'
import SwiftInfoCore
rockbruno commented 3 years ago

In the project where I used this (and it worked) I used -Xswiftc \"-emit-module-interface\" -Xswiftc \"-emit-module\" -Xswiftc \"-enable-library-evolution\"", maybe the emit-module makes the difference?

andre-alves commented 3 years ago

After more digging, I did manage to enable module stability successfuly and tested the same binary with Swift 5.3.2 and Swift 5.4.

Unfortunately, it was not clean. Here are the changes: https://github.com/rockbruno/SwiftInfo/compare/master...andre-alves:module-stability

  1. I added flags -emit-module-interface and -enable-library-evolution. Didn't need to include -emit-module;
  2. Also had to force -swift-version 5 because PathKit dependency is using Swift 4.2;
  3. Move *.swiftinterface files inside the package;
  4. Remove *.swiftmodules, otherwise, I would still get this error:
    ./Infofile.swift:1:8: error: failed to build module 'SwiftInfoCore' from its module interface; the compiler that produced it, 'Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)', may have used features that aren't supported by this compiler, 'Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)'
    import SwiftInfoCore
  5. Edited XcodeProj.swiftinterface, removing XcodeProj. module references because there is a bug when a type has the same name as its module: https://forums.swift.org/t/frameworkname-is-not-a-member-type-of-frameworkname-errors-inside-swiftinterface/28962

It works but it's hacky. What do you think?

rockbruno commented 3 years ago

Holy crap, the XcodeProj one is unfortunate. My fear with that one is that they'll change something in Swift and we'll end up with broken interfaces. I think we can ask them to change the name of the library, I can do that. The other workarounds are fine, we aren't supposed to ship all the files (I started doing that because I thought it would fix the stability once)

rowwingman commented 2 years ago

@rockbruno do you have any plans on renaming the library or main swift file? Btw I install the 2.6 with brew, and it is still has an error: module map file '/usr/local/bin/../include/swiftinfo/Csourcekitd/include/module.modulemap' not found ./Infofile.swift:2:8: error: no such module 'SwiftInfoCore' import SwiftInfoCore ^

Any ideas? Do you have the same with pods?