Skip to content

Add support of version #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

### Options

Currently no options. If you'd like to add a `version` option, that'd be
awesome! ❤️
| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| version | LLVM version | string | latest |


<!-- prettier-ignore -->
[this vs code blog post]: https://code.visualstudio.com/blogs/2022/09/15/dev-container-features
14 changes: 13 additions & 1 deletion devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@
"name": "llvm",
"documentationURL": "https://github.com/devcontainers-community/features-llvm",
"description": "Installs llvm on debian based systems",
"options": {},
"options": {
"version": {
"type": "string",
"proposals": [
"latest",
"18",
"17",
"16"
],
"default": "latest",
"description": "LLVM version"
}
},
"mounts": [],
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
Expand Down
75 changes: 70 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,75 @@
#!/usr/bin/env bash
set -e

apt update && apt install lsb-release wget software-properties-common gnupg -y -qq
if [ "$VERSION" == "latest" ]; then
VERSION=
fi

bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
# Function to run apt-get if needed
apt_get_update_if_needed()
{
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update
else
echo "Skipping apt-get update."
fi
}

ln -s /usr/bin/clang-17 /usr/bin/clang
ln -s /usr/bin/clang++-17 /usr/bin/clang++
ln -s /usr/bin/lld-17 /usr/bin/lld
# Checks if packages are installed and installs them if not
check_packages() {
if ! dpkg -s "$@" > /dev/null 2>&1; then
apt_get_update_if_needed
apt-get -y install --no-install-recommends "$@"
fi
}

check_packages lsb-release wget software-properties-common gnupg

# Remove any previous LLVM that may be in the base image
# LLVM packages packaged by Ubuntu may get picked over us and
# cause problems later.
if dpkg -s llvm > /dev/null 2>&1; then
apt-get purge -y llvm && apt-get autoremove -y
fi

# Hack for apt-add-repository bug on Debian bookworm
# https://github.com/hof/bookworm-apt-add-repository-issue
if [ ! -f "/etc/apt/sources.list" ]; then
echo '#' > /etc/apt/sources.list
fi

cd /tmp
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
./llvm.sh $VERSION all
rm llvm.sh

# Remove downloads to keep Docker layer small
apt-get clean -y && rm -rf /var/lib/apt/lists/*

llvm_root_prefix=/usr/lib/llvm-

if [ -z $VERSION ]; then
# Detect the latest version if it is "latest".
llvm_latest_version=
for llvm in ${llvm_root_prefix}*; do
llvm_version=${llvm##$llvm_root_prefix}
if [ ! -f ${llvm_root_prefix}${llvm_version}/bin/llvm-config ]; then
continue
fi
if [[ -z $llvm_latest_version || llvm_version -gt llvm_latest_version ]]; then
llvm_latest_version=$llvm_version
fi
done
VERSION=$llvm_latest_version
fi

llvm_root=${llvm_root_prefix}${VERSION}

for bin in $llvm_root/bin/*; do
bin=$(basename $bin)
if [ -f /usr/bin/$bin-$VERSION ]; then
ln -sf /usr/bin/$bin-$VERSION /usr/bin/$bin
fi
done
Empty file modified test.sh
100644 → 100755
Empty file.