From 9e7905d69e2f0da8f3dec292f0bfab728a4656a2 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Wed, 16 Aug 2023 01:03:14 -0500 Subject: [PATCH] use a simpler one --- .bashrc | 1 - .clangd | 61 -------- .github/workflows/test-feature.yml | 1 - README.md | 6 +- common/etc/bash.bash_env | 37 ----- common/install.sh | 42 ------ common/utilities.sh | 230 ----------------------------- devcontainer-feature.json | 89 ++--------- install.sh | 98 +----------- llvm.sh | 192 ------------------------ 10 files changed, 16 insertions(+), 741 deletions(-) delete mode 100644 .bashrc delete mode 100644 .clangd delete mode 100644 common/etc/bash.bash_env delete mode 100644 common/install.sh delete mode 100644 common/utilities.sh delete mode 100644 llvm.sh diff --git a/.bashrc b/.bashrc deleted file mode 100644 index 55373eb..0000000 --- a/.bashrc +++ /dev/null @@ -1 +0,0 @@ -export LLVM_VERSION="${LLVM_VERSION}"; diff --git a/.clangd b/.clangd deleted file mode 100644 index 45a4302..0000000 --- a/.clangd +++ /dev/null @@ -1,61 +0,0 @@ -# https://clangd.llvm.org/config - -# Apply a config conditionally to all C files -If: - PathMatch: .*\.(c|h)$ - ---- - -# Apply a config conditionally to all C++ files -If: - PathMatch: .*\.(c|h)pp - ---- - -# Apply a config conditionally to all CUDA files -If: - PathMatch: .*\.cuh? -CompileFlags: - Add: - - "-x" - - "cuda" - # No error on unknown CUDA versions - - "-Wno-unknown-cuda-version" - # Allow variadic CUDA functions - - "-Xclang=-fcuda-allow-variadic-functions" - ---- - -# Tweak the clangd parse settings for all files -CompileFlags: - Add: - # report all errors - - "-ferror-limit=0" - - "-fmacro-backtrace-limit=0" - - "-ftemplate-backtrace-limit=0" - # Skip the CUDA version check - - "--no-cuda-version-check" - Remove: - # remove gcc's -fcoroutines - - -fcoroutines - # remove nvc++ flags unknown to clang - - "-gpu=*" - - "-stdpar*" - # remove nvcc flags unknown to clang - - "-arch*" - - "-gencode*" - - "--generate-code*" - - "-ccbin*" - - "-t=*" - - "--threads*" - - "-Xptxas*" - - "-Xcudafe*" - - "-Xfatbin*" - - "-Xcompiler*" - - "--diag-suppress*" - - "--diag_suppress*" - - "--compiler-options*" - - "--expt-extended-lambda" - - "--expt-relaxed-constexpr" - - "-forward-unknown-to-host-compiler" - - "-Werror=cross-execution-space-call" diff --git a/.github/workflows/test-feature.yml b/.github/workflows/test-feature.yml index bb04a54..58e0b1f 100644 --- a/.github/workflows/test-feature.yml +++ b/.github/workflows/test-feature.yml @@ -25,7 +25,6 @@ jobs: matrix: include: - image: mcr.microsoft.com/devcontainers/base:ubuntu - options: '{ "version": "13" }' - image: debian:bookworm-slim runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index 4547cf3..4736f63 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ // devcontainer.json { "features": { - "ghcr.io/octocat/features/llvm": {} + "ghcr.io/devcontainers-community/features/llvm": {} } } ``` @@ -17,8 +17,8 @@ ### Options -- **`version`:** Choose a specific major toolchain version (like `13`). Can also - be `dev`. Default is `dev`. +Currently no options. If you'd like to add a `version` option, that'd be +awesome! ❤️ [this vs code blog post]: https://code.visualstudio.com/blogs/2022/09/15/dev-container-features diff --git a/common/etc/bash.bash_env b/common/etc/bash.bash_env deleted file mode 100644 index 42bc2a9..0000000 --- a/common/etc/bash.bash_env +++ /dev/null @@ -1,37 +0,0 @@ -#! /usr/bin/env bash - -# Respect --noprofile and --norc -if [[ ! $(ps -o args= -p $$) =~ (--noprofile) ]]; then - # Otherwise, initialize non-login shells like login shells - if ! shopt -q login_shell; then - if [ -f /etc/profile ]; then - . /etc/profile - fi - for x in "$HOME"/.{bash_profile,bash_login,profile}; do - if [ -f "$x" ]; then - . "$x" - break - fi - done - fi -elif [[ ! $(ps -o args= -p $$) =~ (--norc|--rcfile|--init-file) ]]; then - if [ -f /etc/bash.bashrc ]; then - . /etc/bash.bashrc - fi - for x in "$HOME"/.bashrc; do - if [ -f "$x" ]; then - . "$x" - break - fi - done -fi - -export BASH_ENV=/etc/bash.bash_env - -if [ -n "${BASH_ENV_ETC_PROFILE:-}" ]; then - if [ -f "$BASH_ENV_ETC_PROFILE" ] \ - && [ "$BASH_ENV_ETC_PROFILE" != "$BASH_ENV" ]; \ - then - . "$BASH_ENV_ETC_PROFILE" - fi -fi diff --git a/common/install.sh b/common/install.sh deleted file mode 100644 index 217d454..0000000 --- a/common/install.sh +++ /dev/null @@ -1,42 +0,0 @@ -#! /usr/bin/env bash -set -e - -if [ "$(id -u)" -ne 0 ]; then - echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' - exit 1 -fi - -src="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# export bash utility functions -source "$src/utilities.sh"; - -# install /etc/bash.bash_env -cp "$src/etc/bash.bash_env" /etc/; -chown root:root /etc/bash.bash_env; -chmod u+rwx,g+rwx,o+rx /etc/bash.bash_env; - -unset src; - -# Store and reset BASH_ENV in /etc/profile so lmod doesn't steal it from us. -# Our `/etc/bash.bash_env` will source lmod's $BASH_ENV at the end. -append_to_etc_profile "$(cat <> /etc/environment; -fi - -# Remove unnecessary "$HOME/.local/bin" at the end of the path -if grep -qxF 'if [[ "${PATH}" != *"$HOME/.local/bin"* ]]; then export PATH="${PATH}:$HOME/.local/bin"; fi' /etc/bash.bashrc; then - cat /etc/bash.bashrc \ - | grep -vxF 'if [[ "${PATH}" != *"$HOME/.local/bin"* ]]; then export PATH="${PATH}:$HOME/.local/bin"; fi' \ - > /etc/bash.bashrc.new \ -&& mv /etc/bash.bashrc{.new,}; -fi - -cp /etc/skel/.profile /root/.profile; -echo 'mesg n 2> /dev/null || true' >> /root/.profile; diff --git a/common/utilities.sh b/common/utilities.sh deleted file mode 100644 index c3ca21a..0000000 --- a/common/utilities.sh +++ /dev/null @@ -1,230 +0,0 @@ -#! /usr/bin/env bash - -# Define common shell functions - -# Run apt update if apt lists aren't populated -apt_get_update() { - if [ "$(find /var/lib/apt/lists -mindepth 1 | head -n1 | wc -l)" = "0" ]; then - echo "Running apt-get update..."; - apt-get update -y; - fi -} - -export -f apt_get_update; - -# Checks if packages are installed and installs them if not -check_packages() { - if ! dpkg -s "$@" > /dev/null 2>&1; then - apt_get_update; - echo "Installing packages: $@"; - DEBIAN_FRONTEND=noninteractive \ - apt-get -y install --no-install-recommends "$@"; - fi -} - -export -f check_packages; - -for_each_user_bashrc() { - # Update all bashrc files - find / /etc /home ${_REMOTE_USER_HOME} ${_CONTAINER_USER_HOME} -maxdepth 2 -type f -name .bashrc \ - | sort | uniq | xargs -r -d'\n' -n1 bash -c "${@}"; -} - -export -f for_each_user_bashrc; - -append_to_all_bashrcs() { - # Update all bashrc files - for bashrc in $(find / /etc /home ${_REMOTE_USER_HOME} ${_CONTAINER_USER_HOME} -maxdepth 2 -type f -name .bashrc | sort | uniq); do - if [[ "$(cat "$bashrc")" != *"$1"* ]]; then - echo "Appending to $bashrc..."; - echo -e "$1" >> "$bashrc"; - fi - done -} - -export -f append_to_all_bashrcs; - -prepend_to_all_bashrcs() { - # Update all bashrc files - for bashrc in $(find / /etc /home ${_REMOTE_USER_HOME} ${_CONTAINER_USER_HOME} -maxdepth 2 -type f -name .bashrc | sort | uniq); do - if [[ "$(cat "$bashrc")" != *"$1"* ]]; then - echo "Prepending to $bashrc..."; - echo -e "$1\n$(cat "$bashrc")" > "$bashrc"; - fi - done -} - -export -f prepend_to_all_bashrcs; - -append_to_etc_profile() { - if [[ "$(cat /etc/profile)" != *"$1"* ]]; then - echo "Appending to /etc/profile..."; - echo -e "$1" >> /etc/profile; - fi -} - -export -f append_to_etc_profile; - -prepend_to_etc_profile() { - if [[ "$(cat /etc/profile)" != *"$1"* ]]; then - echo "Prepending to /etc/profile..."; - echo -e "$1\n$(cat /etc/profile)" > /etc/profile; - fi -} - -export -f prepend_to_etc_profile; - -append_to_etc_bashrc() { - if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then - echo "Appending to /etc/bash.bashrc..."; - echo -e "$1" >> /etc/bash.bashrc; - fi -} - -export -f append_to_etc_bashrc; - -prepend_to_etc_bashrc() { - if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then - echo "Prepending to /etc/bash.bashrc..."; - echo -e "$1\n$(cat /etc/bash.bashrc)" > /etc/bash.bashrc; - fi -} - -export -f prepend_to_etc_bashrc; - -append_etc_zshrc() { - if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"$1"* ]]; then - echo "Appending to /etc/zsh/zshrc..."; - echo -e "$1" >> /etc/zsh/zshrc; - fi -} - -export -f append_etc_zshrc; - -prepend_to_etc_zshrc() { - if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"$1"* ]]; then - echo "Prepending to /etc/zsh/zshrc..."; - echo -e "$1\n$(cat /etc/zsh/zshrc)" > /etc/zsh/zshrc; - fi -} - -export -f prepend_to_etc_zshrc; - -add_etc_profile_d_script() { - local name="$(($(ls -1q /etc/profile.d/*.sh | wc -l) + 20))-${1}.sh"; - echo -e "#! /usr/bin/env bash\n${@:2}" > "/etc/profile.d/${name}"; - chmod +x "/etc/profile.d/${name}"; -} - -export -f add_etc_profile_d_script; - -# Figure out correct version of a three part version number is not passed -find_version_from_git_tags() { - check_packages git; - local variable_name=$1 - local requested_version=${!variable_name} - if [ "${requested_version}" = "none" ]; then return; fi - local repository=$2 - local prefix=${3:-"tags/v"} - local separator=${4:-"."} - local suffix=${5:-} - local last_part_optional=${6:-"false"} - if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then - local escaped_separator=${separator//./\\.} - local last_part= - if [ "${last_part_optional}" = "true" ]; then - last_part+="(${escaped_separator}[0-9]+)?" - last_part+="(${escaped_separator}[0-9]+)?" - if [ -n "${suffix}" ]; then - last_part+="(${suffix})?" - fi - else - last_part+="${escaped_separator}[0-9]+" - last_part+="${escaped_separator}[0-9]+" - if [ -n "${suffix}" ]; then - last_part+="(${suffix})" - fi - fi - local regex="${prefix}\\K[0-9]+${last_part}$" - local version_list="$(git ls-remote --tags ${repository} | grep -oP "${regex}" | tr -d ' ' | tr "${separator}" "." | sort -rV)" - if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ] || [ "${requested_version}" = "lts" ]; then - declare -g ${variable_name}="$(echo "${version_list}" | head -n 1)" - else - set +e - declare -g ${variable_name}="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")" - set -e - fi - fi - if [ -z "${!variable_name}" ] || ! echo "${version_list}" | grep "^${!variable_name//./\\.}$" > /dev/null 2>&1; then - echo -e "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2 - exit 1 - fi - echo "${variable_name}=${!variable_name}" -} - -export -f find_version_from_git_tags; - -# Use semver logic to decrement a version number then look for the closest match -find_prev_version_from_git_tags() { - local variable_name=$1 - local current_version=${!variable_name} - local repository=$2 - # Normally a "v" is used before the version number, but support alternate cases - local prefix=${3:-"tags/v"} - # Some repositories use "_" instead of "." for version number part separation, support that - local separator=${4:-"."} - # Some repositories may have tags that include a suffix (e.g. actions/node-versions) - local version_suffix_regex=${5:-} - # Some tools release versions that omit the last digit (e.g. go) - local last_part_optional=${6:-"false"} - # Try one break fix version number less if we get a failure. Use "set +e" since "set -e" can cause failures in valid scenarios. - set +e - major="$(echo "${current_version}" | grep -oE '^[0-9]+' || echo '')" - minor="$(echo "${current_version}" | grep -oP '^[0-9]+\.\K[0-9]+' || echo '')" - breakfix="$(echo "${current_version}" | grep -oP '^[0-9]+\.[0-9]+\.\K[0-9]+' 2>/dev/null || echo '')" - - if [ "${minor}" = "0" ] && [ "${breakfix}" = "0" ]; then - ((major=major-1)) - declare -g ${variable_name}="${major}" - # Look for latest version from previous major release - find_version_from_git_tags "${variable_name}" "${repository}" "${prefix}" "${separator}" "${version_suffix_regex}" "${last_part_optional}" - # Handle situations like Go's odd version pattern where "0" releases omit the last part - elif [ "${breakfix}" = "" ] || [ "${breakfix}" = "0" ]; then - ((minor=minor-1)) - declare -g ${variable_name}="${major}.${minor}" - # Look for latest version from previous minor release - find_version_from_git_tags "${variable_name}" "${repository}" "${prefix}" "${separator}" "${version_suffix_regex}" "${last_part_optional}" - else - ((breakfix=breakfix-1)) - if [ "${breakfix}" = "0" ] && [ "${last_part_optional}" = "true" ]; then - declare -g ${variable_name}="${major}.${minor}" - else - declare -g ${variable_name}="${major}.${minor}.${breakfix}" - fi - fi - set -e -} - -export -f find_prev_version_from_git_tags; - -# Determine the appropriate non-root user -find_non_root_user() { - USERNAME="${USERNAME:-"${_REMOTE_USER:-"auto"}"}"; - if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then - USERNAME="" - POSSIBLE_USERS=("vscode" "node" "codespace" "coder" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)") - for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do - if id -u ${CURRENT_USER} > /dev/null 2>&1; then - USERNAME=${CURRENT_USER} - break - fi - done - elif [ "${USERNAME}" = "none" ] || ! id -u "${USERNAME}" > /dev/null 2>&1; then - USERNAME=root - fi - if [ "${USERNAME}" = "" ]; then - USERNAME=root - fi -} - -export -f find_non_root_user; diff --git a/devcontainer-feature.json b/devcontainer-feature.json index cdcca3d..e10e77f 100644 --- a/devcontainer-feature.json +++ b/devcontainer-feature.json @@ -1,83 +1,12 @@ { - "name": "LLVM compilers and tools", "id": "llvm", - "version": "2.0.0", - "description": "A feature to install LLVM compilers and tools", - "options": { - "version": { - "type": "string", - "proposals": [ - "dev", - "17", - "16", - "15", - "14", - "13", - "12", - "11", - "10", - "9" - ], - "default": "dev", - "description": "LLVM version to install." - } - }, - "containerEnv": { - "BASH_ENV": "/etc/bash.bash_env" - }, - "capAdd": [ - "SYS_PTRACE" - ], - "securityOpt": [ - "seccomp=unconfined" - ], - "updateContentCommand": [ - "/bin/bash", - "-c", - "mkdir -m 0755 -p ~/.config/clangd && cp -n /etc/skel/.config/clangd/config.yaml ~/.config/clangd/config.yaml" - ], - "customizations": { - "vscode": { - "extensions": [ - "cschlosser.doxdocgen", - "llvm-vs-code-extensions.vscode-clangd", - "ms-vscode.cpptools", - "vadimcn.vscode-lldb", - "seaube.clangformat" - ], - "settings": { - "C_Cpp.vcpkg.enabled": false, - "C_Cpp.formatting": "disabled", - "C_Cpp.autocomplete": "disabled", - "C_Cpp.errorSquiggles": "disabled", - "C_Cpp.intelliSenseEngine": "disabled", - "C_Cpp.configurationWarnings": "disabled", - "C_Cpp.autoAddFileAssociations": false, - "clang-format.fallbackStyle": "none", - "clang-format.executable": "/usr/bin/clang-format", - "clangd.arguments": [ - "--log=info", - "--clang-tidy", - "--debug-origin", - "--pch-storage=disk", - "--use-dirty-headers", - "--background-index=true", - "--all-scopes-completion", - "--header-insertion=iwyu", - "--completion-parse=always", - "--completion-style=detailed", - "--header-insertion-decorators" - ], - "[c]": { - "editor.defaultFormatter": "seaube.clangformat" - }, - "[cpp]": { - "editor.defaultFormatter": "seaube.clangformat" - }, - "[cuda-cpp]": { - "editor.defaultFormatter": "seaube.clangformat" - } - } - } - } + "version": "3.0.0", + "name": "llvm", + "documentationURL": "https://github.com/devcontainers-community/features-llvm", + "description": "Installs llvm on debian based systems", + "options": {}, + "mounts": [], + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] } diff --git a/install.sh b/install.sh index bc9737f..485f1d3 100644 --- a/install.sh +++ b/install.sh @@ -1,96 +1,6 @@ -#! /usr/bin/env bash -set -ex +#!/usr/bin/env bash +set -e -# Ensure we're in this feature's directory during build -cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; +apt update && apt install lsb-release wget software-properties-common gnupg -y -qq -# install global/common scripts -. ./common/install.sh; - -LLVM_VERSION="${VERSION:-}"; - -check_packages \ - gpg \ - wget \ - apt-utils \ - lsb-release \ - gettext-base \ - bash-completion \ - ca-certificates \ - apt-transport-https \ - software-properties-common \ - ; - -if [[ -z "$LLVM_VERSION" \ - || "$LLVM_VERSION" == "latest" \ - || "$LLVM_VERSION" == "dev" \ - || "$LLVM_VERSION" == "pre" \ - || "$LLVM_VERSION" == "prerelease" \ -]]; then - LLVM_VERSION="latest"; - find_version_from_git_tags \ - LLVM_VERSION \ - https://github.com/llvm/llvm-project \ - "tags/llvmorg-" "." "-init" "true"; - LLVM_VERSION="$(echo $LLVM_VERSION | grep -oP '[0-9]+')"; -fi - -echo "Installing llmv-${LLVM_VERSION} compilers and tools"; - -./llvm.sh $LLVM_VERSION all; - -# # Remove existing cc/c++ alternatives -# (update-alternatives --remove-all cc >/dev/null 2>&1 || true); -# (update-alternatives --remove-all c++ >/dev/null 2>&1 || true); - -# # Install cc/c++ alternatives -# update-alternatives \ -# --install /usr/bin/cc cc $(which clang-${LLVM_VERSION}) 30 \ -# --slave /usr/bin/c++ c++ $(which clang++-${LLVM_VERSION}) \ -# ; - -# # Set default cc/c++ alternatives -# update-alternatives --set cc $(which clang-${LLVM_VERSION}); - -# Remove existing clang/llvm alternatives -(update-alternatives --remove-all clang >/dev/null 2>&1 || true); -(update-alternatives --remove-all clangd >/dev/null 2>&1 || true); -(update-alternatives --remove-all clang++ >/dev/null 2>&1 || true); -(update-alternatives --remove-all clang-format >/dev/null 2>&1 || true); -(update-alternatives --remove-all clang-tidy >/dev/null 2>&1 || true); -(update-alternatives --remove-all lldb >/dev/null 2>&1 || true); -(update-alternatives --remove-all llvm-config >/dev/null 2>&1 || true); -(update-alternatives --remove-all llvm-cov >/dev/null 2>&1 || true); - -# Install clang/llvm alternatives -update-alternatives \ - --install /usr/bin/clang clang $(which clang-${LLVM_VERSION}) 30 \ - --slave /usr/bin/clangd clangd $(which clangd-${LLVM_VERSION}) \ - --slave /usr/bin/clang++ clang++ $(which clang++-${LLVM_VERSION}) \ - --slave /usr/bin/clang-format clang-format $(which clang-format-${LLVM_VERSION}) \ - --slave /usr/bin/clang-tidy clang-tidy $(which clang-tidy-${LLVM_VERSION}) \ - --slave /usr/bin/lldb lldb $(which lldb-${LLVM_VERSION}) \ - --slave /usr/bin/llvm-config llvm-config $(which llvm-config-${LLVM_VERSION}) \ - --slave /usr/bin/llvm-cov llvm-cov $(which llvm-cov-${LLVM_VERSION}) \ - ; - -# Set default clang/llvm alternatives -update-alternatives --set clang $(which clang-${LLVM_VERSION}); - -export LLVM_VERSION="${LLVM_VERSION}"; - -# export envvars in bashrc files -append_to_etc_bashrc "$(cat .bashrc | envsubst)"; -append_to_all_bashrcs "$(cat .bashrc | envsubst)"; -# export envvars in /etc/profile.d -add_etc_profile_d_script llvm "$(cat .bashrc | envsubst)"; - -# Copy clangd config into etc/skel -mkdir -p -m 0755 /etc/skel/.config/clangd/; -cp .clangd /etc/skel/.config/clangd/config.yaml; - -# Clean up -# rm -rf /tmp/*; -rm -rf /var/tmp/*; -rm -rf /var/cache/apt/*; -rm -rf /var/lib/apt/lists/*; +bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" diff --git a/llvm.sh b/llvm.sh deleted file mode 100644 index 2017d69..0000000 --- a/llvm.sh +++ /dev/null @@ -1,192 +0,0 @@ -#!/bin/bash -################################################################################ -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -################################################################################ -# -# This script will install the llvm toolchain on the different -# Debian and Ubuntu versions - -set -eux - -usage() { - set +x - echo "Usage: $0 [llvm_major_version] [all] [OPTIONS]" 1>&2 - echo -e "all\t\t\tInstall all packages." 1>&2 - echo -e "-n=code_name\t\tSpecifies the distro codename, for example bionic" 1>&2 - echo -e "-h\t\t\tPrints this help." 1>&2 - echo -e "-m=repo_base_url\tSpecifies the base URL from which to download." 1>&2 - exit 1; -} - -CURRENT_LLVM_STABLE=17 -BASE_URL="http://apt.llvm.org" - -# Check for required tools -needed_binaries=(lsb_release wget add-apt-repository gpg) -missing_binaries=() -for binary in "${needed_binaries[@]}"; do - if ! which $binary >/dev/null 2>&1 ; then - missing_binaries+=($binary) - fi -done -if [[ ${#missing_binaries[@]} -gt 0 ]] ; then - echo "You are missing some tools this script requires: ${missing_binaries[@]}" - echo "(hint: apt install lsb-release wget software-properties-common gnupg)" - exit 4 -fi - -# Set default values for commandline arguments -# We default to the current stable branch of LLVM -LLVM_VERSION=$CURRENT_LLVM_STABLE -ALL=0 -DISTRO=$(lsb_release -is) -VERSION=$(lsb_release -sr) -UBUNTU_CODENAME="" -CODENAME_FROM_ARGUMENTS="" -# Obtain VERSION_CODENAME and UBUNTU_CODENAME (for Ubuntu and its derivatives) -source /etc/os-release -DISTRO=${DISTRO,,} -case ${DISTRO} in - debian) - if [[ "${VERSION}" == "unstable" ]] || [[ "${VERSION}" == "testing" ]] || [[ "${VERSION_CODENAME}" == "bookworm" ]]; then - # For now, bookworm == sid. - # TODO change when bookworm is released - CODENAME=unstable - LINKNAME= - else - # "stable" Debian release - CODENAME=${VERSION_CODENAME} - LINKNAME=-${CODENAME} - fi - ;; - *) - # ubuntu and its derivatives - if [[ -n "${UBUNTU_CODENAME}" ]]; then - CODENAME=${UBUNTU_CODENAME} - if [[ -n "${CODENAME}" ]]; then - LINKNAME=-${CODENAME} - fi - fi - ;; -esac - -# read optional command line arguments -if [ "$#" -ge 1 ] && [ "${1::1}" != "-" ]; then - if [ "$1" != "all" ]; then - LLVM_VERSION=$1 - else - # special case for ./llvm.sh all - ALL=1 - fi - OPTIND=2 - if [ "$#" -ge 2 ]; then - if [ "$2" == "all" ]; then - # Install all packages - ALL=1 - OPTIND=3 - fi - fi -fi - -while getopts ":hm:n:" arg; do - case $arg in - h) - usage - ;; - m) - BASE_URL=${OPTARG} - ;; - n) - CODENAME=${OPTARG} - if [[ "${CODENAME}" == "unstable" ]]; then - # link name does not apply to unstable repository - LINKNAME= - else - LINKNAME=-${CODENAME} - fi - CODENAME_FROM_ARGUMENTS="true" - ;; - esac -done - -if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root!" - exit 1 -fi - -declare -A LLVM_VERSION_PATTERNS -LLVM_VERSION_PATTERNS[9]="-9" -LLVM_VERSION_PATTERNS[10]="-10" -LLVM_VERSION_PATTERNS[11]="-11" -LLVM_VERSION_PATTERNS[12]="-12" -LLVM_VERSION_PATTERNS[13]="-13" -LLVM_VERSION_PATTERNS[14]="-14" -LLVM_VERSION_PATTERNS[15]="-15" -LLVM_VERSION_PATTERNS[16]="-16" -LLVM_VERSION_PATTERNS[17]="-17" -LLVM_VERSION_PATTERNS[18]="" - -if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then - echo "This script does not support LLVM version $LLVM_VERSION" - exit 3 -fi - -LLVM_VERSION_STRING=${LLVM_VERSION_PATTERNS[$LLVM_VERSION]} - -# join the repository name -if [[ -n "${CODENAME}" ]]; then - REPO_NAME="deb ${BASE_URL}/${CODENAME}/ llvm-toolchain${LINKNAME}${LLVM_VERSION_STRING} main" - - # check if the repository exists for the distro and version - if ! wget -q --method=HEAD ${BASE_URL}/${CODENAME} >/dev/null 2>&1; then - if [[ -n "${CODENAME_FROM_ARGUMENTS}" ]]; then - echo "Specified codename '${CODENAME}' is not supported by this script." - else - echo "Distribution '${DISTRO}' in version '${VERSION}' is not supported by this script." - fi - exit 2 - fi -fi - - -# install everything - -if [ ! -f /etc/apt/trusted.gpg.d/apt.llvm.org.asc ]; then - # download GPG key once - wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc -fi - -if [[ -z "`apt-key list 2> /dev/null | grep -i llvm`" ]]; then - # Delete the key in the old format - apt-key del AF4F7421 -fi - -cat <<"EOF" >> "/etc/apt/preferences.d/llvm-$LLVM_VERSION" -Package: * -Pin: origin *llvm.org* -Pin-Priority: 600 -EOF - -add-apt-repository -n -y "${REPO_NAME}" - -apt-get update - -PKG="clang-$LLVM_VERSION lldb-$LLVM_VERSION lld-$LLVM_VERSION clangd-$LLVM_VERSION" -if [[ $ALL -eq 1 ]]; then - # same as in test-install.sh - # No worries if we have dups - PKG="$PKG clang-tidy-$LLVM_VERSION clang-format-$LLVM_VERSION clang-tools-$LLVM_VERSION llvm-$LLVM_VERSION-dev lld-$LLVM_VERSION lldb-$LLVM_VERSION llvm-$LLVM_VERSION-tools libomp-$LLVM_VERSION-dev libc++-$LLVM_VERSION-dev libc++abi-$LLVM_VERSION-dev libclang-common-$LLVM_VERSION-dev libclang-$LLVM_VERSION-dev" - if test $LLVM_VERSION -gt 9; then - PKG="$PKG libclang-cpp$LLVM_VERSION-dev" - fi - if test $LLVM_VERSION -gt 11; then - PKG="$PKG libunwind-$LLVM_VERSION-dev" - fi - if test $LLVM_VERSION -gt 14; then - PKG="$PKG libclang-rt-$LLVM_VERSION-dev libpolly-$LLVM_VERSION-dev" - fi -fi - -apt-get install -y $PKG