-
-
Notifications
You must be signed in to change notification settings - Fork 727
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
Xcode error "No such module 'CSQLite'" when embedding GRDB as a Swift package #642
Comments
Hello @janine-knowink, Thanks for the report and the demo project. The solution is to remove CSQLite from the packages of your Xcode project. |
Sorry if I was not clear - the problem happens without CSQLite installed. I had installed it only to see if it would help, but it did not. My co-worker worked around the problem by adding GRDB to the "Link Binary With Libraries" build rule for our test target, but it seems like that should not be required? GRDB isn't even used in any of the tests, it's only coming in via the testable import of the main project. And I haven't needed to add any of the packages which are used in the tests, so this seems wrong to me. |
The attached demo projets starts successfully compile (both app target, and test target) after I have removed CSQLite from SPM packages.
GRDB has to be linked to the target(s) that uses it. That is normal. Now I don't know if you talk about your application or test target. It your tests needs some objects that need GRDB indirectly, then yes your tests need GRDB. But let's focus: the
Make sure nothing at all refers to CSQLite, anywhere. This should remove your issue. |
There must be something different between your setup and mine. I tried again to build my sample app: I deleted derived data:
Checked for references to CSQLite:
Also verified that it's not being included by the package manager. Closed the app window in Xcode and reopened it so that the package manager would check out GRDB again, and then built. Building the app works, but building the tests still fails with "Missing required module 'CSQLite'". In order to get the tests to build, I have to comment out the setup function, which uses GRDB, the import of GRDB, and the testable import of the main app. In our real app, this happens even though GRDB is not used at all in the tests. We get the error about CSQLite simply from the testable import of the main app, where it is used, and the only way to get rid of it is to manually link GRDB for the tests. I am using Xcode 11.1 and macOS 10.15.1. Are you using something different? |
All right @janine-knowink, let's reopen the issue. GRDB used to depend on a Meanwhile, I suggest you downgrade GRDB to 4.4.0. |
After further investigation, I still can not reproduce your issue. I'll keep this open a few days, in order to let you exhibit a way to reproduce the "Missing required module 'CSQLite'" error. For example, make your demo project fail with this error. Meanwhile, I personally stop doing any investigation. |
The issue seems to exist only in Xcode 11.1. Using 11.2 the tests build and run fine. I have no idea why it's different, but that is what I am seeing. |
Good! Maybe Xcode 11.1 had a bug that was solved in Xcode 11.2? We'll never know. Thanks for telling. |
For the record, this conversation may contain interesting hints, provided we are able to reproduce the "Missing required module 'CSQLite'" error. Left as an exercice for the unfortunate. |
I'm now receiving this bug as well on Xcode Version 11.2.1 (11B500) using the SPM. What did you expect to happen?If the main project builds ok, the tests should also. Tests break on the server during integration testing and on local Mac What happened instead?EnvironmentGRDB flavor(s): (GRDB, SQLCipher, Custom SQLite build?) Just GRDB GRDB version:4.5.0 "up to next major" Installation method: (CocoaPods, SPM, manual?)SPM Xcode version:11.2.1 Swift version:5 Platform(s) running GRDB: (iOS, macOS, watchOS?)iOS macOS version running Xcode:10.14.5 The build only fails for testing. |
Hello @ApplebaumIan. I still can't reproduce this issue, so there's nothing I can do. Please re-read above comments. Thank you! |
Would it help If I zipped my repository and sent it to you? It only fails when you try to run tests. Or at least left it as an example? |
If you can not investigate and understand the cause of your issue, then yes, asking for help is more efficient if you can provide a reproducible case that other people can inspect. Without any reproducible case, people just don't know what you are talking about, and can't help. So, first try to investigate yourself, read, learn about Swift packages and Xcode, search Google, try hard on your own time. Only when you think you are stuck and really need the time of somebody else, ask for help, and make it easier for people who will help with a reproducible case. |
Weirdly this just started happening for me as well, after a minor unrelated change. What fixed it for me was removing the workspace file |
Thank you for the tip, @simonbirt! @ApplebaumIan, @janine-knowink, does this trick resolve the problem for you too? |
Hi @groue, I'm facing the same issue. I'm trying with my personal project but also with GRDBDemoiOS installing GRDB with SPM. Same results. GRDB v4.8.1 |
Hi @robcas3. Until there is a way to reproduce this issue, nobody will be able to help. This has been said several times above already. |
Hi @groue I've found a hint. [Edit] I've tested with 4.9.0, 4.8.1, 4.5.0, 4.4.0 and it does not work with either of these versions. It seems like the modulemap, when built with watchOS target, cannot be found. |
Thank you @robcas3, I could finally reproduce the error from your sample repo 👍 The error happens with the watch extension target. I could successfully create and run UI and Unit testing targets that use GRDB. This is an Xcode bug, not a GRDB bug. Now, things being what they are, it would be nice to have a workaround. I could not find any. I have tried to downgrade to GRDB 4.4.0, at a time when CSQLite was still an independent repo (before #627), so that I could add https://github.com/groue/CSQLite as an explicit dependency to the Xcode project. Alas! This does not make it possible to explicitly link it to the watch extension target. For the record, the CSQLite SPM target is needed for a single GRDB feature: the global error log. My current suggestion is:
For my part, I'll keep this issue open, just in case someone would have a brilliant idea that would restore support for SPM in multi-targets Xcode projects. And I'll add a warning in the SPM section of the documentation. |
I know nothing about this project (but plan to start using it this month). I was looking through the open issues to see how stable/good it is and found this open issue. This doesn't look like an Xcode bug to me. I downloaded the test repo https://github.com/robcas3/TestGRDB and built it with Xcode 11.3 on macOS 10.15.2 This comment seems to indicate that there should be no further dependency on CSQLite:
However the error in Xcode I get is in the file GRDB/CORE/Configuration.swift which clearly has still an import for CSQLite on line 4. This import is conditional on SWIFT_PACKAGE (so only occurs if you import GRDB via the package manager I guess?). Actually, there are a ton of references to CSQLite in the repo on the master branch, so maybe I'm misunderstanding this thread? Apologies if so. https://github.com/groue/GRDB.swift/search?q=CSQLite&unscoped_q=CSQLite It seems like the Package.swift file needs to list CSQLite as a dependency given these conditional import statements. |
I just had this issue with Xcode 12 beta. Honestly it's impossible to pin down, but a few interesting things. It happened on a Multiplatform App (new project template in xcode12), in a project that's already had a bit of work, many builds and some other SPM packages. A brand new multiplatform app it worked. So I cleaned everything up, build folder, that didn't work. What did work: |
Hello all, I inspected the ModuleCache.noindex directory under the DerivedData and noticed that 2 files CSQliteXXX.pcm and CSQliteXXX.pcm.timestamp are generated (along with files named after Apple-related frameworks such as SwiftUI, CoreAudio and so on) each time Xcode builds the main app. Hope it will help |
Additional info: |
Hi all, I didn't realize the case is closed as I was coming from a google search. |
I found this thread via Google search when trying to set up unit tests that referenced my app. Since UI tests (the built-in tests in the Multiplatform template) simply launch the app, they don't need references to GRDB etc. However, as soon as I tried to import my app I started getting this error (missing CSQLite). All-in-all, the fix was to ensure we link the Deleting DerivedData didn't work, but this did. Hope this helps someone, even if I'm a bit necro-ing a thread here. |
The fix from @citelao worked for me! |
I had the same issue on Xcode 12.5.1 in unit test target. In my case, GRDB is imported in a local Swift package. Test target builds fine until I set the test target's host application to I think it's the same problem described by @citelao, my test target was previously referencing
|
Hi,
I met the issue when building UI tests. The workaround was to link the useful packages to the target one by one.
I think this is still relevant on 5.x versions.
Hope it helps
… On Jul 19, 2021, at 12:41 PM, Shai Mishali ***@***.***> wrote:
Sorry for the bump, but seems like this is still an issue. Is there no workaround for this as of now?
Read this thread but most comments here related to 4.x.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@weisunOW's suggestion is what fixed it for me. I had to add GRDB as a dependency of my UI Test target. It feels awkward because my UI Tests do not access GRDB or SQLite. My XcodeGen snippet:
|
I could succesfully build an iOS test target with a host application that embeds the GRDB package, by adding the new |
I am still seeing this issue with the latest GRDB 6.21.0 under Xcode 15.0.1 in building for regular iOS 17 target, not a test version. I had to resort to set up a manual link to CSQLite as suggested by others in this forum. Just adding a data point for this issue. |
I had some success with exporting GRDB ( Anyway, I'm not sure this is a problem with GRDB, but rather a problem with SPM or Xcode: I recommend filing feedbacks on http://feedbackassistant.apple.com |
Makes all frameworks, except depending on GRDB, mergable. See https://developer.apple.com/documentation/xcode/configuring-your-project-to-use-mergeable-libraries#Manually-configure-merging. @see: groue/GRDB.swift#642
* Make mergable frameworks to increase launch time Makes all frameworks, except depending on GRDB, mergable. See https://developer.apple.com/documentation/xcode/configuring-your-project-to-use-mergeable-libraries#Manually-configure-merging. @see: groue/GRDB.swift#642 * make MERGEABLE_LIBRARY: true
Still an issue as of Xcode 15.0.
Indeed and this is not a solution but rather an anecdotal observation: |
I am also getting the same scenario as @dfeinzimer |
@groue upon looking at |
Those exports expose the SQLite symbols to the code that import GRDB. I remember a time, before I added those exports, where it uneasy to access them. It looked like a good idea, and it has worked well for a great deal of applications. Today, it looks like the inconvenience of Xcode/SPM have surpassed the convenience of those exports! I'll take the opportunity of the next major release, GRDB 7, to remove those exports. Thanks @kellyhuberty for spotting this just as I was planning the TODO-list for that next release 👍 |
I removed Update: actually I spoke too soon. Personally I feel like, since GRDB is the only library with this sort of issue, this isn’t an Xcode problem it’s a GRDB library problem. |
@dfeinzimer @colbyn Did deleting |
When adding the package through Project Settings -> Package Dependencies -> ’+’ and selecting GRDB or GRDB-dynamic, everything works fine. However, when adding the package directly in Package.swift, it fails with the following error: After some troubleshooting, it appears this issue may be related to a naming bug within Xcode’s Swift Package Manager (SPM). I resolved it by modifying the Package.swift file within the GRDB.swift repository, changing “GRDB” to “GRDB.swift.” This adjustment allowed the package to be recognized correctly. Repository link: https://github.com/shawn7com/GRDB.swift.git |
Posting this in case it helps others facing the same or a similar issue. In my project setup I was linking against GRDB as an implementation detail of a framework target that's accessed by other framework targets and my main app target. This framework target is used by both an iOS app and a Mac app target, and my Mac app was building just fine, but I was seeing the "missing required module..." error when trying to build the iOS app. The difference between my Mac target that worked and the iOS target that didn't was that the Mac app target explicitly linked against all framework dependencies in Xcode's "Link Binary With Libraries" build phase. Meanwhile, the iOS app target didn't. Adding all framework targets used by the iOS app, including the one that accesses GRDB, into the "Link Binary With Libraries" build phase for the app target resolved the issue. |
I set up a dependency chain where my main target linked to static framework B, which in turn linked to static framework A, which used GRDB. During builds, framework B kept failing with a "missing required module" error. Turns out, static frameworks don’t handle transitive dependencies well. Making framework A dynamic fixed the build for framework B, but then my main target started showing the same error. The solution was to make both frameworks dynamic. After that, everything worked perfectly. Dynamic frameworks handle module visibility and transitive dependencies better, so converting to dynamic frameworks did the trick. |
Here's a simple fix I found for GRDB dependency issues: If you only need GRDB inside your framework (and don't want other targets using it), add @_implementationOnly before each GRDB import, like this: @_implementationOnly import GRDB This tells Swift to hide GRDB from any targets that depend on your framework. It fixes the "missing required module" error.
|
Assuming you are using Swift 6, you can use SE-409 to replace uses of In the future, internal imports will become the default, which you can also opt into early with the |
What did you do?
Added GRDB to my iOS app via the Swift package manager and added one "import GRDB" (nothing else). The project builds fine, but the tests fail to link with the error "Missing required module 'CSQLite'" on every file which includes "@testable import "
I made a demo project where I just added GRDB and imported it into ContentView.swift. This exhibited the problem. I then found and installed the CSQLite package and imported that also into ContentView.swift, but the problem remains.
What did you expect to happen?
If the main project builds ok, the tests should also.
What happened instead?
Described above.
Environment
GRDB flavor(s): (GRDB, SQLCipher, Custom SQLite build?)
Just GRDB
GRDB version:
4.5.0 "up to next major"
Installation method: (CocoaPods, SPM, manual?)
SPM
Xcode version:
11.1
Swift version:
5
Platform(s) running GRDB: (iOS, macOS, watchOS?)
iOS
macOS version running Xcode:
10.15.1
Demo Project
GRDBTest.zip
The text was updated successfully, but these errors were encountered: