1#!/bin/bash 2# Copyright (c) Meta Platforms, Inc. and affiliates. 3# All rights reserved. 4# 5# This source code is licensed under the BSD-style license found in the 6# LICENSE file in the root directory of this source tree. 7 8set -ex 9 10install_ubuntu() { 11 apt-get update 12 13 apt-get install -y --no-install-recommends clang-"$CLANG_VERSION" 14 apt-get install -y --no-install-recommends llvm-"$CLANG_VERSION" 15 # Also require LLD linker from llvm and libomp to build PyTorch from source 16 apt-get install -y lld "libomp-${CLANG_VERSION}-dev" "libc++-${CLANG_VERSION}-dev" 17 18 # Use update-alternatives to make this version the default 19 update-alternatives --install /usr/bin/clang clang /usr/bin/clang-"$CLANG_VERSION" 50 20 update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-"$CLANG_VERSION" 50 21 # Override cc/c++ to clang as well 22 update-alternatives --install /usr/bin/cc cc /usr/bin/clang 50 23 update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 50 24 25 # Cleanup package manager 26 apt-get autoclean && apt-get clean 27 rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 28} 29 30if [ -n "$CLANG_VERSION" ]; then 31 # Install base packages depending on the base OS 32 ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"') 33 case "$ID" in 34 ubuntu) 35 install_ubuntu 36 ;; 37 *) 38 echo "Unable to determine OS..." 39 exit 1 40 ;; 41 esac 42fi 43