Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ announce_configured_options(CMAKE_TOOLCHAIN_FILE)
load_build_preset()
include(${PROJECT_SOURCE_DIR}/tools/cmake/preset/default.cmake)

# Enable ccache if available
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
message(STATUS "ccache found and enabled for faster builds")
else()
message(STATUS "ccache not found, builds will not be cached")
endif()
announce_configured_options(CCACHE_PROGRAM)

# Print all the configs that were called with announce_configured_options.
print_configured_options()

Expand Down
28 changes: 28 additions & 0 deletions docs/source/using-executorch-building-from-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Windows (x86_64)
* `g++` version 7 or higher, `clang++` version 5 or higher, or another
C++17-compatible toolchain.
* `python` version 3.10-3.12
* `ccache` (optional) - A compiler cache that speeds up recompilation

Note that the cross-compilable core runtime code supports a wider range of
toolchains, down to C++17. See the [Runtime Overview](runtime-overview.md) for
Expand Down Expand Up @@ -119,6 +120,8 @@ Or alternatively, [install conda on your machine](https://conda.io/projects/cond
> git submodule sync
> git submodule update --init --recursive
> ```
>
> The `--clean` command removes build artifacts, pip outputs, and also clears the ccache if it's installed, ensuring a completely fresh build environment.

## Build ExecuTorch C++ runtime from source

Expand Down Expand Up @@ -171,6 +174,29 @@ To further optimize the release build for size, use both:
-DEXECUTORCH_OPTIMIZE_SIZE=ON
```

#### Compiler Cache (ccache)

ExecuTorch automatically detects and enables [ccache](https://ccache.dev/) if it's installed on your system. This significantly speeds up recompilation by caching previously compiled objects:

- If ccache is detected, you'll see: `ccache found and enabled for faster builds`
- If ccache is not installed, you'll see: `ccache not found, builds will not be cached`

To install ccache:
```bash
# Ubuntu/Debian
sudo apt install ccache

# macOS
brew install ccache

# CentOS/RHEL
sudo yum install ccache
# or
sudo dnf install ccache
```

No additional configuration is needed - the build system will automatically use ccache when available.

See [CMakeLists.txt](https://github.com/pytorch/executorch/blob/main/CMakeLists.txt)

### Build the runtime components
Expand All @@ -190,6 +216,8 @@ cd executorch
cmake --build cmake-out -j9
```

> **_TIP:_** For faster rebuilds, consider installing ccache (see [Compiler Cache section](#compiler-cache-ccache) above). On first builds, ccache populates its cache. Subsequent builds with the same compiler flags can be significantly faster.

## Use an example binary `executor_runner` to execute a .pte file

First, generate a .pte file, either by exporting an example model or following
Expand Down
13 changes: 13 additions & 0 deletions install_executorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ def clean():
shutil.rmtree(d, ignore_errors=True)
print("Cleaning buck-out/...")
shutil.rmtree("buck-out/", ignore_errors=True)

# Clean ccache if available
try:
result = subprocess.run(["ccache", "--version"], capture_output=True, text=True)
if result.returncode == 0:
print("Cleaning ccache...")
subprocess.run(["ccache", "--clear"], check=True)
print("ccache cleared successfully.")
else:
print("ccache not found, skipping ccache cleanup.")
except (subprocess.CalledProcessError, FileNotFoundError):
print("ccache not found, skipping ccache cleanup.")

print("Done cleaning build artifacts.")


Expand Down
Loading