├── .github └── workflows │ ├── build.yml │ └── lint.yml ├── .gitignore ├── .tool-versions ├── LICENSE ├── README.md ├── bin ├── download ├── install ├── list-all └── utils.sh └── scripts ├── shellcheck.bash └── shfmt.bash /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | jobs: 10 | plugin_test: 11 | name: asdf plugin test 12 | strategy: 13 | matrix: 14 | os: 15 | - ubuntu-latest 16 | - macos-latest 17 | runs-on: ${{ matrix.os }} 18 | steps: 19 | - name: asdf_plugin_test 20 | uses: asdf-vm/actions/plugin-test@v2 21 | with: 22 | command: sqlite3 --version 23 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | jobs: 10 | shellcheck: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout code 14 | uses: actions/checkout@v2 15 | 16 | - name: Install asdf dependencies 17 | uses: asdf-vm/actions/install@v1 18 | 19 | - name: Run ShellCheck 20 | run: scripts/shellcheck.bash 21 | 22 | shellfmt: 23 | runs-on: ubuntu-latest 24 | steps: 25 | - name: Checkout code 26 | uses: actions/checkout@v2 27 | 28 | - name: Install asdf dependencies 29 | uses: asdf-vm/actions/install@v1 30 | 31 | - name: List file to shfmt 32 | run: shfmt -f . 33 | 34 | - name: Run shfmt 35 | run: scripts/shfmt.bash 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 2 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 3 | 4 | # User-specific stuff 5 | .idea/**/workspace.xml 6 | .idea/**/tasks.xml 7 | .idea/**/usage.statistics.xml 8 | .idea/**/dictionaries 9 | .idea/**/shelf 10 | 11 | # Generated files 12 | .idea/**/contentModel.xml 13 | 14 | # Sensitive or high-churn files 15 | .idea/**/dataSources/ 16 | .idea/**/dataSources.ids 17 | .idea/**/dataSources.local.xml 18 | .idea/**/sqlDataSources.xml 19 | .idea/**/dynamic.xml 20 | .idea/**/uiDesigner.xml 21 | .idea/**/dbnavigator.xml 22 | 23 | # Gradle 24 | .idea/**/gradle.xml 25 | .idea/**/libraries 26 | 27 | # Gradle and Maven with auto-import 28 | # When using Gradle or Maven with auto-import, you should exclude module files, 29 | # since they will be recreated, and may cause churn. Uncomment if using 30 | # auto-import. 31 | # .idea/modules.xml 32 | # .idea/*.iml 33 | # .idea/modules 34 | 35 | # CMake 36 | cmake-build-*/ 37 | 38 | # Mongo Explorer plugin 39 | .idea/**/mongoSettings.xml 40 | 41 | # File-based project format 42 | *.iws 43 | 44 | # IntelliJ 45 | out/ 46 | 47 | # mpeltonen/sbt-idea plugin 48 | .idea_modules/ 49 | 50 | # JIRA plugin 51 | atlassian-ide-plugin.xml 52 | 53 | # Cursive Clojure plugin 54 | .idea/replstate.xml 55 | 56 | # Crashlytics plugin (for Android Studio and IntelliJ) 57 | com_crashlytics_export_strings.xml 58 | crashlytics.properties 59 | crashlytics-build.properties 60 | fabric.properties 61 | 62 | # Editor-based Rest Client 63 | .idea/httpRequests 64 | 65 | # Android studio 3.1+ serialized cache file 66 | .idea/caches/build_file_checksums.ser 67 | 68 | # Prerequisites 69 | *.d 70 | 71 | # Object files 72 | *.o 73 | *.ko 74 | *.obj 75 | *.elf 76 | 77 | # Linker output 78 | *.ilk 79 | *.map 80 | *.exp 81 | 82 | # Precompiled Headers 83 | *.gch 84 | *.pch 85 | 86 | # Libraries 87 | *.lib 88 | *.a 89 | *.la 90 | *.lo 91 | 92 | # Shared objects (inc. Windows DLLs) 93 | *.dll 94 | *.so 95 | *.so.* 96 | *.dylib 97 | 98 | # Executables 99 | *.exe 100 | *.out 101 | *.app 102 | *.i*86 103 | *.x86_64 104 | *.hex 105 | 106 | # Debug files 107 | *.dSYM/ 108 | *.su 109 | *.idb 110 | *.pdb 111 | 112 | # Kernel Module Compile Results 113 | *.mod* 114 | *.cmd 115 | .tmp_versions/ 116 | modules.order 117 | Module.symvers 118 | Mkfile.old 119 | dkms.conf 120 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | shellcheck 0.7.1 2 | shfmt 3.3.0 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # asdf-sqlite 2 | 3 | [![Build Status](https://github.com/cLupus/asdf-sqlite/actions/workflows/build.yml/badge.svg)](https://github.com/cLupus/asdf-sqlite/actions/workflows/build.yml) [![Lint](https://github.com/cLupus/asdf-sqlite/actions/workflows/lint.yml/badge.svg)](https://github.com/cLupus/asdf-sqlite/actions/workflows/lint.yml) 4 | 5 | [SQLite](https://www.sqlite.org) plugin for [asdf](https://github.com/asdf-vm/asdf) version manager 6 | 7 | 8 | ## Requirements 9 | 10 | It uses curl, C compiler & dev tools and file. In Ubuntu or similar Debian systems: 11 | ```bash 12 | apt install curl build-essential file 13 | ``` 14 | 15 | In Dockerfile: 16 | ```dockerfile 17 | RUN DEBIAN_FRONTEND=noninteractive apt install -y curl build-essential file 18 | ``` 19 | 20 | ## Install 21 | 22 | Install the plugin: 23 | 24 | ```bash 25 | asdf plugin-add sqlite 26 | ``` 27 | 28 | ### Compilation options 29 | 30 | By default, SQLite will be compiled with most of [the recommended compile-time options](https://sqlite.org/compile.html#recommended_compile_time_options) are enabled. 31 | Additionally, multiple [optional features](https://sqlite.org/compile.html#_options_to_enable_features_normally_turned_off) are enabled to amke SQLite mure useful. 32 | 33 | If you would like to override the compile options, you may set the environment variable `ASDF_SQLITE_ENABLED_FEATURES` as desired. 34 | 35 | ## Use 36 | 37 | Check [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install & manage versions of SQLite. 38 | -------------------------------------------------------------------------------- /bin/download: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | # shellcheck source=bin/utils.sh 5 | source "$(dirname "$0")/utils.sh" 6 | 7 | _add_padding() { 8 | if [[ ${#1} == '1' ]]; then 9 | printf '%d%02d' "$1" "" 10 | fi 11 | if [[ ${#1} == '2' ]]; then 12 | printf '%d%01d' "$1" "" 13 | fi 14 | } 15 | 16 | get_release_year() { 17 | local version=$1 18 | get_sqlite_url "releaselog/$(echo "$version" | tr '.' '_').html" | 19 | grep ".*" | 20 | sed -E 's|.*On ([0-9]{4})-.*|\1|g' 21 | } 22 | 23 | get_long_version() { 24 | local version=$1 25 | # shellcheck disable=SC2034 26 | read -r major minor patch fix <<<"$(echo "$version" | tr '.' ' ')" 27 | # TODO: Deal with fix 28 | 29 | echo "$major$(_add_padding "$minor")$(_add_padding "$patch")" 30 | } 31 | 32 | get_source() { 33 | local version=$1 34 | local long_version 35 | long_version="$(get_long_version "$version")" 36 | local release_year 37 | release_year="$(get_release_year "$version")" 38 | 39 | local sqlite_tarball="sqlite-autoconf-$long_version.tar.gz" 40 | local sqlite_url="https://www.sqlite.org/$release_year/$sqlite_tarball" 41 | 42 | echo "downloading sqlite source code; url=$sqlite_url; destDir=$ASDF_DOWNLOAD_PATH" 43 | 44 | curl -L --silent "$sqlite_url" --output "$ASDF_DOWNLOAD_PATH/$sqlite_tarball" 45 | tar -xf "$ASDF_DOWNLOAD_PATH/$sqlite_tarball" --strip-components=1 -C "$ASDF_DOWNLOAD_PATH" 46 | } 47 | 48 | get_source "$ASDF_INSTALL_VERSION" 49 | -------------------------------------------------------------------------------- /bin/install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | # shellcheck source=bin/utils.sh 5 | source "$(dirname "$0")/utils.sh" 6 | 7 | # Guess a good number for make -j 8 | jobs() { 9 | { 10 | nproc || 11 | sysctl -n hw.ncpu || 12 | getconf _NPROCESSORS_ONLN || 13 | echo 1 14 | } 2>/dev/null 15 | } 16 | 17 | compile_source() { 18 | local install_path=$1 19 | local gcc_options="-Os" 20 | # These are the compile options by SQLite (https://www.sqlite.org/compile.html) 21 | # except for these options, which I find might limit the use-cases of the asdf-sqlite plugin 22 | # * SQLITE_THREADSAFE=0 (when I can't make assumptions on how people will use the plugin, I find it safer to enable thread safety) 23 | # * SQLITE_DEFAULT_MEMSTATUS=0 24 | # * SQLITE_LIKE_DOESNT_MATCH_BLOBS 25 | # * SQLITE_OMIT_DECLTYPE 26 | # * SQLITE_OMIT_PROGRESS_CALLBACK 27 | # * SQLITE_OMIT_AUTOINIT 28 | local recommended_options=" 29 | -DSQLITE_DQS=0 30 | -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 31 | -DSQLITE_MAX_EXPR_DEPTH=0 32 | -DSQLITE_OMIT_DEPRECATED 33 | -DSQLITE_OMIT_SHARED_CACHE 34 | -DSQLITE_USE_ALLOCA 35 | -DSQLITE_STRICT_SUBTYPE=1 36 | " 37 | local default_features=" 38 | -DSQLITE_ENABLE_API_ARMOR 39 | -DSQLITE_ENABLE_BATCH_ATOMIC_WRITE 40 | -DSQLITE_ENABLE_BYTECODE_VTAB 41 | -DSQLITE_ENABLE_COLUMN_METADATA 42 | -DSQLITE_ENABLE_DBSTAT_VTAB 43 | -DSQLITE_ENABLE_FTS5 44 | -DSQLITE_ENABLE_GEOPOLY 45 | -DSQLITE_ENABLE_JSON1 46 | -DSQLITE_ENABLE_RTREE 47 | -DSQLITE_ENABLE_STAT4 48 | -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT 49 | " 50 | # SQLITE_ENABLE_JSON1 is added to enable JSON for versions older than 3.38.0 51 | # SQLITE_ENABLE_STAT4 is chosen instead of SQLITE_ENABLE_QPSG because the use case of asdf-sqlite is mostly 52 | # concerned with running locally on a developer's machin rather than in production 53 | local enabled_features="${ASDF_SQLITE_ENABLED_FEATURES:-$default_features}" 54 | local DEFAULT_OPTIONS="$gcc_options $recommended_options $enabled_features" 55 | cd "$ASDF_DOWNLOAD_PATH" 56 | { 57 | local cflags 58 | cflags="${CFLAGS:-$DEFAULT_OPTIONS}" 59 | cflags="$(echo "$cflags" | tr -d '\n' | sed -E 's/[ \t]+/ /g')" 60 | CFLAGS="$cflags" \ 61 | ./configure \ 62 | --prefix="$install_path" 63 | make -j "$(jobs)" 64 | make install 65 | } >/dev/null 66 | } 67 | 68 | install_sqlite() { 69 | local install_type="$1" 70 | local install_path="$2" 71 | 72 | if [[ "$install_type" != 'version' ]]; then 73 | echoerr "Cannot install specific ref from source, sorry." 74 | echoerr "For a list of available versions, see \`asdf list-all sqlite\`." 75 | exit 1 76 | fi 77 | 78 | echo "configure && compile && make install: this might take a minute; buildDir=$ASDF_DOWNLOAD_PATH; installDir=${install_path}" 79 | compile_source "$install_path" 80 | } 81 | 82 | install_sqlite "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_PATH" 83 | -------------------------------------------------------------------------------- /bin/list-all: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | # shellcheck source=bin/utils.sh 5 | source "$(dirname "$0")/utils.sh" 6 | 7 | get_sqlite_url "/chronology.html" | 8 | grep -E '([0-9]+\.[0-9]+\.[0-9]+(.[0-9]+)?)' | 9 | sed -E 's|.*>([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?).*|\1|g' | 10 | sort_versions | 11 | tr "\n" " " 12 | -------------------------------------------------------------------------------- /bin/utils.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | export SQLITE_URL="https://www.sqlite.org" 5 | #export SQLITE_HISTORY_URL="${SQLITE_URL}/chronology.html" 6 | 7 | # Borrowed from https://github.com/rbenv/ruby-build/pull/631/files#diff-fdcfb8a18714b33b07529b7d02b54f1dR942 8 | function sort_versions() { 9 | sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | 10 | LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' 11 | } 12 | 13 | # Borrowed from https://github.com/danhper/asdf-python/blob/master/bin/utils.sh 14 | echoerr() { 15 | printf "\033[0;31m%s\033[0m" "$1" >&2 16 | } 17 | 18 | get_sqlite_url() { 19 | curl -L --silent "$SQLITE_URL/$1" 20 | } 21 | -------------------------------------------------------------------------------- /scripts/shellcheck.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | exec shellcheck -s bash -x \ 4 | bin/* -P lib/ 5 | -------------------------------------------------------------------------------- /scripts/shfmt.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | exec shfmt -d . 4 | --------------------------------------------------------------------------------