Skip to content

Commit 053ced9

Browse files
authored
[BUILD] Build with ccache by default if available (#5076)
It's a bit annoying to have to remember to pass `TRITON_BUILD_WITH_CCACHE` every time you invoke `pip install`. This changes the default to check if ccache is installed and use it if it's found, with the option to manually disable ccache if it's not wanted for some reason.
1 parent c802bb4 commit 053ced9

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

CMakeLists.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ set(CMAKE_CXX_STANDARD 17)
1212

1313
set(CMAKE_INCLUDE_CURRENT_DIR ON)
1414

15-
project(triton)
15+
project(triton CXX)
1616
include(CTest)
1717

1818
if(NOT WIN32)
@@ -26,8 +26,25 @@ option(TRITON_BUILD_TUTORIALS "Build C++ Triton tutorials" ON)
2626
option(TRITON_BUILD_PYTHON_MODULE "Build Python Triton bindings" OFF)
2727
option(TRITON_BUILD_PROTON "Build the Triton Proton profiler" ON)
2828
option(TRITON_BUILD_UT "Build C++ Triton Unit Tests" ON)
29+
option(TRITON_BUILD_WITH_CCACHE "Build with ccache (if available)" ON)
2930
set(TRITON_CODEGEN_BACKENDS "" CACHE STRING "Enable different codegen backends")
3031

32+
if(TRITON_BUILD_WITH_CCACHE)
33+
find_program(CCACHE_PROGRAM ccache)
34+
if(CCACHE_PROGRAM)
35+
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}"
36+
CACHE STRING "C compiler launcher")
37+
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}"
38+
CACHE STRING "CXX compiler launcher")
39+
else()
40+
message(
41+
STATUS
42+
"Could not find ccache. Consider installing ccache to speed up compilation."
43+
)
44+
endif()
45+
endif()
46+
47+
3148
# Ensure Python3 vars are set correctly
3249
# used conditionally in this file and by lit tests
3350

python/setup.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,16 @@ def build_extension(self, ext):
460460
"-DCMAKE_CXX_FLAGS=-fsanitize=address",
461461
]
462462

463-
if check_env_flag("TRITON_BUILD_WITH_CCACHE"):
464-
cmake_args += [
465-
"-DCMAKE_CXX_COMPILER_LAUNCHER=ccache",
466-
]
463+
# environment variables we will pass through to cmake
464+
passthrough_args = [
465+
"TRITON_BUILD_PROTON",
466+
"TRITON_BUILD_TUTORIALS",
467+
"TRITON_BUILD_WITH_CCACHE",
468+
]
469+
cmake_args += [f"-D{option}={os.getenv(option)}" for option in passthrough_args if option in os.environ]
467470

468471
if check_env_flag("TRITON_BUILD_PROTON", "ON"): # Default ON
469472
cmake_args += self.get_proton_cmake_args()
470-
else:
471-
cmake_args += ["-DTRITON_BUILD_PROTON=OFF"]
472473

473474
if is_offline_build():
474475
# unit test builds fetch googletests from GitHub

0 commit comments

Comments
 (0)