|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Download musl.cc cross-compiler toolchains |
| 4 | +# |
| 5 | +# This script downloads pre-built cross-compiler toolchains from musl.cc |
| 6 | +# and stores them in the cross-compilers/ directory for Git LFS tracking. |
| 7 | +# |
| 8 | +# Usage: ./scripts/download-musl-cc.sh |
| 9 | +# |
| 10 | +# Before running this script, ensure Git LFS is installed: |
| 11 | +# brew install git-lfs (macOS) |
| 12 | +# apt-get install git-lfs (Ubuntu/Debian) |
| 13 | +# choco install git-lfs (Windows) |
| 14 | +# |
| 15 | +# Then initialize Git LFS in this repository: |
| 16 | +# git lfs install |
| 17 | +# |
| 18 | + |
| 19 | +set -e |
| 20 | + |
| 21 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 22 | +REPO_ROOT="$(dirname "$SCRIPT_DIR")" |
| 23 | +CROSS_COMPILERS_DIR="$REPO_ROOT/cross-compilers" |
| 24 | + |
| 25 | +# Create cross-compilers directory if it doesn't exist |
| 26 | +mkdir -p "$CROSS_COMPILERS_DIR" |
| 27 | + |
| 28 | +# Array of architectures to download |
| 29 | +declare -a ARCHITECTURES=( |
| 30 | + "arm-linux-musleabihf" |
| 31 | + "riscv64-linux-musl" |
| 32 | + "s390x-linux-musl" |
| 33 | + "powerpc64le-linux-musl" |
| 34 | +) |
| 35 | + |
| 36 | +# Colors for output |
| 37 | +GREEN='\033[0;32m' |
| 38 | +BLUE='\033[0;34m' |
| 39 | +RED='\033[0;31m' |
| 40 | +NC='\033[0m' # No Color |
| 41 | + |
| 42 | +echo -e "${BLUE}Downloading musl.cc cross-compiler toolchains${NC}" |
| 43 | +echo "Destination: $CROSS_COMPILERS_DIR" |
| 44 | +echo "" |
| 45 | + |
| 46 | +# Check if Git LFS is configured |
| 47 | +if ! git lfs version &>/dev/null; then |
| 48 | + echo -e "${RED}Error: Git LFS is not installed${NC}" |
| 49 | + echo "" |
| 50 | + echo "Install Git LFS first:" |
| 51 | + echo " macOS: brew install git-lfs" |
| 52 | + echo " Linux: apt-get install git-lfs" |
| 53 | + echo " Windows: choco install git-lfs" |
| 54 | + echo "" |
| 55 | + echo "Then initialize it in this repository:" |
| 56 | + echo " git lfs install" |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | + |
| 60 | +# Download each toolchain |
| 61 | +for arch in "${ARCHITECTURES[@]}"; do |
| 62 | + filename="${arch}-cross.tgz" |
| 63 | + filepath="$CROSS_COMPILERS_DIR/$filename" |
| 64 | + url="https://musl.cc/${filename}" |
| 65 | + |
| 66 | + # Skip if already exists |
| 67 | + if [ -f "$filepath" ]; then |
| 68 | + echo -e "${GREEN}✓${NC} $filename already exists, skipping" |
| 69 | + continue |
| 70 | + fi |
| 71 | + |
| 72 | + echo -e "${BLUE}Downloading${NC} $filename..." |
| 73 | + |
| 74 | + # Download with retries |
| 75 | + for attempt in 1 2 3; do |
| 76 | + if wget -O "$filepath" "$url"; then |
| 77 | + echo -e "${GREEN}✓${NC} Downloaded: $filename" |
| 78 | + break |
| 79 | + else |
| 80 | + if [ $attempt -lt 3 ]; then |
| 81 | + echo " Attempt $attempt failed, retrying in 15 seconds..." |
| 82 | + sleep 15 |
| 83 | + else |
| 84 | + echo -e "${RED}✗${NC} Failed to download $filename after 3 attempts" |
| 85 | + rm -f "$filepath" |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | + fi |
| 89 | + done |
| 90 | +done |
| 91 | + |
| 92 | +echo "" |
| 93 | +echo -e "${GREEN}All musl.cc cross-compilers downloaded successfully!${NC}" |
| 94 | +echo "" |
| 95 | +echo "Next steps:" |
| 96 | +echo " 1. Add these files to Git LFS tracking:" |
| 97 | +echo " git lfs track 'cross-compilers/*.tgz'" |
| 98 | +echo " 2. Commit and push:" |
| 99 | +echo " git add cross-compilers/ .gitattributes" |
| 100 | +echo " git commit -m 'Add musl.cc cross-compiler toolchains'" |
| 101 | +echo " git push" |
0 commit comments