Skip to content

Commit 563b25b

Browse files
alexclaude
andauthored
Add script to update vendored libsodium (#921)
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 <[email protected]>
1 parent d233105 commit 563b25b

File tree

2 files changed

+106
-2
lines changed

2 files changed

+106
-2
lines changed

.github/bin/update-libsodium.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/bash
2+
#
3+
# Script to upgrade the vendored copy of libsodium.
4+
#
5+
# Usage:
6+
# .github/bin/update-libsodium.sh <version>
7+
#
8+
# Example:
9+
# .github/bin/update-libsodium.sh 1.0.20
10+
11+
set -euo pipefail
12+
13+
BASE_URL="https://download.libsodium.org/libsodium/releases"
14+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15+
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
16+
SRC_DIR="$REPO_ROOT/src"
17+
LIBSODIUM_DIR="$SRC_DIR/libsodium"
18+
19+
if [ $# -ne 1 ]; then
20+
echo "Usage: $0 <version>" >&2
21+
echo "Example: $0 1.0.20" >&2
22+
exit 1
23+
fi
24+
25+
VERSION="$1"
26+
TARBALL_NAME="libsodium-${VERSION}-stable.tar.gz"
27+
MSVC_NAME="libsodium-${VERSION}-stable-msvc.zip"
28+
TARBALL_URL="${BASE_URL}/${TARBALL_NAME}"
29+
MSVC_URL="${BASE_URL}/${MSVC_NAME}"
30+
MSVC_PATH="${SRC_DIR}/${MSVC_NAME}"
31+
32+
echo "Upgrading libsodium to version ${VERSION}"
33+
echo
34+
35+
# Step 1: Check git is clean (ignore untracked files)
36+
echo "Checking git working tree..."
37+
if git status --porcelain | grep -qv '^??'; then
38+
echo "Error: Git working tree has uncommitted changes." >&2
39+
echo "Please commit or stash your changes first." >&2
40+
exit 1
41+
fi
42+
echo " -> Working tree is clean"
43+
echo
44+
45+
# Step 2: Download new files to temp location first to verify they exist
46+
echo "Downloading new files..."
47+
TMPDIR="$(mktemp -d)"
48+
trap 'rm -rf "$TMPDIR"' EXIT
49+
50+
TMP_TARBALL="${TMPDIR}/${TARBALL_NAME}"
51+
TMP_MSVC="${TMPDIR}/${MSVC_NAME}"
52+
53+
echo "Downloading ${TARBALL_URL}..."
54+
if ! curl -fSL -o "$TMP_TARBALL" "$TARBALL_URL"; then
55+
echo "Error downloading tarball." >&2
56+
echo "Version ${VERSION} may not exist. Check available versions at:" >&2
57+
echo " ${BASE_URL}/" >&2
58+
exit 1
59+
fi
60+
echo " -> Downloaded tarball"
61+
62+
echo "Downloading ${MSVC_URL}..."
63+
if ! curl -fSL -o "$TMP_MSVC" "$MSVC_URL"; then
64+
echo "Error downloading MSVC zip." >&2
65+
echo "Version ${VERSION} may not exist. Check available versions at:" >&2
66+
echo " ${BASE_URL}/" >&2
67+
exit 1
68+
fi
69+
echo " -> Downloaded MSVC zip"
70+
echo
71+
72+
# Step 3: Remove old files
73+
echo "Removing old files..."
74+
if [ -d "$LIBSODIUM_DIR" ]; then
75+
echo "Removing ${LIBSODIUM_DIR}..."
76+
rm -rf "$LIBSODIUM_DIR"
77+
fi
78+
79+
# Remove old MSVC zip (but not the one for the version we're upgrading to)
80+
for old_file in "$SRC_DIR"/libsodium-*-stable-msvc.zip; do
81+
[ -e "$old_file" ] || continue
82+
if [[ "$old_file" == *"-${VERSION}-"* ]]; then
83+
continue
84+
fi
85+
echo "Removing old archive ${old_file}..."
86+
rm -f "$old_file"
87+
done
88+
echo
89+
90+
# Step 4: Extract tarball and install MSVC zip
91+
echo "Extracting tarball to ${LIBSODIUM_DIR}..."
92+
mkdir -p "$LIBSODIUM_DIR"
93+
tar -xzf "$TMP_TARBALL" -C "$LIBSODIUM_DIR" --strip-components=1
94+
95+
echo "Installing MSVC zip..."
96+
mv "$TMP_MSVC" "$MSVC_PATH"
97+
echo " -> ${MSVC_PATH}"
98+
echo
99+
100+
echo "Successfully upgraded libsodium to ${VERSION}"
101+
echo
102+
echo "Next steps:"
103+
echo " 1. Review the changes with 'git diff'"
104+
echo " 2. Test the build"
105+
echo " 3. Commit the changes"

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ dist
1010
build
1111
eggs
1212
parts
13-
bin
1413
var
1514
sdist
1615
develop-eggs
@@ -45,4 +44,4 @@ src/libsodium/libtool
4544
!src/libsodium/builds/msvc/build
4645

4746
# mypy's cache
48-
.mypy_cache
47+
.mypy_cache

0 commit comments

Comments
 (0)