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

Update compilation.md with automated script. #1150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ If you're creating a package that relies on a custom build of `better-sqlite3`,

If you're using a SQLite3 encryption extension that is a drop-in replacement for SQLite3 (such as [SEE](https://www.sqlite.org/see/doc/release/www/readme.wiki) or [sqleet](https://github.com/resilar/sqleet)), then simply replace `sqlite3.c` and `sqlite3.h` with the source files of your encryption extension.

### Automated example
Here's an automated script that will do all of this for you.

```sh
mkdir -p sqlite-amalgamation
cd sqlite-amalgamation

curl -O https://sqlite.com/2024/sqlite-amalgamation-3450100.zip
Copy link
Member

@mceachen mceachen Mar 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to write this PR!

Unfortunately, I suspect people will blindly copy and paste this in the future and not realize they're pulling in an out of date amalgamation (this library is popular, and people open spurious bugs continuously. I suspect this will be a new source.)

If you want to be fancy, you can do something like this, which would be evergreen.

  1. do the npm install better-sqlite3 first.
  2. then mkdir -p sqlite-amalgamation && cd sqlite-amalgamation
  3. then something like this:
source <(egrep "^(YEAR|VERSION)=" ../node_modules/better-sqlite3/deps/download.sh)
curl https://sqlite.org/$YEAR/sqlite-amalgamation-$VERSION.tar.gz | tar -xz --strip 1

To fetch and extract into your new dir.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for me!

unzip sqlite-amalgamation-3450100.zip
mv sqlite-amalgamation-3450100/* .

rm -rf sqlite-amalgamation-3450100.zip
rm -rf sqlite-amalgamation-3450100


# Enable whatever flags you want here.
LINE='#define SQLITE_ENABLE_RTREE 1'
sed -i '' "1s|^|$LINE\\n|" sqlite3.c

cd ..
npm install better-sqlite3 --no-save --build-from-source --sqlite3="$(pwd)/sqlite-amalgamation"
```

# Bundled configuration

By default, this distribution currently uses SQLite3 **version 3.45.1** with the following [compilation options](https://www.sqlite.org/compile.html):
Expand Down