Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions scripts/update-local-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

set -euo pipefail

# Ensure the linker can find clang_rt on macOS (Xcode clang version may differ
# from the version some Rust crates hard-code in their build scripts).
if [ "$(uname)" = "Darwin" ]; then
CLANG_LIB="$(echo /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/*/lib/darwin)"
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
if [ -d "$CLANG_LIB" ]; then
Comment on lines +10 to +11

Copilot AI Mar 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLANG_LIB is derived via echo .../clang/*/lib/darwin, which can expand to multiple paths (space-separated) if more than one clang version directory exists; in that case [ -d "$CLANG_LIB" ] will fail and LIBRARY_PATH won’t be set. Consider resolving a single directory deterministically (e.g., using xcode-select -p plus ls -d ... | sort -V | tail -n1, or a small find/array-glob) and avoiding echo for glob expansion.

Suggested change
CLANG_LIB="$(echo /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/*/lib/darwin)"
if [ -d "$CLANG_LIB" ]; then
# Use the active Xcode toolchain and pick the highest clang version's darwin lib dir.
XCODE_PATH="$(xcode-select -p 2>/dev/null || true)"
if [ -n "$XCODE_PATH" ]; then
CLANG_LIB="$(ls -d "$XCODE_PATH"/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/*/lib/darwin 2>/dev/null | sort -V | tail -n 1 || true)"
else
CLANG_LIB=""
fi
if [ -n "${CLANG_LIB:-}" ] && [ -d "$CLANG_LIB" ]; then

Copilot uses AI. Check for mistakes.
export LIBRARY_PATH="${CLANG_LIB}${LIBRARY_PATH:+:$LIBRARY_PATH}"
fi
Comment on lines +10 to +13

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This implementation has a couple of robustness issues:

  1. Hardcoded Xcode Path: The path /Applications/Xcode.app is hardcoded. It's better to use xcode-select -p to find the developer directory dynamically, as Xcode can be installed in other locations.
  2. Unsafe Glob Expansion: The command echo ...*... is not safe. If the * glob expands to multiple directories (e.g., multiple clang versions installed), $CLANG_LIB will contain a space-separated string of paths, and the if [ -d "$CLANG_LIB" ] test will fail with a "too many arguments" error.

Here is a more robust implementation that addresses both points by using xcode-select and handling glob expansion with an array.

Suggested change
CLANG_LIB="$(echo /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/*/lib/darwin)"
if [ -d "$CLANG_LIB" ]; then
export LIBRARY_PATH="${CLANG_LIB}${LIBRARY_PATH:+:$LIBRARY_PATH}"
fi
XCODE_DEV_PATH="$(xcode-select -p 2>/dev/null)"
if [ -n "$XCODE_DEV_PATH" ]; then
# Use an array to safely handle glob expansion and take the first result.
CLANG_LIB_PATHS=("$XCODE_DEV_PATH"/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/*/lib/darwin)
if [[ ${#CLANG_LIB_PATHS[@]} -gt 0 && -d "${CLANG_LIB_PATHS[0]}" ]]; then
export LIBRARY_PATH="${CLANG_LIB_PATHS[0]}${LIBRARY_PATH:+:$LIBRARY_PATH}"
fi
fi

fi

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
CONFIG_FILE="$REPO_ROOT/.local-binaries.txt"
Expand Down
Loading