SwiftInfo icon indicating copy to clipboard operation
SwiftInfo copied to clipboard

Enable Module Stability

Open rockbruno opened this issue 3 years ago • 5 comments

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

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

rockbruno avatar Mar 26 '21 15:03 rockbruno

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

andre-alves avatar May 05 '21 20:05 andre-alves

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?

rockbruno avatar May 06 '21 06:05 rockbruno

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
  1. 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?

andre-alves avatar May 06 '21 15:05 andre-alves

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)

rockbruno avatar May 06 '21 18:05 rockbruno

@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?

rowwingman avatar Jan 12 '22 19:01 rowwingman