Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit 8f00ba8

Browse files
committed
missing script
1 parent d436aa4 commit 8f00ba8

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

scripts/install-sccache

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env bash
2+
3+
SCCACHE_VERSION="${SCCACHE_VERSION:-0.5.4}"
4+
SCCACHE_INSTALL_DIR="${SCCACHE_INSTALL_DIR:-$HOME/.cargo/bin}"
5+
6+
function .log() {
7+
echo "[sccache::installer]" "$@" >&2
8+
}
9+
10+
function .get_platform_triple() {
11+
# e.g. "linux"
12+
local os
13+
os="$(uname | tr '[:upper:]' '[:lower:]')"
14+
15+
# e.g. "x86_64"
16+
local platform
17+
platform="$(uname -p)"
18+
19+
if [[ "$os" == "linux" ]]; then
20+
echo "${platform}-unknown-${os}-musl"
21+
else
22+
.log "ERROR: Unsupported operating system ${os}"
23+
return 1
24+
fi
25+
}
26+
27+
function .get_download_url() {
28+
local triple
29+
triple="$(.get_platform_triple)"
30+
31+
local version
32+
version="${SCCACHE_VERSION}"
33+
34+
echo "https://github.com/mozilla/sccache/releases/download/v${version}/sccache-v${version}-${triple}.tar.gz"
35+
}
36+
37+
function .install_sccache() {
38+
local triple
39+
triple="$(.get_platform_triple)"
40+
41+
local version
42+
version="${SCCACHE_VERSION}"
43+
44+
local url
45+
url="$(.get_download_url)"
46+
47+
local tmpdir
48+
tmpdir="$(mktemp -d)"
49+
50+
local exec_file
51+
exec_file="sccache-v${version}-${triple}/sccache"
52+
53+
.log "Installing sccache ${version}..."
54+
55+
(
56+
cd "${tmpdir}" && \
57+
curl -fsSL "${url}" | tar xzf - --strip-components=1 "${exec_file}" && \
58+
install -m 0755 sccache "${SCCACHE_INSTALL_DIR}/sccache"
59+
)
60+
61+
if [ -d "${tmpdir}" ]; then
62+
rm -r "${tmpdir}"
63+
fi
64+
}
65+
66+
function .main() {
67+
local installed_version
68+
69+
if ! which sccache &>/dev/null ; then
70+
.log "sccache not found on PATH, installing requested version"
71+
.install_sccache
72+
else
73+
installed_version="$(sccache --version | awk '{print $2;}')"
74+
75+
if [[ "${installed_version}" != "${SCCACHE_VERSION}" ]]; then
76+
.log "Currently installed version (${installed_version} does not match requested version ${SCCACHE_VERSION}, reinstalling sccache"
77+
.install_sccache
78+
else
79+
.log "Installed version is up to date with requested version, nothing to do"
80+
fi
81+
fi
82+
}
83+
84+
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
85+
set -euo pipefail
86+
.main "$@"
87+
fi

0 commit comments

Comments
 (0)