Skip to content
1        10        20        30        40        50        60        70        80        90        100       1101#!/usr/bin/env bash2# Vendors the C and C++ libraries the server links into its own binary:3#   - DuckDB's static archives (engine, built-in extensions, httplib, extension loader)4#   - the libstdc++ static archive DuckDB's C++ needs5#6# They land in vendor/duckdb/<version>/. Nothing is expected from the host: no7# libduckdb.so, no libstdc++-dev, no g++. The script is idempotent and exits early8# when every file is already present.9set -euo pipefail1011version="${DUCKDB_VERSION:-2.0.0}"12root="$(cd "$(dirname "$0")/.." && pwd)"13dest="$root/vendor/duckdb/v$version"1415case "$(uname -m)" in16  x86_64)  arch=amd64 ;;17  aarch64) arch=arm64 ;;18  *) echo "unsupported architecture: $(uname -m)" >&2; exit 1 ;;19esac2021# Checksums pin the exact bytes so a build cannot silently pick up a different22# library. DuckDB publishes no checksum file, so these are recorded here.23case "$version" in24  2.0.0)25    duckdb_url="https://github.com/duckdb/duckdb/releases/download/v$version/duckdb-static-libs-linux-$arch.tar.gz"26    case "$arch" in27      amd64) duckdb_sha=112d62c980f5447cd303a70b3dacbc09acd41ccb4ef6d154e8629f543a0f8568 ;;28      arm64) duckdb_sha=8171b4842e68a85b2e82b342d3bf7b542a88fd6666e0c18438d7b459012494ee ;;29    esac30    libstdcxx_url="https://deb.debian.org/debian/pool/main/g/gcc-12/libstdc++-12-dev_12.2.0-14+deb12u1_$arch.deb"31    case "$arch" in32      amd64) libstdcxx_sha=d28def6c23630432b57cb38a4c2fd67a79d4e0484027386ca6e8d6005c3d7a73 ;;33      arm64) libstdcxx_sha=b74b18927037498c10c8c5dd7a0abe132b4d90188ca5d6e899a4f777c6d52a74 ;;34    esac35    ;;36  *)37    echo "no pinned checksums for DuckDB $version; add them to scripts/fetch-duckdb.sh" >&238    exit 139    ;;40esac4142required=(43  libduckdb_static.a44  libduckdb_httplib.a45  libduckdb_loadable_extensions.a46  libcore_functions_extension.a47  libjson_extension.a48  libparquet_extension.a49  libicu_extension.a50  libstdc++.a51  duckdb.h52  duckdb_static_extension.h53)5455missing=056for file in "${required[@]}"; do57  [[ -f "$dest/$file" ]] || missing=158done59if [[ "$missing" -eq 0 ]]; then60  echo "DuckDB $version is already vendored in $dest"61  exit 062fi6364work="$(mktemp -d)"65trap 'rm -rf "$work"' EXIT6667download() { # url, sha256, output68  local url="$1" sha="$2" out="$3" got69  echo "Fetching $url"70  curl -fsSL --retry 3 -o "$out" "$url"71  got="$(sha256sum "$out" | cut -d' ' -f1)"72  if [[ "$got" != "$sha" ]]; then73    echo "checksum mismatch for $url: expected $sha, got $got" >&274    exit 175  fi76}7778extract_deb() { # deb, output directory79  local deb="$1" out="$2"80  mkdir -p "$out"81  if command -v dpkg-deb >/dev/null 2>&1; then82    dpkg-deb -x "$deb" "$out"83  else84    local unpack="$work/deb"85    mkdir -p "$unpack"86    (cd "$unpack" && ar x "$deb")87    tar -xf "$unpack"/data.tar.* -C "$out"88  fi89}9091mkdir -p "$dest"9293download "$duckdb_url" "$duckdb_sha" "$work/duckdb.tar.gz"94tar -xzf "$work/duckdb.tar.gz" -C "$dest"9596download "$libstdcxx_url" "$libstdcxx_sha" "$work/libstdc++.deb"97extract_deb "$work/libstdc++.deb" "$work/libstdcxx"98libstdcxx_archive="$(find "$work/libstdcxx" -name libstdc++.a -print -quit)"99if [[ -z "$libstdcxx_archive" ]]; then100  echo "libstdc++.a is missing from $libstdcxx_url" >&2101  exit 1102fi103cp "$libstdcxx_archive" "$dest/libstdc++.a"104105for file in "${required[@]}"; do106  [[ -f "$dest/$file" ]] || { echo "missing $dest/$file after extraction" >&2; exit 1; }107done108109echo "Vendored DuckDB $version and libstdc++ into $dest"