Compare commits

...

4 Commits

Author SHA1 Message Date
Etan Kissling 1898dbbeb9
add upstream download reference 2024-01-24 16:26:35 +01:00
Etan Kissling 78b7e45dcd
macOS supports no backup with `-i ''`, but GNU sed dislikes the space 2024-01-24 16:12:56 +01:00
Etan Kissling 4ab7cbe80a
ensure file content does not change 2024-01-24 16:11:13 +01:00
Etan Kissling 9178cc545a
validate SHA3 hash
To ensure file integrity, validate SHA3 hash of downloaded SQLite.
Also remove user-specific data from generated code such as $HOME name.
2024-01-24 16:03:32 +01:00
2 changed files with 22 additions and 11 deletions

View File

@ -1,6 +1,5 @@
# Generated @ 2023-02-21T09:43:32+01:00
# Command line:
# /home/arnetheduck/.nimble/pkgs2/nimterop-0.6.13-a93246b2ad5531db11e51de7b2d188c42d95576a/nimterop/toast --preprocess -m:c -H --compile+=sqlite3_abi/sqlite3.c --pnim --symOverride=sqlite3_index_info,sqlite3_vmprintf,sqlite3_vsnprintf,sqlite3_str_vappendf,sqlite_int64,sqlite_uint64,sqlite3_int64,sqlite3_uint64,SQLITE_STATIC,sqlite3_version --nim:/home/arnetheduck/src/Nim/bin/nim --pluginSourcePath=/home/arnetheduck/.cache/nim/nimterop/cPlugins/nimterop_2309319294.nim /home/arnetheduck/src/nim-sqlite3-abi/sqlite3_abi/sqlite3.h -o /home/arnetheduck/src/nim-sqlite3-abi/sqlite3_abi/sqlite3_gen.nim
# ~/.nimble/pkgs2/nimterop-0.6.13-a93246b2ad5531db11e51de7b2d188c42d95576a/nimterop/toast --preprocess -m:c -H --compile+=sqlite3_abi/sqlite3.c --pnim --symOverride=sqlite3_index_info,sqlite3_vmprintf,sqlite3_vsnprintf,sqlite3_str_vappendf,sqlite_int64,sqlite_uint64,sqlite3_int64,sqlite3_uint64,SQLITE_STATIC,sqlite3_version --nim:nim --pluginSourcePath=~/.cache/nim/nimterop/cPlugins/nimterop_2309319294.nim sqlite3_abi/sqlite3.h -o sqlite3_abi/sqlite3_gen.nim
# const 'SQLITE_EXTERN' has unsupported value 'extern'
# const 'SQLITE_STDCALL' has unsupported value 'SQLITE_APICALL'

View File

@ -1,31 +1,43 @@
#!/bin/bash
#!/usr/bin/env bash
set -eu -o pipefail
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")"
# https://www.sqlite.org/download.html
MAJOR="${1:-3}"
MINOR="${2:-40}"
PATCH="${3:-1}"
YEAR="${4:-2022}"
HASH="${5:-2618a7f311ce3f8307c45035bce31805185d632241b2af6c250b4531f09edccb}"
VER_INT="$(printf "%d%02d%02d00" "$MAJOR" "$MINOR" "$PATCH")"
# TODO check sha256sum
cd sqlite3_abi
ZIP="sqlite-amalgamation-$VER_INT.zip"
[ -f "$ZIP" ] || wget https://www.sqlite.org/2022/$ZIP
[ -f "$ZIP" ] || wget https://www.sqlite.org/$YEAR/$ZIP
HASH_ACTUAL=$(python3 -c "import hashlib; print(hashlib.sha3_256(open('$ZIP', 'rb').read()).hexdigest())")
if [[ "${HASH_ACTUAL}" != "${HASH}" ]]; then
echo "Incorrect ${ZIP} hash: ${HASH}"
false
fi
unzip -jo $ZIP "sqlite-amalgamation-$VER_INT/sqlite3.c" "sqlite-amalgamation-$VER_INT/sqlite3.h"
cd ..
[[ -v HAS_NIMTEROP ]] || nimble install -y nimterop@0.6.13
(( ${HAS_NIMTEROP:-0} )) || nimble install -y nimterop@0.6.13
nim c -o:wrap --verbosity:0 --hints:off ./sqlite3_abi/wrap.nim
nim c -o:wrap --skipParentCfg --verbosity:0 --hints:off ./sqlite3_abi/wrap.nim
./wrap
sed -i \
sed -i.bak \
-e "s|cdecl|sqlitedecl|g" \
-e "s|$PWD/||" \
-e 's|{.experimental: "codeReordering".}|{.experimental: "codeReordering".}\nwhen (NimMajor, NimMinor) < (1, 4):\n {.pragma: sqlitedecl, cdecl, gcsafe, raises: [Defect].}\nelse:\n {.pragma: sqlitedecl, gcsafe, cdecl, raises: [].}|' \
-e "\|Generated @|d" \
-e "s|$PWD/||g" \
-e "s|$HOME|~|g" \
-e "s|--nim:/[^ ]*|--nim:nim|g" \
-e 's|{.experimental: "codeReordering".}|{.experimental: "codeReordering".}\nwhen (NimMajor, NimMinor) < (1, 4):\n {.pragma: sqlitedecl, cdecl, gcsafe, raises: [Defect].}\nelse:\n {.pragma: sqlitedecl, cdecl, gcsafe, raises: [].}|' \
-e "s|sqlite3_column_text\\*(a1: ptr sqlite3_stmt; iCol: cint): ptr cuchar|sqlite3_column_text\\*(a1: ptr sqlite3_stmt; iCol: cint): cstring|" \
-e "s|sqlite3_value_text\\*(a1: ptr sqlite3_value): ptr cuchar|sqlite3_value_text\\*(a1: ptr sqlite3_value): cstring|" \
sqlite3_abi/sqlite3_gen.nim
rm -f sqlite3_abi/sqlite3_gen.nim.bak # Portable GNU/macOS `sed` needs backup