Skip to content

Commit ded1e7e

Browse files
committed
New ccache binary recipe
1 parent 531faad commit ded1e7e

File tree

8 files changed

+183
-61
lines changed

8 files changed

+183
-61
lines changed

.gitignore

Lines changed: 44 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
1-
# Byte-compiled / optimized / DLL files
1+
# Conan specific
2+
**/test_package/build/
3+
**/test_package/build-*/
4+
**/test_package/test_output/
5+
conan.lock
6+
conanbuildinfo.cmake
7+
conanbuildinfo.txt
8+
conaninfo.txt
9+
graph_info.json
10+
build/
11+
.conanrunner/
12+
.conanrc
13+
14+
# CMake
15+
CMakeUserPresets.json
16+
17+
# IDEs
18+
.idea
19+
.vs
20+
.vscode
21+
.project
22+
.pydevproject
23+
.settings/
24+
.ropeproject/
25+
.devcontainer/
26+
## emacs
27+
*~
28+
29+
# Byte-compiled / optimized / DLL files / Cache
230
__pycache__/
31+
**/test_package/__pycache__/
32+
*.pyc
333
*.py[cod]
434
*$py.class
35+
tmp/
36+
.DS_Store
537

638
# C extensions
739
*.so
@@ -20,7 +52,6 @@ parts/
2052
sdist/
2153
var/
2254
wheels/
23-
share/python-wheels/
2455
*.egg-info/
2556
.installed.cfg
2657
*.egg
@@ -39,17 +70,14 @@ pip-delete-this-directory.txt
3970
# Unit test / coverage reports
4071
htmlcov/
4172
.tox/
42-
.nox/
4373
.coverage
4474
.coverage.*
4575
.cache
4676
nosetests.xml
4777
coverage.xml
4878
*.cover
49-
*.py,cover
5079
.hypothesis/
5180
.pytest_cache/
52-
cover/
5381

5482
# Translations
5583
*.mo
@@ -59,7 +87,6 @@ cover/
5987
*.log
6088
local_settings.py
6189
db.sqlite3
62-
db.sqlite3-journal
6390

6491
# Flask stuff:
6592
instance/
@@ -72,49 +99,16 @@ instance/
7299
docs/_build/
73100

74101
# PyBuilder
75-
.pybuilder/
76102
target/
77103

78104
# Jupyter Notebook
79105
.ipynb_checkpoints
80106

81-
# IPython
82-
profile_default/
83-
ipython_config.py
84-
85107
# pyenv
86-
# For a library or package, you might want to ignore these files since the code is
87-
# intended to run in multiple environments; otherwise, check them in:
88-
# .python-version
89-
90-
# pipenv
91-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94-
# install all needed dependencies.
95-
#Pipfile.lock
96-
97-
# poetry
98-
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99-
# This is especially recommended for binary packages to ensure reproducibility, and is more
100-
# commonly ignored for libraries.
101-
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102-
#poetry.lock
103-
104-
# pdm
105-
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106-
#pdm.lock
107-
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108-
# in version control.
109-
# https://pdm.fming.dev/#use-with-ide
110-
.pdm.toml
111-
112-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113-
__pypackages__/
114-
115-
# Celery stuff
108+
.python-version
109+
110+
# celery beat schedule file
116111
celerybeat-schedule
117-
celerybeat.pid
118112

119113
# SageMath parsed files
120114
*.sage.py
@@ -132,29 +126,18 @@ venv.bak/
132126
.spyderproject
133127
.spyproject
134128

135-
# Rope project settings
136-
.ropeproject
137-
138129
# mkdocs documentation
139130
/site
140131

141132
# mypy
142133
.mypy_cache/
143-
.dmypy.json
144-
dmypy.json
145-
146-
# Pyre type checker
147-
.pyre/
148-
149-
# pytype static type analyzer
150-
.pytype/
151134

152-
# Cython debug symbols
153-
cython_debug/
135+
# scons build files
136+
*.dblite
154137

155-
# PyCharm
156-
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157-
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158-
# and can be added to the global gitignore or merged into this file. For a more nuclear
159-
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160-
#.idea/
138+
# vim temp files
139+
.*.sw?
140+
.sw?
141+
Session.vim
142+
*~
143+
.undodir
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
include_guard()
2+
3+
# Enable cache if available
4+
set(CACHE_OPTION "ccache" CACHE STRING "Compiler cache to be used")
5+
set(CACHE_OPTION_VALUES "ccache" "sccache")
6+
set(CCACHE_ARGS "base_dir=<CONAN_HOME>;hash_dir=false")
7+
set_property(CACHE CACHE_OPTION PROPERTY STRINGS ${CACHE_OPTION_VALUES})
8+
list(FIND CACHE_OPTION_VALUES ${CACHE_OPTION} CACHE_OPTION_INDEX)
9+
10+
if(${CACHE_OPTION_INDEX} EQUAL -1)
11+
message(
12+
STATUS
13+
"Using custom compiler cache system: '${CACHE_OPTION}', explicitly supported entries are ${CACHE_OPTION_VALUES}"
14+
)
15+
endif()
16+
17+
find_program(CACHE_BINARY NAMES ${CACHE_OPTION_VALUES})
18+
if(CACHE_BINARY)
19+
message(STATUS "${CACHE_BINARY} found and enabled")
20+
set(CMAKE_CXX_COMPILER_LAUNCHER "${CACHE_BINARY};${CCACHE_ARGS}" CACHE FILEPATH "CXX compiler cache used")
21+
set(CMAKE_C_COMPILER_LAUNCHER "${CACHE_BINARY};${CCACHE_ARGS}" CACHE FILEPATH "C compiler cache used")
22+
else()
23+
message(WARNING "${CACHE_OPTION} is enabled but was not found. Not using it")
24+
endif()
25+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sources:
2+
"4.10.2":
3+
Linux:
4+
x86_64:
5+
url: "https://github.com/ccache/ccache/releases/download/v4.10.2/ccache-4.10.2-linux-x86_64.tar.xz"
6+
sha256: "80cab87bd510eca796467aee8e663c398239e0df1c4800a0b5dff11dca0b4f18"
7+
Macos:
8+
universal:
9+
url: "https://github.com/ccache/ccache/releases/download/v4.10.2/ccache-4.10.2-darwin.tar.gz"
10+
sha256: "d90514fff15943a8607e84e3f42d45f823915a92f99984f3fc88202f6295d1e8"
11+
Windows:
12+
x86_64:
13+
url: "https://github.com/ccache/ccache/releases/download/v4.10.2/ccache-4.10.2-windows-x86_64.zip"
14+
sha256: "6252f081876a9a9f700fae13a5aec5d0d486b28261d7f1f72ac11c7ad9df4da9"

recipes/ccache/binary/conanfile.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import os
2+
from pathlib import Path
3+
4+
from conan import ConanFile
5+
from conan.errors import ConanInvalidConfiguration
6+
from conan.tools.files import get, copy, replace_in_file
7+
8+
required_conan_version = ">=2.7"
9+
10+
AUTOIJECT_CMAKE = "ccache-autoinject.cmake"
11+
12+
class CcacheConan(ConanFile):
13+
name = "ccache"
14+
package_type = "application"
15+
description = (
16+
"Ccache (or “ccache”) is a compiler cache. It speeds up recompilation "
17+
"by caching previous compilations and detecting when the same "
18+
"compilation is being done again."
19+
)
20+
license = "GPL-3.0-or-later"
21+
topics = ("compiler-cache", "recompilation", "cache", "compiler")
22+
homepage = "https://ccache.dev"
23+
url = "https://github.com/conan-io/conan-center-index"
24+
settings = "os", "arch"
25+
exports_sources = [AUTOIJECT_CMAKE]
26+
27+
def validate(self):
28+
if self.settings.os != "Macos" and self.settings.arch != "x86_64":
29+
raise ConanInvalidConfiguration("ccache binaries are only provided for x86_64 architectures")
30+
31+
def build(self):
32+
arch = str(self.settings.arch) if self.settings.os != "Macos" else "universal"
33+
get(self, **self.conan_data["sources"][self.version][str(self.settings.os)][arch],
34+
destination=self.source_folder, strip_root=True)
35+
36+
def package_id(self):
37+
if self.info.settings.os == "Macos":
38+
del self.info.settings.arch
39+
40+
def package(self):
41+
copy(self, "*GPL-*.txt", src=self.build_folder, dst=os.path.join(self.package_folder, "licenses"))
42+
copy(self, "LICENSE.*", src=self.build_folder, dst=os.path.join(self.package_folder, "licenses"))
43+
copy(self, "ccache", src=self.build_folder, dst=os.path.join(self.package_folder, "bin"))
44+
copy(self, AUTOIJECT_CMAKE, src=self.build_folder, dst=self.package_folder)
45+
46+
def finalize(self):
47+
copy(self, "*", src=self.immutable_package_folder, dst=self.package_folder)
48+
# TODO: find a way of retrieving conan home without accessing private API
49+
# replace_in_file(self, os.path.join(self.package_folder, AUTOIJECT_CMAKE), "<CONAN_HOME>", self._conan_helpers.cache.store)
50+
replace_in_file(self, os.path.join(self.package_folder, AUTOIJECT_CMAKE), "<CONAN_HOME>", str(Path.home()))
51+
52+
def package_info(self):
53+
self.cpp_info.libdirs = []
54+
self.cpp_info.includedirs = []
55+
if self.conf.get("user.ccache:auto_inject", default=True, check_type=bool):
56+
self.conf_info.append("tools.cmake.cmaketoolchain:user_toolchain", os.path.join(self.package_folder, AUTOIJECT_CMAKE))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(test_package LANGUAGES CXX)
3+
4+
add_executable(${PROJECT_NAME} test_package.cpp)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
from conan import ConanFile
3+
from conan.tools.build import can_run
4+
from conan.tools.cmake import CMake, cmake_layout
5+
from conan.errors import ConanException
6+
7+
8+
class TestPackageConan(ConanFile):
9+
settings = "os", "arch", "compiler", "build_type"
10+
generators = "CMakeToolchain"
11+
12+
def build_requirements(self):
13+
self.tool_requires(self.tested_reference_str)
14+
15+
def test(self):
16+
generated_file = os.path.join(self.dependencies.build[self.tested_reference_str].package_folder, "ccache-autoinject.cmake")
17+
if not os.path.exists(generated_file):
18+
raise ConanException("ccache-autoinject.cmake toolchain file does not exist")
19+
user_toolchain = self.conf.get("tools.cmake.cmaketoolchain:user_toolchain", check_type=list)
20+
if generated_file not in user_toolchain:
21+
raise ConanException("ccache not found in user toolchain")
22+
23+
if can_run(self):
24+
self.run("ccache --version", env="conanbuild")
25+
26+
def layout(self):
27+
cmake_layout(self)
28+
29+
def build(self):
30+
cmake = CMake(self)
31+
cmake.configure()
32+
cmake.build()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <iostream>
2+
3+
int main() {
4+
std::cout << "Hello world!\n";
5+
}

recipes/ccache/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
versions:
2+
"4.10.2":
3+
folder: binary

0 commit comments

Comments
 (0)