Skip to content

Instantly share code, notes, and snippets.

@nicksherron
Last active June 28, 2025 00:14
Show Gist options
  • Save nicksherron/953d427f79150e12c3588b23e394b882 to your computer and use it in GitHub Desktop.
Save nicksherron/953d427f79150e12c3588b23e394b882 to your computer and use it in GitHub Desktop.
Work around for using github.com/tursodatabase/go-libsql in go vendor mode. Otherwise the c files in lib/ get nuked.
#!/bin/bash
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}=== Syncing go-libsql C/CGO files to vendor directory ===${NC}"
# Extract the version from go.mod
GO_LIBSQL_VERSION=$(grep 'github.com/tursodatabase/go-libsql' go.mod | awk '{print $2}')
if [ -z "$GO_LIBSQL_VERSION" ]; then
echo -e "${RED}Error: Could not find go-libsql version in go.mod${NC}"
exit 1
fi
echo -e "${YELLOW}Found go-libsql version: $GO_LIBSQL_VERSION${NC}"
# Extract commit hash from pseudo-version (format: v0.0.0-YYYYMMDDHHMMSS-COMMIT)
COMMIT_HASH=$(echo "$GO_LIBSQL_VERSION" | sed -n 's/.*-\([0-9a-f]\{12\}\)$/\1/p')
if [ -z "$COMMIT_HASH" ]; then
# If it's a tagged version, use it as-is
COMMIT_HASH=$GO_LIBSQL_VERSION
fi
echo -e "${YELLOW}Using commit/tag: $COMMIT_HASH${NC}"
ORIG_DIR=$(pwd)
# Create temporary directory
TEMP_DIR=$(mktemp -d)
trap "rm -rf $TEMP_DIR" EXIT
echo -e "${GREEN}Cloning go-libsql repository...${NC}"
cd "$TEMP_DIR"
git clone --quiet https://github.com/tursodatabase/go-libsql.git
cd go-libsql
echo -e "${GREEN}Checking out version $COMMIT_HASH...${NC}"
git checkout --quiet "$COMMIT_HASH"
# Get back to the original directory
cd - > /dev/null
# Define source and destination paths
SOURCE_LIB="$TEMP_DIR/go-libsql/lib"
echo -e "${YELLOW}Source lib directory: $SOURCE_LIB${NC}"
DEST_VENDOR="${ORIG_DIR}/vendor/github.com/tursodatabase/go-libsql"
# Check if lib directory exists in the cloned repo
if [ ! -d "$SOURCE_LIB" ]; then
echo -e "${RED}Error: lib/ directory not found in cloned repository${NC}"
exit 1
fi
#Ensure vendor directory exists
if [ ! -d "$DEST_VENDOR" ]; then
echo -e "${RED}Error: Vendor directory $DEST_VENDOR does not exist. Run 'go mod vendor' first.${NC}"
exit 1
fi
# Copy lib directory to vendor
echo -e "${GREEN}Copying lib/ files to vendor directory...${NC}"
cp -r "$SOURCE_LIB" "$DEST_VENDOR/"
# List what was copied
echo -e "${GREEN}Successfully copied the following files:${NC}"
find "$DEST_VENDOR/lib" -type f | sort | while read -r file; do
echo " - ${file#vendor/github.com/tursodatabase/go-libsql/}"
done
echo -e "${GREEN}✓ Done! CGO header files have been synced to the vendor directory.${NC}"
echo -e "${YELLOW}Note: These files will be removed if you run 'go mod vendor' again.${NC}"
echo -e "${YELLOW} Run this script after 'go mod vendor' to restore them.${NC}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment