Skip to content

Instantly share code, notes, and snippets.

@fractaledmind
Created September 10, 2023 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fractaledmind/6e70b23ecbd150751f6513e1b9839572 to your computer and use it in GitHub Desktop.
Save fractaledmind/6e70b23ecbd150751f6513e1b9839572 to your computer and use it in GitHub Desktop.
A script to install and compile a custom SQLite installation
#!/usr/bin/env sh
cd ../vendor
mkdir -p sqlite/bin sqlite/lib sqlite/include
# ============================================================================================================
# Compile and install sqlite3 (for performance turning and build customizations)
# SEE: https://www.sqlite.org/compile.html
# NOTE: The sqlite3 Ruby gem will not work with the following compile time flags
# * -DSQLITE_OMIT_DEPRECATED
# ============================================================================================================
curl --remote-name --remote-header-name https://www.sqlite.org/2023/sqlite-amalgamation-3430000.zip && unzip sqlite-amalgamation-3430000.zip
cd sqlite-amalgamation-3430000
PREPROCESSOR_FLAGS=(
-D SQLITE_DEFAULT_MEMSTATUS=0
-D SQLITE_DEFAULT_PAGE_SIZE=16384
-D SQLITE_DEFAULT_WAL_SYNCHRONOUS=1
-D SQLITE_DQS=0
-D SQLITE_ENABLE_FTS5
-D SQLITE_LIKE_DOESNT_MATCH_BLOBS
-D SQLITE_MAX_EXPR_DEPTH=0
-D SQLITE_OMIT_DECLTYPE
-D SQLITE_OMIT_PROGRESS_CALLBACK
-D SQLITE_OMIT_SHARED_CACHE
-D SQLITE_THREADSAFE=0
-D SQLITE_USE_ALLOCA
)
# compile the executable
gcc "${PREPROCESSOR_FLAGS[@]}" shell.c sqlite3.c -lpthread -ldl -lm -o ../sqlite/bin/sqlite3
# compile and setup shared library
gcc "${PREPROCESSOR_FLAGS[@]}" shell.c sqlite3.c -lpthread -ldl -lm -fPIC -shared -o ../sqlite/lib/libsqlite3.so && \
chmod 755 ../sqlite/lib/libsqlite3.so && \
ln -s ../sqlite/lib/libsqlite3.so ../sqlite/lib/libsqlite3.so.0
# copy header/include files
cp sqlite3.h ../sqlite/include/ && \
cp sqlite3ext.h ../sqlite/include/
# cleanup
PREPROCESSOR_FLAGS=""
# configure bundler to be aware of the custom sqlite3 installation
BUILD_SQLITE3="true"
bundle config set build.sqlite3 --enable-system-libraries --with-opt-dir=./vendor/sqlite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment