Skip to content

Commit

Permalink
Merge pull request #5 from 0xE1E10/main
Browse files Browse the repository at this point in the history
Add support of version
  • Loading branch information
0xE1E10 authored Dec 15, 2023
2 parents 578e99a + 387f77b commit 510c964
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 8 deletions.
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.

0 comments on commit 510c964

Please sign in to comment.