Skip to content

Commit 7344fd3

Browse files
committed
Add CMake, LLVM, and sccache feature installers with configuration options
1 parent 9660cdb commit 7344fd3

6 files changed

Lines changed: 162 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"id": "cmake",
3+
"version": "1.0.0",
4+
"name": "cmake",
5+
"description": "Installs CMake from Kitware's official GitHub release binaries (distro-agnostic), symlinking cmake/ctest/cpack/ccmake into /usr/local/bin. Supports x86_64 and aarch64.",
6+
"documentationURL": "https://github.com/SoureCode/devcontainer-features/tree/master/src/cmake",
7+
"options": {
8+
"version": {
9+
"type": "string",
10+
"default": "latest",
11+
"description": "CMake release to install. `latest` resolves to the most recent tag from Kitware/CMake GitHub releases. Otherwise a specific version like `3.30.5`."
12+
}
13+
}
14+
}

src/cmake/install.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
# cmake feature installer.
3+
# https://cmake.org/
4+
set -e
5+
6+
CMAKE_VERSION="${VERSION:-latest}"
7+
8+
if ! command -v curl >/dev/null 2>&1 || ! command -v tar >/dev/null 2>&1; then
9+
apt-get update
10+
apt-get install -y --no-install-recommends curl ca-certificates tar
11+
rm -rf /var/lib/apt/lists/*
12+
fi
13+
14+
if [ "$CMAKE_VERSION" = "latest" ]; then
15+
CMAKE_VERSION="$(curl -fsSL https://api.github.com/repos/Kitware/CMake/releases/latest \
16+
| sed -n 's/^.*"tag_name": *"v\([^"]*\)".*$/\1/p')"
17+
fi
18+
19+
ARCH="$(uname -m)"
20+
case "$ARCH" in
21+
x86_64) CM_ARCH=x86_64 ;;
22+
aarch64) CM_ARCH=aarch64 ;;
23+
*) echo "cmake feature: unsupported arch: $ARCH" >&2; exit 1 ;;
24+
esac
25+
26+
TMPDIR="$(mktemp -d)"
27+
trap 'rm -rf "$TMPDIR"' EXIT
28+
29+
curl -fsSL -o "$TMPDIR/cmake.tar.gz" \
30+
"https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-${CM_ARCH}.tar.gz"
31+
tar -xzf "$TMPDIR/cmake.tar.gz" -C "$TMPDIR"
32+
33+
INSTALL_DIR="/usr/local/cmake-${CMAKE_VERSION}"
34+
rm -rf "$INSTALL_DIR"
35+
mv "$TMPDIR/cmake-${CMAKE_VERSION}-linux-${CM_ARCH}" "$INSTALL_DIR"
36+
37+
for bin in cmake ctest cpack ccmake; do
38+
[ -x "$INSTALL_DIR/bin/$bin" ] || continue
39+
ln -sf "$INSTALL_DIR/bin/$bin" "/usr/local/bin/$bin"
40+
done

src/llvm/devcontainer-feature.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"id": "llvm",
3+
"version": "1.0.0",
4+
"name": "llvm",
5+
"description": "Installs LLVM / Clang on Debian / Ubuntu via the official apt.llvm.org repository. Major-version binaries (clang, clang++, lld, lldb, clangd, clang-format, clang-tidy, etc.) are symlinked into /usr/local/bin without the version suffix.",
6+
"documentationURL": "https://github.com/SoureCode/devcontainer-features/tree/master/src/llvm",
7+
"options": {
8+
"version": {
9+
"type": "string",
10+
"default": "22",
11+
"description": "LLVM major version to install. Passed directly to apt.llvm.org's llvm.sh."
12+
},
13+
"all": {
14+
"type": "boolean",
15+
"default": true,
16+
"description": "Install the full LLVM toolchain (clang, lld, lldb, libc++, polly, compiler-rt, …). Disable to get the default minimal set."
17+
}
18+
},
19+
"containerEnv": {
20+
"CC": "/usr/local/bin/clang",
21+
"CXX": "/usr/local/bin/clang++"
22+
}
23+
}

src/llvm/install.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
# llvm feature installer (uses apt.llvm.org's llvm.sh).
3+
# https://apt.llvm.org/
4+
set -e
5+
6+
LLVM_VERSION="${VERSION:-22}"
7+
LLVM_ALL="${ALL:-true}"
8+
9+
apt-get update
10+
apt-get install -y --no-install-recommends \
11+
ca-certificates curl gnupg lsb-release software-properties-common wget
12+
rm -rf /var/lib/apt/lists/*
13+
14+
TMPDIR="$(mktemp -d)"
15+
trap 'rm -rf "$TMPDIR"' EXIT
16+
17+
curl -fsSL -o "$TMPDIR/llvm.sh" https://apt.llvm.org/llvm.sh
18+
chmod +x "$TMPDIR/llvm.sh"
19+
20+
EXTRA_ARGS=()
21+
if [ "$LLVM_ALL" = "true" ]; then
22+
EXTRA_ARGS+=("all")
23+
fi
24+
25+
"$TMPDIR/llvm.sh" "$LLVM_VERSION" "${EXTRA_ARGS[@]}"
26+
27+
# Symlink versioned binaries to unsuffixed names so generic tooling finds them.
28+
for bin in \
29+
clang clang++ clang-cpp \
30+
clang-format clang-tidy clangd \
31+
lld ld.lld lld-link \
32+
lldb lldb-server \
33+
llvm-config llvm-symbolizer llvm-ar llvm-nm llvm-objdump llvm-objcopy \
34+
llvm-ranlib llvm-readelf llvm-strip llvm-cov llvm-profdata; do
35+
if [ -x "/usr/bin/${bin}-${LLVM_VERSION}" ]; then
36+
ln -sf "/usr/bin/${bin}-${LLVM_VERSION}" "/usr/local/bin/${bin}"
37+
fi
38+
done
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"id": "sccache",
3+
"version": "1.0.0",
4+
"name": "sccache",
5+
"description": "Installs Mozilla sccache from GitHub release binaries into /usr/local/bin. Distro-agnostic (musl-linked). Supports x86_64 and aarch64. Pair with SCCACHE_DIR / SCCACHE_CACHE_SIZE env vars in devcontainer.json to persist the cache across rebuilds.",
6+
"documentationURL": "https://github.com/SoureCode/devcontainer-features/tree/master/src/sccache",
7+
"options": {
8+
"version": {
9+
"type": "string",
10+
"default": "latest",
11+
"description": "sccache release to install. `latest` resolves to the most recent tag from mozilla/sccache GitHub releases. Otherwise a specific version like `0.8.2`."
12+
}
13+
}
14+
}

src/sccache/install.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
# sccache feature installer.
3+
# https://github.com/mozilla/sccache
4+
set -e
5+
6+
SCCACHE_VERSION="${VERSION:-latest}"
7+
8+
if ! command -v curl >/dev/null 2>&1 || ! command -v tar >/dev/null 2>&1; then
9+
apt-get update
10+
apt-get install -y --no-install-recommends curl ca-certificates tar
11+
rm -rf /var/lib/apt/lists/*
12+
fi
13+
14+
if [ "$SCCACHE_VERSION" = "latest" ]; then
15+
SCCACHE_VERSION="$(curl -fsSL https://api.github.com/repos/mozilla/sccache/releases/latest \
16+
| sed -n 's/^.*"tag_name": *"v\([^"]*\)".*$/\1/p')"
17+
fi
18+
19+
ARCH="$(uname -m)"
20+
case "$ARCH" in
21+
x86_64) SC_ARCH=x86_64-unknown-linux-musl ;;
22+
aarch64) SC_ARCH=aarch64-unknown-linux-musl ;;
23+
*) echo "sccache feature: unsupported arch: $ARCH" >&2; exit 1 ;;
24+
esac
25+
26+
TMPDIR="$(mktemp -d)"
27+
trap 'rm -rf "$TMPDIR"' EXIT
28+
29+
curl -fsSL -o "$TMPDIR/sccache.tar.gz" \
30+
"https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-${SC_ARCH}.tar.gz"
31+
tar -xzf "$TMPDIR/sccache.tar.gz" -C "$TMPDIR"
32+
33+
install -m 0755 "$TMPDIR/sccache-v${SCCACHE_VERSION}-${SC_ARCH}/sccache" /usr/local/bin/sccache

0 commit comments

Comments
 (0)