Skip to content

Commit 2c5f53d

Browse files
tarebyteCopilot
andcommitted
install-codespace-tools: fall back to cargo for tree-sitter on older glibc
The prebuilt tree-sitter binary requires glibc 2.35+ (Ubuntu 22.04), but github/github codespaces run Ubuntu 20.04 (glibc 2.31). Add a glibc_version_lt helper and route through `cargo install tree-sitter-cli` when the system glibc is too old for the prebuilt binary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent db363aa commit 2c5f53d

1 file changed

Lines changed: 42 additions & 12 deletions

File tree

script/install-codespace-tools

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ tool_version() {
3434
echo "${ver:-unknown}"
3535
}
3636

37+
# Return 0 (true) if system glibc is older than the given version.
38+
# Usage: glibc_version_lt 2.35
39+
glibc_version_lt() {
40+
local threshold="$1"
41+
local ver
42+
ver=$(getconf GNU_LIBC_VERSION 2>/dev/null | awk '{print $2}')
43+
if [ -z "$ver" ]; then
44+
# Can't determine glibc version; assume old to be safe
45+
return 0
46+
fi
47+
local sys_major sys_minor thr_major thr_minor
48+
sys_major="${ver%%.*}"
49+
sys_minor="${ver#*.}"
50+
thr_major="${threshold%%.*}"
51+
thr_minor="${threshold#*.}"
52+
[ "$sys_major" -lt "$thr_major" ] || \
53+
{ [ "$sys_major" -eq "$thr_major" ] && [ "$sys_minor" -lt "$thr_minor" ]; }
54+
}
55+
3756
# Check GitHub API rate limit before downloading a release asset.
3857
# Skips the download (returns 1) when remaining quota is too low.
3958
# The rate_limit endpoint itself is free and never counts against quota.
@@ -71,19 +90,30 @@ if command -v tree-sitter >/dev/null 2>&1; then
7190
echo " ✓ tree-sitter already installed ($(tool_version tree-sitter))"
7291
else
7392
start=$SECONDS
74-
echo " Installing tree-sitter-cli..."
75-
case "$ARCH_GO" in
76-
amd64) TS_ARCH="x64" ;;
77-
arm64) TS_ARCH="arm64" ;;
78-
esac
79-
if gh_download --clobber --output /tmp/tree-sitter.gz --repo tree-sitter/tree-sitter \
80-
--pattern "tree-sitter-linux-${TS_ARCH}.gz"; then
81-
gunzip -f /tmp/tree-sitter.gz
82-
install /tmp/tree-sitter "$LOCAL_BIN/tree-sitter"
83-
rm -f /tmp/tree-sitter
84-
echo " ✓ tree-sitter installed ($(tool_version tree-sitter), $((SECONDS - start))s)"
93+
if glibc_version_lt 2.35; then
94+
GLIBC_VER=$(getconf GNU_LIBC_VERSION 2>/dev/null | awk '{print $2}' || echo "unknown")
95+
echo " Installing tree-sitter-cli via cargo (glibc ${GLIBC_VER} < 2.35)..."
96+
if command -v cargo >/dev/null 2>&1; then
97+
cargo install tree-sitter-cli --root "$HOME/.local"
98+
echo " ✓ tree-sitter installed ($(tool_version tree-sitter), $((SECONDS - start))s)"
99+
else
100+
echo " ⚠ tree-sitter skipped (cargo not found; install Rust to build from source)"
101+
fi
85102
else
86-
echo " ⚠ tree-sitter skipped"
103+
echo " Installing tree-sitter-cli..."
104+
case "$ARCH_GO" in
105+
amd64) TS_ARCH="x64" ;;
106+
arm64) TS_ARCH="arm64" ;;
107+
esac
108+
if gh_download --clobber --output /tmp/tree-sitter.gz --repo tree-sitter/tree-sitter \
109+
--pattern "tree-sitter-linux-${TS_ARCH}.gz"; then
110+
gunzip -f /tmp/tree-sitter.gz
111+
install /tmp/tree-sitter "$LOCAL_BIN/tree-sitter"
112+
rm -f /tmp/tree-sitter
113+
echo " ✓ tree-sitter installed ($(tool_version tree-sitter), $((SECONDS - start))s)"
114+
else
115+
echo " ⚠ tree-sitter skipped"
116+
fi
87117
fi
88118
fi
89119

0 commit comments

Comments
 (0)