Why Use a Custom Build?
A custom SQLite build enables:- FTS5 full-text search (on platforms where it’s not available by default)
- Pre-update hooks for advanced transaction observation
- SQLite extensions not enabled in the system version
- Newer SQLite features before they ship in the OS
- Performance optimizations through compiler flags
GRDB builds SQLite using swiftlyfalling/SQLiteLib, which uses the same configuration as Apple’s SQLite builds.
Installation Steps
1. Clone and Checkout GRDB
Clone the GRDB repository and checkout the latest version:2. Choose Compilation Options
Select the SQLite compilation options you need. Common options include:SQLITE_ENABLE_FTS5- Full-text searchSQLITE_ENABLE_PREUPDATE_HOOK- Pre-update hooksSQLITE_ENABLE_SNAPSHOT- Snapshot support (recommended)SQLITE_ENABLE_RTREE- R*Tree indexSQLITE_ENABLE_JSON1- JSON functions
3. Create GRDBCustomSQLite Folder
Create a folder namedGRDBCustomSQLite somewhere in your project directory:
4. Create Configuration Files
Create four files in theGRDBCustomSQLite folder:
SQLiteLib-USER.xcconfig
Sets extra SQLite compilation flags:GRDBCustomSQLite-USER.xcconfig
Lets GRDB know about extra compilation flags:GRDBCustomSQLite-USER.h
Lets your application know about extra compilation flags:GRDBCustomSQLite-INSTALL.sh
Installs the three configuration files:5. Embed GRDBCustom Project
Embed theGRDBCustom.xcodeproj project in your own project.
6. Add Target Dependencies
Add theGRDBCustom target in the Target Dependencies section of the Build Phases tab of your application target.
7. Embed the Framework
AddGRDBCustom.framework from the targeted platform to the Embedded Binaries section of the General tab of your application target.
8. Add Build Pre-Action
Add a Run Script phase in the Pre-actions section of the Build tab of your application scheme:GRDBCustomSQLite-INSTALL.sh file.
Select your application target in the “Provide build settings from” menu.
9. Share Your Scheme
Check the Shared checkbox of your application scheme. This allows you to commit the pre-action in your version control system.10. Configure Hardened Runtime (if needed)
If you have enabled “Hardened Runtime” for your target:- Go to the Signing & Capabilities tab
- Under Hardened Runtime, check Disable Library Validation
Using Your Custom Build
Once configured, use GRDB normally:Verifying Enabled Features
Check which features are enabled:Common Compilation Options
Full-Text Search
Pre-Update Hooks
Snapshot Support
DatabasePool performance optimization.
R*Tree Index
Multiple Options
Combine multiple options:Troubleshooting
Build Errors with SPM Libraries
Custom SQLite builds are incompatible with Swift Package Manager. If you use GRDBQuery or other SPM libraries:- Consider using the system SQLite instead
- Or avoid SPM dependencies that require GRDB
”Library not loaded” Error
If you see “Library not loaded … different Team IDs”:- Enable “Hardened Runtime” settings
- Check “Disable Library Validation”
Pre-Action Script Not Running
If the install script doesn’t run:- Verify the script path is correct
- Make sure you selected your target in “Provide build settings from”
- Check that your scheme is marked as “Shared”
Wrong SQLite Version
If you’re still using the system SQLite:- Verify you’re linking
GRDBCustom.framework, notGRDB.framework - Clean your build folder (Product > Clean Build Folder)
- Check that the pre-action script ran successfully
Best Practices
- Document your options - Keep a list of enabled SQLite features
- Test thoroughly - Custom builds may behave differently
- Update carefully - New GRDB versions may change requirements
- Share your scheme - Let team members use the same configuration
- Enable SQLITE_ENABLE_SNAPSHOT - Improves DatabasePool performance
- Verify at runtime - Check that expected features are available
See Also
- Full-Text Search - Using FTS5
- Encryption - SQLCipher integration
- Transaction Observers - Pre-update hooks