-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathsccache.py
More file actions
62 lines (51 loc) · 2.22 KB
/
Copy pathsccache.py
File metadata and controls
62 lines (51 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
# -- stdlib --
import os
import platform
from .cmake import cmake_args
# -- third party --
# -- own --
from .dep import download_dep
from .misc import banner, get_cache_home
from .tinysh import Command, sh
# -- code --
@banner("Setup sccache")
def setup_sccache() -> Command:
"""
Download and install sccache, setup compiler wrappers, and return the `sccache` command.
"""
root = get_cache_home() / "sccache-v041"
bin = root / "bin"
u = platform.uname()
if u.system in ("Linux", "Darwin"):
exe = bin / "sccache"
elif u.system == "Windows":
exe = bin / "sccache.exe"
else:
raise RuntimeError(f"Unsupported platform: {u.system} {u.machine}")
if not exe.exists():
if (u.system, u.machine) == ("Linux", "x86_64"):
url = "https://github.com/mozilla/sccache/releases/download/v0.10.0/sccache-v0.10.0-x86_64-unknown-linux-musl.tar.gz"
elif (u.system, u.machine) in (("Linux", "arm64"), ("Linux", "aarch64")):
url = "https://github.com/mozilla/sccache/releases/download/v0.10.0/sccache-v0.10.0-aarch64-unknown-linux-musl.tar.gz"
elif (u.system, u.machine) == ("Darwin", "arm64"):
url = "https://github.com/mozilla/sccache/releases/download/v0.10.0/sccache-v0.10.0-aarch64-apple-darwin.tar.gz"
elif (u.system, u.machine) == ("Darwin", "x86_64"):
url = "https://github.com/mozilla/sccache/releases/download/v0.10.0/sccache-v0.10.0-x86_64-apple-darwin.tar.gz"
elif u.system == "Windows":
url = "https://github.com/mozilla/sccache/releases/download/v0.10.0/sccache-v0.10.0-x86_64-pc-windows-msvc.tar.gz"
else:
raise RuntimeError(f"Unsupported platform: {u.system} {u.machine}")
download_dep(url, bin, strip=1)
exe.chmod(0o755)
os.environ["SCCACHE_LOG"] = "error"
exepath = str(exe).replace("\\", "\\\\")
cmake_args["CMAKE_C_COMPILER_LAUNCHER"] = exepath
cmake_args["CMAKE_CXX_COMPILER_LAUNCHER"] = exepath
# <LocalCache>
cache = root / "cache"
cache.mkdir(parents=True, exist_ok=True)
os.environ["SCCACHE_DIR"] = str(cache)
os.environ["SCCACHE_CACHE_SIZE"] = "40G"
# </LocalCache>
return sh.bake(str(exe))