From 5f04e3114cac0347d4eab988ccc116af2c6c3804 Mon Sep 17 00:00:00 2001 From: Bryan Wilder Field Lozano Date: Wed, 13 Nov 2024 21:45:21 -0800 Subject: [PATCH] [skip ci] Provide script for installing system dependencies (#14405) INSTALLING.md instructions use pinned version of deps that may go out of sync and vary across distro. Avoid the need to document, by introducing a script The new script can be called from our Dockerfiles as well ### What's changed Script provided Documentation updated --- INSTALLING.md | 10 +-- install_dependencies.sh | 141 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 8 deletions(-) create mode 100755 install_dependencies.sh diff --git a/INSTALLING.md b/INSTALLING.md index e872542d621..a4ddd8608ab 100644 --- a/INSTALLING.md +++ b/INSTALLING.md @@ -29,16 +29,10 @@ Note the current compatability matrix: ### Step 2. System-level dependencies ```sh -sudo apt update -sudo apt install software-properties-common=0.99.9.12 build-essential=12.8ubuntu1.1 python3.8-venv libhwloc-dev graphviz cmake=3.16.3-1ubuntu1.20.04.1 ninja-build - -wget https://apt.llvm.org/llvm.sh -chmod u+x llvm.sh -sudo ./llvm.sh 17 -sudo apt install libc++-17-dev libc++abi-17-dev +sudo ./install_dependencies.sh ``` - Note: `CMake 3.16` is the targetted required version of `CMake` as it aligns with the default from `Ubuntu 20.04`. Some advanced build configurations like unity builds require `CMake 3.20`. - - To install `CMake 3.20` see: https://github.com/tenstorrent/tt-metal/blob/4d7730d3e2d22c51d62baa1bfed861b557d9a3c0/dockerfile/ubuntu-20.04-amd64.Dockerfile#L9-L14 + - To install `CMake 3.20` see: https://github.com/tenstorrent/tt-metal/blob/4d7730d3e2d22c51d62baa1bfed861b557d9a3c0/dockerfile/ubuntu-20.04-amd64.Dockerfile#L9-L14 --- ### Step 3. Hugepages diff --git a/install_dependencies.sh b/install_dependencies.sh new file mode 100755 index 00000000000..8c65888184c --- /dev/null +++ b/install_dependencies.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +# SPDX-License-Identifier: Apache-2.0 +# Copyright (C) 2024 Tenstorrent, Inc. All rights reserved. +# +# This script is based on `xrtdeps.sh` from the Xilinx XRT project. +# Original source: https://github.com/Xilinx/XRT/blob/master/src/runtime_src/tools/scripts/xrtdeps.sh +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FLAVOR=`grep '^ID=' /etc/os-release | awk -F= '{print $2}' | tr -d '"'` +VERSION=`grep '^VERSION_ID=' /etc/os-release | awk -F= '{print $2}' | tr -d '"'` +MAJOR=${VERSION%.*} +ARCH=`uname -m` + +usage() +{ + echo "Usage: sudo ./install_dependencies.sh [options]" + echo + echo "[--help, -h] List this help" + echo "[--validate, -v] Validate that required packages are installed" + exit 1 +} + +validate=0 + +while [ $# -gt 0 ]; do + case "$1" in + --help|-h) + usage + ;; + --validate|-v) + validate=1 + shift + ;; + *) + echo "Unknown option: $1" + usage + ;; + esac +done + +ub_package_list() +{ + UB_LIST=(\ + git \ + git-lfs \ + build-essential \ + cmake \ + software-properties-common \ + libhwloc-dev \ + graphviz \ + ninja-build \ + libpython3-dev \ + libcapstone-dev \ + python3-pip \ + python3-dev \ + python3.8-venv \ + libc++-17-dev \ + libc++abi-17-dev \ + ) + +} + +update_package_list() +{ + if [ $FLAVOR == "ubuntu" ]; then + ub_package_list + else + echo "unknown OS flavor $FLAVOR" + exit 1 + fi +} + +validate_packages() +{ + if [ $FLAVOR == "ubuntu" ]; then + dpkg -l "${UB_LIST[@]}" + #dpkg -l "${UB_LIST[@]}" > /dev/null + else + echo "unknown OS flavor $FLAVOR" + exit 1 + fi +} + +prep_ubuntu() +{ + echo "Preparing ubuntu ..." + # Update the list of available packages + apt-get update +} + +install_llvm() { + LLVM_VERSION="17" + echo "Checking if LLVM $LLVM_VERSION is already installed..." + if command -v clang-$LLVM_VERSION &> /dev/null; then + echo "LLVM $LLVM_VERSION is already installed. Skipping installation." + else + echo "Installing LLVM $LLVM_VERSION..." + TEMP_DIR=$(mktemp -d) + wget -P $TEMP_DIR https://apt.llvm.org/llvm.sh + chmod u+x $TEMP_DIR/llvm.sh + $TEMP_DIR/llvm.sh $LLVM_VERSION + rm -rf "$TEMP_DIR" + fi +} + +install() +{ + if [ $FLAVOR == "ubuntu" ]; then + prep_ubuntu + + echo "Installing packages..." + apt-get install -y "${UB_LIST[@]}" + fi +} + +if [ "$EUID" -ne 0 ]; then + echo "This script must be run as root. Please use sudo." + usage +fi + +install_llvm + +update_package_list + +if [ $validate == 1 ]; then + validate_packages +else + install +fi