feat: add fetch-libstorage.sh to download prebuilt library

Script auto-detects OS/arch, downloads the matching libstorage release
zip from GitHub, and extracts it into the layout expected by CMakeLists.txt.
Also updates .gitignore to exclude build/ and libstorage/ directories.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gmega 2026-02-02 16:09:13 -03:00
parent 7bf64b65b7
commit 3baf2d65d3
No known key found for this signature in database
GPG Key ID: 6290D34EAD824B18
2 changed files with 71 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
cmake-*
build/
libstorage/
.idea

69
scripts/fetch-libstorage.sh Executable file
View File

@ -0,0 +1,69 @@
#!/usr/bin/env bash
set -euo pipefail
LIBSTORAGE_VERSION="v0.3.1"
# --- Detect OS ---
case "$(uname -s)" in
Linux) OS="linux" ;;
Darwin) OS="darwin" ;;
*) echo "Error: unsupported OS '$(uname -s)'" >&2; exit 1 ;;
esac
# --- Detect architecture ---
case "$(uname -m)" in
x86_64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) echo "Error: unsupported architecture '$(uname -m)'" >&2; exit 1 ;;
esac
# --- Check dependencies ---
for cmd in curl unzip; do
if ! command -v "$cmd" &>/dev/null; then
echo "Error: '$cmd' is required but not found" >&2
exit 1
fi
done
# --- Construct URL and destination ---
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEST_DIR="${SCRIPT_DIR}/../libstorage"
ZIP_NAME="libstorage-${OS}-${ARCH}-${LIBSTORAGE_VERSION}.zip"
URL="https://github.com/logos-storage/logos-storage-nim/releases/download/${LIBSTORAGE_VERSION}/${ZIP_NAME}"
echo "Fetching ${ZIP_NAME} ..."
# --- Download to temp file ---
TMPFILE="$(mktemp)"
trap 'rm -f "$TMPFILE"' EXIT
if ! curl -fSL -o "$TMPFILE" "$URL"; then
echo "Error: failed to download ${URL}" >&2
exit 1
fi
# --- Prepare destination ---
rm -rf "$DEST_DIR"
mkdir -p "${DEST_DIR}/library" "${DEST_DIR}/build"
# --- Extract ---
TMPDIR_EXTRACT="$(mktemp -d)"
trap 'rm -f "$TMPFILE"; rm -rf "$TMPDIR_EXTRACT"' EXIT
unzip -q -o "$TMPFILE" -d "$TMPDIR_EXTRACT"
# --- Place files into expected layout ---
# Determine shared library extension
case "$OS" in
linux) LIB_EXT="so" ;;
darwin) LIB_EXT="dylib" ;;
esac
cp "${TMPDIR_EXTRACT}/libstorage.h" "${DEST_DIR}/library/"
cp "${TMPDIR_EXTRACT}/libstorage.${LIB_EXT}" "${DEST_DIR}/build/"
echo ""
echo "libstorage ${LIBSTORAGE_VERSION} installed to: ${DEST_DIR}"
echo ""
echo "Use with cmake:"
echo " cmake -B build -S . -DLOGOS_STORAGE_NIM_ROOT=${DEST_DIR}"