Skip to content
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

Closed
janine-knowink opened this issue Nov 1, 2019 · 54 comments
Labels
help wanted Extra attention is needed support

Comments

@janine-knowink
Copy link

janine-knowink commented Nov 1, 2019

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

@groue
Copy link
Owner

groue commented Nov 4, 2019

Hello @janine-knowink,

Thanks for the report and the demo project. The solution is to remove CSQLite from the packages of your Xcode project.

@groue groue added the support label Nov 4, 2019
@groue groue closed this as completed Nov 4, 2019
@janine-knowink
Copy link
Author

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.

@groue
Copy link
Owner

groue commented Nov 4, 2019

Sorry if I was not clear

The attached demo projets starts successfully compile (both app target, and test target) after I have removed CSQLite from SPM packages.

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 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 Missing required module 'CSQLite' error means that something is still referring to CSQLite. But whatever is referring to CSQLite should stop:

  • GRDB 4.5.0 does not refer to CSQLite.
  • Your app may still refer to CSQLite (see my previous comment).
  • Some Xcode caches may also still refer to CSQLite: clean up everything, erase your Derived Data folder.

Make sure nothing at all refers to CSQLite, anywhere. This should remove your issue.

@janine-knowink
Copy link
Author

There must be something different between your setup and mine. I tried again to build my sample app:

I deleted derived data:

janine@casey DerivedData % ls -d GRDBTest*
GRDBTest-gbrvwpmiukkzeidfvbfvrdyztjly	GRDBTest-gcxqjzigycqhyzbevkrwyhbcvuoe
janine@casey DerivedData % rm -rf GRDBTest*
janine@casey DerivedData % !ls
ls -d GRDBTest*
zsh: no matches found: GRDBTest*

Checked for references to CSQLite:

janine@casey GRDBTest % cd ~/Desktop/GRDBTest
janine@casey GRDBTest % find . -type f -exec fgrep 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?

@groue groue reopened this Nov 5, 2019
@groue
Copy link
Owner

groue commented Nov 5, 2019

All right @janine-knowink, let's reopen the issue. GRDB used to depend on a CSQLite package, and this dependency has been removed in #627. I may have not done this properly: I'll check it.

Meanwhile, I suggest you downgrade GRDB to 4.4.0.

@groue
Copy link
Owner

groue commented Nov 5, 2019

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.

@janine-knowink
Copy link
Author

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.

@groue
Copy link
Owner

groue commented Nov 7, 2019

Good! Maybe Xcode 11.1 had a bug that was solved in Xcode 11.2? We'll never know. Thanks for telling.

@groue groue closed this as completed Nov 7, 2019
@groue
Copy link
Owner

groue commented Nov 7, 2019

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.

@ApplebaumIan
Copy link

ApplebaumIan commented Nov 27, 2019

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?

Screen Shot 2019-11-27 at 6 35 11 PM

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.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.
Build target ColorAssistantTests_2019-11-27T18-38-16.txt
Build target ColorAssistantUITests_2019-11-27T18-38-16.txt

@groue
Copy link
Owner

groue commented Nov 28, 2019

Hello @ApplebaumIan. I still can't reproduce this issue, so there's nothing I can do. Please re-read above comments. Thank you!

@ApplebaumIan
Copy link

ApplebaumIan commented Nov 30, 2019

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?

@groue
Copy link
Owner

groue commented Nov 30, 2019

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.

@simonbirt
Copy link

Weirdly this just started happening for me as well, after a minor unrelated change. What fixed it for me was removing the workspace file UserInterfaceState.xcuserstate (which was the only file I could find in the workspace that contained the string 'CSQLite') and restarting Xcode.

@groue
Copy link
Owner

groue commented Dec 2, 2019

Thank you for the tip, @simonbirt! @ApplebaumIan, @janine-knowink, does this trick resolve the problem for you too?

@rcasula
Copy link
Contributor

rcasula commented Jan 15, 2020

Hi @groue, I'm facing the same issue.
When using the library with SPM the target build fails. I've tried all of the above but nothing worked.

I'm trying with my personal project but also with GRDBDemoiOS installing GRDB with SPM. Same results.
The build fails in all GRDB files that import CSQLite (e.g. Core/Configuration.swift)

GRDB v4.8.1
Xcode 11.3.1

@groue
Copy link
Owner

groue commented Jan 15, 2020

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.

@rcasula
Copy link
Contributor

rcasula commented Jan 17, 2020

Hi @groue I've found a hint.
If you test a brand new project 'iOS App with Watch App' and you include the library in the Watch Extension you can get the error stated above.
I hope it would be of some help.

[Edit]
Here is a sample repo that shows the issue: https://github.com/robcas3/TestGRDB

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.

@groue
Copy link
Owner

groue commented Jan 19, 2020

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:

  1. Do file a bug on https://feedbackassistant.apple.com
  2. Use another installation technique (such as CocoaPods)

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.

@groue groue reopened this Jan 19, 2020
@groue groue added the help wanted Extra attention is needed label Jan 19, 2020
@groue groue changed the title "Missing required module 'CSQLite'" when building tests Xcode error "No such module 'CSQLite'" when embedding GRDB as a Swift package Jan 19, 2020
@haikusw
Copy link
Contributor

haikusw commented Feb 2, 2020

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:

All right @janine-knowink, let's reopen the issue. GRDB used to depend on a CSQLite package, and this dependency has been removed in #627. I may have not done this properly: I'll check it.

Meanwhile, I suggest you downgrade GRDB to 4.4.0.

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.

@groue
Copy link
Owner

groue commented May 28, 2020

Hello @shawnkoh. I am no longer able reproduce the issue. Will you please investigate and share a minimal setup which creates this error? Like a recipe. "Do this, then that, finally this, and witness the error." Thank you very much for your contribution.

@xplus2g4
Copy link

xplus2g4 commented May 28, 2020

@groue I am able to reproduce this bug, but it seems like a Xcode bug, here are the steps:

  1. Create a standalone swift package in your project
  2. Create MyLibrary and MyLibrary2 in the inner package
    a) Import GRDB in MyLibrary
    b) Import MyLibrary and GRDB in MyLibrary2
  3. In Package.swift of the standalone package:
    a) add the two libraries
    b) add GRDB to the dependencies
    c) Under targets, set GRDB as the dependencies to MyLibrary
    d) Do not set dependencies for MyLibrary2 (Ideally, MyLibrary should be set as the dependency)
  4. Build MyLibrary
  5. Build MyLibrary2
    -> Missing required module 'CSQLite'

@groue
Copy link
Owner

groue commented May 28, 2020

Thanks, @xplus2g4! Is it your setup, @shawnkoh?

@shawnkoh
Copy link

Yup @groue
Thanks for the really quick replies, we really appreciate your work! Its an incredibly well written library!

@groue
Copy link
Owner

groue commented May 28, 2020

Thanks @shawnkoh! But you know that this does not mean I have unlimited time and skills, don't you? I appreciate flattery as anybody else, but users who investigate such bugs and properly report them to Apple are even sweeter. THIS is your best option today, not waiting for me.

@ojkelly
Copy link

ojkelly commented Jul 1, 2020

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:
Removed your Derived Data folder.

@mhrakoto999
Copy link

Hello all,
I encountered the same issue when building UITests with both Xcode 12 and Xcode 12.2 beta.
I cleaned up DerivedData directory to no avail.

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

@mhrakoto999
Copy link

Additional info:
Main app and unit tests are built successfully

@mhrakoto999
Copy link

Hi all,

I didn't realize the case is closed as I was coming from a google search.
Last info:
I had retroverted to GRDB 4.14.0 and tried to build UITests again, it built well with Xcode 12.2 beta

@citelao
Copy link

citelao commented Jan 1, 2021

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 GRDB library when we finish compiling (I also added my other dependencies, since they are needed in my case):

Screenshot of xcodeproj config with 'Tests macOS' selected and GRDB, Telegraph, and Checksum all present under 'Link Binary with libraries'

Deleting DerivedData didn't work, but this did. Hope this helps someone, even if I'm a bit necro-ing a thread here.

@ataias
Copy link

ataias commented Mar 21, 2021

The fix from @citelao worked for me!

@weisunOW
Copy link

weisunOW commented Jun 29, 2021

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 none. I then had to manually link that local package against the failing test target.

I think it's the same problem described by @citelao, my test target was previously referencing CSQLite via the host application's linked libraries.

BTW I'm now getting linking against a dylib which is not safe for use in application extensions warning on that test target on linking stage. Looks like clearing DerivedData makes the warning go away.

@mhrakoto999
Copy link

mhrakoto999 commented Jul 19, 2021 via email

@DanielSincere
Copy link

DanielSincere commented Oct 14, 2022

I then had to manually link that local package against the failing test target.

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

targets:
  # ...
  ScreenshotTests:
      type: bundle.ui-testing
      platform: iOS
      dependencies:
        - target: ScreenshotApp
        - package: GRDB

@groue
Copy link
Owner

groue commented Nov 28, 2022

I could succesfully build an iOS test target with a host application that embeds the GRDB package, by adding the new CSQLite package product to the "Link Binary With Libraries" build phase of the test target. The new CSQLite package product is available from GRDB v6.4.0.

@joshzhao
Copy link

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.

@groue
Copy link
Owner

groue commented Nov 11, 2023

I had some success with exporting GRDB (@_exported import GRDB) from modules that depends on GRDB, as described in #1424. It may help in some situations.

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

rinat-enikeev added a commit to ruuvi/com.ruuvi.station.ios that referenced this issue Nov 24, 2023
* 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
@dfeinzimer
Copy link

Still an issue as of Xcode 15.0.

I'm not sure this is a problem with GRDB, but rather a problem with SPM or Xcode

Indeed and this is not a solution but rather an anecdotal observation:
I'm using a package that has GRDB as one of its dependencies. If I use the package through SPM then I get the error but if I download the package and use it locally then I don't get it.

@sky-victortavernari
Copy link

I am also getting the same scenario as @dfeinzimer

@kellyhuberty
Copy link

@groue upon looking at GRDB/Export.swift I noticed there is a line that imports CSQLite. That seems unnecessary if you no longer use it, but I'm afraid I don't know enough about the internals to know what exactly that does?

image

@groue
Copy link
Owner

groue commented Feb 11, 2024

@groue upon looking at GRDB/Export.swift I noticed there is a line that imports CSQLite. That seems unnecessary if you no longer use it, but I'm afraid I don't know enough about the internals to know what exactly that does?

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 👍

@colbyn
Copy link

colbyn commented Feb 20, 2024

I removed GRDB-dynamic from being linked after compiling from the project and now the Swift package/library has no such error.

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.

@DigitalSolomon
Copy link

@dfeinzimer @colbyn Did deleting DerivedData help? That seemed to have done it for me (knocks on wood)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed support
Projects
None yet
Development

No branches or pull requests