#!/usr/bin/env bash # Installs the official prebuilt DuckDB shared library (libduckdb.so and # duckdb.h) for the current CPU architecture into , after checking # its SHA-256. DuckDB is never compiled from source in this project. # # scripts/fetch-libduckdb.sh # # Then build with DUCKDB_LIB_DIR= and run tests or the binary with # LD_LIBRARY_PATH= (the Docker image uses ldconfig instead). # # The pinned version MUST match the duckdb crate in Cargo.lock: duckdb-rs # encodes the DuckDB version in its second component (DuckDB 1.5.6 <-> duckdb # 1.10506.x); scripts/check.sh enforces this. To upgrade, change the version # and both checksums together (from the "digest" field of each asset in # https://api.github.com/repos/duckdb/duckdb/releases/tags/v). # DuckDB 2.x renamed these assets to duckdb-shared-libs-linux-.tar.gz. set -euo pipefail DUCKDB_VERSION=1.5.6 dest=${1:?usage: fetch-libduckdb.sh } case "$(uname -m)" in x86_64 | amd64) arch=amd64 sha256=b845005f5132a7d8180057c35e14a7626632258782f871a90861b19c1c03841b ;; aarch64 | arm64) arch=arm64 sha256=b72ed9f05003f5e9d2015f7ceada6416b377d9dd33169cdde3c9e33897856eee ;; *) echo "fetch-libduckdb: unsupported architecture: $(uname -m)" >&2; exit 1 ;; esac stamp="$DUCKDB_VERSION-linux-$arch" installed() { [ -f "$dest/libduckdb.so" ] && [ "$(cat "$dest/.duckdb-release" 2>/dev/null)" = "$stamp" ]; } if installed; then echo "libduckdb $stamp already in $dest" exit 0 fi command -v unzip >/dev/null || { echo "fetch-libduckdb: unzip is required" >&2; exit 1; } parent=$(dirname "$dest") mkdir -p "$parent" # Stage next to the destination so the final rename is atomic: parallel CI # jobs sharing /opt/hostedtoolcache never see a half-extracted library. stage=$(mktemp -d "$parent/.libduckdb.XXXXXX") trap 'rm -rf "$stage"' EXIT asset="libduckdb-linux-$arch.zip" curl -fsSL --retry 3 -o "$stage/$asset" \ "https://github.com/duckdb/duckdb/releases/download/v$DUCKDB_VERSION/$asset" echo "$sha256 $stage/$asset" | sha256sum -c --quiet - \ || { echo "fetch-libduckdb: checksum mismatch for $asset" >&2; exit 1; } # The archive also carries libduckdb_static.a (~80 MB) and duckdb.hpp; only the # shared library and the C header are needed. unzip -o -j -q "$stage/$asset" libduckdb.so duckdb.h -d "$stage/lib" echo "$stamp" > "$stage/lib/.duckdb-release" if ! mv -T "$stage/lib" "$dest" 2>/dev/null; then # Either another job just installed the same release, or an older one is there. installed || { rm -rf "$dest" && mv -T "$stage/lib" "$dest"; } fi echo "libduckdb $stamp installed in $dest"