Skip to content

Commit 510c964

Browse files
authored
Merge pull request #5 from 0xE1E10/main
Add support of version
2 parents 578e99a + 387f77b commit 510c964

File tree

4 files changed

+87
-8
lines changed

4 files changed

+87
-8
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
### Options
1919

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

2325
<!-- prettier-ignore -->
2426
[this vs code blog post]: https://code.visualstudio.com/blogs/2022/09/15/dev-container-features

devcontainer-feature.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@
44
"name": "llvm",
55
"documentationURL": "https://github.com/devcontainers-community/features-llvm",
66
"description": "Installs llvm on debian based systems",
7-
"options": {},
7+
"options": {
8+
"version": {
9+
"type": "string",
10+
"proposals": [
11+
"latest",
12+
"18",
13+
"17",
14+
"16"
15+
],
16+
"default": "latest",
17+
"description": "LLVM version"
18+
}
19+
},
820
"mounts": [],
921
"installsAfter": [
1022
"ghcr.io/devcontainers/features/common-utils"

install.sh

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,75 @@
11
#!/usr/bin/env bash
22
set -e
33

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

6-
bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
8+
# Function to run apt-get if needed
9+
apt_get_update_if_needed()
10+
{
11+
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
12+
echo "Running apt-get update..."
13+
apt-get update
14+
else
15+
echo "Skipping apt-get update."
16+
fi
17+
}
718

8-
ln -s /usr/bin/clang-17 /usr/bin/clang
9-
ln -s /usr/bin/clang++-17 /usr/bin/clang++
10-
ln -s /usr/bin/lld-17 /usr/bin/lld
19+
# Checks if packages are installed and installs them if not
20+
check_packages() {
21+
if ! dpkg -s "$@" > /dev/null 2>&1; then
22+
apt_get_update_if_needed
23+
apt-get -y install --no-install-recommends "$@"
24+
fi
25+
}
26+
27+
check_packages lsb-release wget software-properties-common gnupg
28+
29+
# Remove any previous LLVM that may be in the base image
30+
# LLVM packages packaged by Ubuntu may get picked over us and
31+
# cause problems later.
32+
if dpkg -s llvm > /dev/null 2>&1; then
33+
apt-get purge -y llvm && apt-get autoremove -y
34+
fi
35+
36+
# Hack for apt-add-repository bug on Debian bookworm
37+
# https://github.com/hof/bookworm-apt-add-repository-issue
38+
if [ ! -f "/etc/apt/sources.list" ]; then
39+
echo '#' > /etc/apt/sources.list
40+
fi
41+
42+
cd /tmp
43+
wget https://apt.llvm.org/llvm.sh
44+
chmod +x llvm.sh
45+
./llvm.sh $VERSION all
46+
rm llvm.sh
47+
48+
# Remove downloads to keep Docker layer small
49+
apt-get clean -y && rm -rf /var/lib/apt/lists/*
50+
51+
llvm_root_prefix=/usr/lib/llvm-
52+
53+
if [ -z $VERSION ]; then
54+
# Detect the latest version if it is "latest".
55+
llvm_latest_version=
56+
for llvm in ${llvm_root_prefix}*; do
57+
llvm_version=${llvm##$llvm_root_prefix}
58+
if [ ! -f ${llvm_root_prefix}${llvm_version}/bin/llvm-config ]; then
59+
continue
60+
fi
61+
if [[ -z $llvm_latest_version || llvm_version -gt llvm_latest_version ]]; then
62+
llvm_latest_version=$llvm_version
63+
fi
64+
done
65+
VERSION=$llvm_latest_version
66+
fi
67+
68+
llvm_root=${llvm_root_prefix}${VERSION}
69+
70+
for bin in $llvm_root/bin/*; do
71+
bin=$(basename $bin)
72+
if [ -f /usr/bin/$bin-$VERSION ]; then
73+
ln -sf /usr/bin/$bin-$VERSION /usr/bin/$bin
74+
fi
75+
done

test.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)