RxSwift: Test target does not build when RxCocoa Swift Package is used
Short description of the issue:
When RxCocoa is used in a project in Xcode 11, and it is imported as RxSwift package, unit tests for that project do not build, with following error:
missing required module 'RxCocoaRuntime'
I am not an expert on Swift Packages, just starting with it. I see RxCocoaRuntime is declared as a target in Package.swift, and RxCocoa depends on it. But it is not declared as a product. This may be also Xcode’s issue. But I don’t have issues with other dependencies.
Expected outcome:
Tests build and are executed.
What actually happens:
Build fails.
Self contained code example that reproduces the issue:
Sample, minimal project: https://github.com/michallaskowski/RxCocoaTestsIssue
RxSwift/RxCocoa/RxBlocking/RxTest version/commit
Current master, commit 6b2a406
Platform/Environment
- iOS
- macOS
- tvOS
- watchOS
- playgrounds
How easy is to reproduce? (chances of successful reproduce after running the self contained code)
- easy, 100% repro
- sometimes, 10%-100%
- hard, 2% - 10%
- extremely hard, %0 - 2%
Xcode version:
Xcode 11 beta 7, tested also with beta 6
⚠️ Fields below are optional for general issues or in case those questions aren’t related to your issue, but filling them out will increase the chances of getting your issue resolved. ⚠️
Installation method:
- CocoaPods
- Carthage
- Git submodules
other - Swift Packages 😃
I have multiple versions of Xcode installed: (so we can know if this is a potential cause of your issue)
- yes (Xcode 10.1, Xcode 10.2.1)
- no
Level of RxSwift knowledge: (this is so we can understand your level of knowledge and formulate the response in an appropriate manner)
- just starting
- I have a small code base
- I have a significant code base
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 30
- Comments: 44 (11 by maintainers)
I have found out that it is a known issue with rdar://problem/54587458.
Work around is to add flag to explicitly append modulemap to the
OTHER_SWIFT_FLAGS
in the test target:I’m not sure if it’s the same case for everyone. But in my case, when I add “RxCocoa” to “Link Binary with Libraries” in the test target’s Build Phase tab, it successfully built.
@yusuke024
I’m here from google, tried to resolve another, but a similar bug. When I use Swift Package Manager and set “Host Application” to None for test target’s settings, test target stops building with linking issues of SPM’s dependencies. So I need to explicitly add those dependencies to test target’s both Dependencies and Link Binary With Libraries sections in Build Phases tab. Thanks for suggestion!
Not working for me in Xcode 11.3.1 (that is, I cannot run tests, get the
EXC_BAD_ACCESS
error, when test target includes RxBlocking)Hey Gal 👋 There was a suggestion here but I haven’t tested it personally. I’ve been hopeful Apple will fix up their mess but this doesn’t seem to be the case.
https://github.com/ReactiveX/RxSwift/issues/2127#issuecomment-717830502
I tested the changes, thanks for the info. While the tests build now, they are crashing on Xcodes 11.0, 11.1 GM, and 11.2 beta. On Xcode 11.1,
swift_checkMetadataState
throws EXC_BAD_ACCESS. May be still an issue with Swift Packages, not RxSwift itself.Sample project updated: https://github.com/michallaskowski/RxCocoaTestsIssue
Depending on what you are building for (simulator, device, archive build) the modulemap path will reference the
iphoneos
platform and notiphonesimulator
. Below is the flag I am using so the path is referencing the current platform:-fmodule-map-file=$(PROJECT_TEMP_ROOT)/GeneratedModuleMaps-$(PLATFORM_NAME)/RxCocoaRuntime.modulemap
I think this is causing my test crashes in Xcode 11.3.1 as well,
EXC_BAD_ACCESS
andSIGABRT
due tofatalError
.XXX.app (51242) encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted. (Underlying error: Crash: XXX (51242): type metadata completion function for CombineLatestSink2_))
Also, lots of console messages like:
…which I suspect is the problem: RxSwift is static in both the test and the app.
Well, yes. Removing RxTest and RxBlocking from test target stops the crash. But also doesn’t solve anything, if I want to test reactive parts of code. Unless you mean something else in this case, @FabianTerhorst ?
RxTest and RxBlocking both depend on RxSwift target, which is linked in the host application. Because of that, test target seems to also link RxSwift. Potential fix is linking RxTest and RxBlocking to the host application, but well, it is not a great solution.
@freak4pc I found it in swift-nio library. Issue-1228