Skip to content

Commit 0529d66

Browse files
FindHaofacebook-github-bot
authored andcommitted
Fix CI Script for Ubuntu 24.04 and Improve CUDA Handling (#51)
Summary: This PR updates the `.ci/setup.sh` script to improve compatibility and reliability for CI on Ubuntu 24.04. ## Key Changes 1. **Set Default Clang Version** * After installing `clang-19` and `clangd-19`, `update-alternatives` is now used to explicitly set them as the system-wide default `clang` and `clangd` commands. This ensures that subsequent scripts and build tools can directly call `clang`, resolving the `clang: command not found` issue. 2. **Optimized CUDA Detection and Installation** * The script now robustly checks for `nvcc` in the `PATH` or standard installation locations in a way that prevents the script from exiting prematurely due to `set -e`. * Added support for the `INSTALL_CUDA` environment variable to conditionally control the installation of the CUDA toolkit. 3. **Improved Debugging and Robustness** * Removed unnecessary debug outputs while retaining essential error messages and installation information. * Ensured that all critical dependencies can be correctly invoked after installation. ## Impact * The CI environment is more stable on Ubuntu 24.04, with the toolchain and dependencies configured automatically. * Users no longer need to manually configure the default clang version, reducing environment setup errors. * CUDA detection is more robust, supporting various installation scenarios. Pull Request resolved: #51 Reviewed By: sfzhu93 Differential Revision: D79598464 Pulled By: FindHao fbshipit-source-id: aee9865460c0580b42c5381ac2f61d950b1f67fb
1 parent 62f875c commit 0529d66

File tree

1 file changed

+35
-43
lines changed

1 file changed

+35
-43
lines changed

.ci/setup.sh

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,63 +18,52 @@ echo "CUDA_VERSION: $CUDA_VERSION"
1818
# Install system dependencies
1919
echo "Installing system dependencies..."
2020

21-
# Set up LLVM 17 APT source with modern GPG key handling
22-
echo "Setting up LLVM 17 APT source..."
23-
NEED_SOURCE_UPDATE=false
24-
25-
# Check if LLVM source is already configured
26-
if [ ! -f "/etc/apt/sources.list.d/llvm-toolchain-jammy-17.list" ]; then
27-
echo "📝 Configuring LLVM APT source..."
28-
29-
# Download and install GPG key to /usr/share/keyrings
30-
curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key |
31-
gpg --dearmor | sudo tee /usr/share/keyrings/llvm-archive-keyring.gpg >/dev/null
32-
33-
# Make sure key file is readable by _apt
34-
sudo chmod a+r /usr/share/keyrings/llvm-archive-keyring.gpg
35-
36-
# Write APT source list, explicitly binding keyring file
37-
echo "deb [signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" |
38-
sudo tee /etc/apt/sources.list.d/llvm-toolchain-jammy-17.list
39-
40-
NEED_SOURCE_UPDATE=true
41-
echo "✅ LLVM APT source configured"
42-
else
43-
echo "✅ LLVM APT source already configured"
44-
fi
45-
4621
# Update package lists
47-
if [ "$NEED_SOURCE_UPDATE" = "true" ]; then
48-
echo "🔄 Updating package lists (new source added)..."
49-
else
50-
echo "🔄 Updating package lists..."
51-
fi
22+
echo "🔄 Updating package lists..."
5223
sudo apt-get update
5324

5425
# Install clang and clangd first
5526
echo "Installing clang and clangd..."
56-
if command -v clang-17 &>/dev/null && command -v clangd-17 &>/dev/null; then
57-
echo "✅ clang-17 and clangd-17 already installed"
27+
if command -v clang-19 &>/dev/null && command -v clangd-19 &>/dev/null; then
28+
echo "✅ clang-19 and clangd-19 already installed"
5829
else
59-
echo "📦 Installing clang-17 and clangd-17..."
60-
sudo apt-get install -y clang-17 clangd-17
30+
echo "📦 Installing clang-19 and clangd-19 from Ubuntu repositories..."
31+
sudo apt-get install -y clang-19 clangd-19
6132
fi
6233

63-
# Set up clang alternatives
64-
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 100
65-
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 100
66-
sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-17 100
34+
# Set clang-19 and clangd-19 as the default
35+
echo "Setting clang-19 and clangd-19 as default..."
36+
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-19 100
37+
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 100
38+
sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-19 100
6739

6840
# Install CUDA and development libraries
6941
echo "Installing CUDA and development libraries..."
7042

7143
# Check for specific CUDA 12.8 version
7244
CUDA_VERSION_REQUIRED="12.8"
7345
HAS_CORRECT_CUDA=false
46+
# Allow skipping CUDA installation via environment variable
47+
INSTALL_CUDA=${INSTALL_CUDA:-true}
7448

49+
# Try to find nvcc in a way that is safe for `set -e`
50+
NVCC_PATH=""
7551
if command -v nvcc &>/dev/null; then
52+
NVCC_PATH=$(command -v nvcc)
53+
echo "Found nvcc in PATH: $NVCC_PATH"
54+
elif [ -x "/usr/local/cuda/bin/nvcc" ]; then
55+
NVCC_PATH="/usr/local/cuda/bin/nvcc"
56+
echo "Found nvcc at $NVCC_PATH"
57+
elif [ -x "/usr/local/cuda-12.8/bin/nvcc" ]; then
58+
NVCC_PATH="/usr/local/cuda-12.8/bin/nvcc"
59+
echo "Found nvcc at $NVCC_PATH"
60+
fi
61+
62+
if [ -n "$NVCC_PATH" ]; then
63+
echo "Verifying CUDA version using '$NVCC_PATH -v':"
64+
$NVCC_PATH -v
7665
# Get CUDA version from nvcc
77-
INSTALLED_CUDA_VERSION=$(nvcc --version | grep "release" | sed -n 's/.*release \([0-9]\+\.[0-9]\+\).*/\1/p')
66+
INSTALLED_CUDA_VERSION=$($NVCC_PATH --version | grep "release" | sed -n 's/.*release \([0-9]\+\.[0-9]\+\).*/\1/p')
7867
if [ "$INSTALLED_CUDA_VERSION" = "$CUDA_VERSION_REQUIRED" ]; then
7968
echo "✅ CUDA $CUDA_VERSION_REQUIRED already installed"
8069
HAS_CORRECT_CUDA=true
@@ -83,22 +72,25 @@ if command -v nvcc &>/dev/null; then
8372
HAS_CORRECT_CUDA=false
8473
fi
8574
else
86-
echo "📦 No CUDA toolkit found"
75+
echo "📦 No CUDA toolkit found in PATH or standard locations"
8776
HAS_CORRECT_CUDA=false
8877
fi
8978

9079
echo "🔧 Installing development libraries"
91-
sudo apt-get install -y libstdc++6 libstdc++-12-dev libffi-dev libncurses-dev zlib1g-dev libxml2-dev git build-essential cmake bc gdb curl wget
80+
sudo apt-get install -y libstdc++6 libstdc++-13-dev libffi-dev libncurses-dev zlib1g-dev libxml2-dev git build-essential cmake bc gdb curl wget
9281

93-
if [ "$HAS_CORRECT_CUDA" != "true" ]; then
82+
if [ "$HAS_CORRECT_CUDA" != "true" ] && [ "$INSTALL_CUDA" = "true" ]; then
9483
echo "📦 Installing CUDA $CUDA_VERSION_REQUIRED"
9584
# Install all packages including CUDA toolkit (this is the big download)
9685
sudo apt-get install -y cuda-toolkit-12.8
86+
elif [ "$INSTALL_CUDA" != "true" ]; then
87+
echo "ℹ️ Skipping CUDA installation because INSTALL_CUDA is not 'true'."
9788
fi
9889

9990
# Verify clang installation
10091
echo "Verifying clang installation..."
10192
clang --version
93+
clang++ --version
10294
clangd --version
10395

10496
# Install Miniconda if not already installed
@@ -118,7 +110,7 @@ conda init bash || true
118110

119111
# Create conda environment
120112
echo "Creating conda environment: $CONDA_ENV"
121-
conda create -n "$CONDA_ENV" python="$PYTHON_VERSION" -y || true
113+
conda create -n "$CONDA_ENV" python="$PYTHON_VERSION" -y -c conda-forge || true
122114

123115
# Activate conda environment
124116
source /opt/miniconda3/etc/profile.d/conda.sh

0 commit comments

Comments
 (0)