From fbbadce830c02bebd06796e2dceb046889e8872a Mon Sep 17 00:00:00 2001
From: Mateusz Rajski <mateusz.rajski@swmansion.com>
Date: Thu, 6 Nov 2025 12:57:21 +0100
Subject: [PATCH 1/3] feat: add ccache support in clean command

---
 packages/cli/src/lib/plugins/clean.ts | 32 ++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/packages/cli/src/lib/plugins/clean.ts b/packages/cli/src/lib/plugins/clean.ts
index 2d28228cc..30b229326 100644
--- a/packages/cli/src/lib/plugins/clean.ts
+++ b/packages/cli/src/lib/plugins/clean.ts
@@ -31,6 +31,7 @@ const CLEANUP_TASK_NAMES = [
   'android',
   'gradle',
   'cocoapods',
+  'ccache',
   'metro',
   'watchman',
   'node_modules',
@@ -97,6 +98,20 @@ function hasMetroProject(projectRoot: string): boolean {
   return false;
 }
 
+/**
+ * Checks if ccache is installed on the system.
+ * @returns Promise that resolves to true if ccache is available, false otherwise
+ */
+async function hasCCacheInstalled(): Promise<boolean> {
+  try {
+    await spawn('sh', ['-c', 'command -v ccache']);
+    return true;
+  } catch (error) {
+    logger.debug(`Failed to find ccache binary: ${error}`);
+    return false;
+  }
+}
+
 /**
  * Cleans temporary directories that match a given pattern.
  * @param pattern - The pattern to match temporary directory names
@@ -135,10 +150,10 @@ function cleanDirectories(directories: string[], baseDir: string): void {
  * @param options - Clean options that affect task creation
  * @returns Array of cleanup tasks with their configurations
  */
-function createCleanupTasks(
+async function createCleanupTasks(
   projectRoot: string,
   options: CleanOptions,
-): CleanupTask[] {
+): Promise<CleanupTask[]> {
   const tasks: CleanupTask[] = [];
 
   // Android cleanup
@@ -207,6 +222,17 @@ function createCleanupTasks(
     },
   });
 
+  const hasCCache = await hasCCacheInstalled();
+  // CCache cleanup (only if ccache is installed)
+  tasks.push({
+    name: 'ccache',
+    description: '[C/C++] CCache compiler cache',
+    enabled: hasCCache,
+    action: async () => {
+      await spawn('ccache', ['--clear']);
+    },
+  });
+
   // Watchman cleanup (only for Metro projects)
   const hasMetro = hasMetroProject(projectRoot);
   tasks.push({
@@ -302,7 +328,7 @@ function createCleanupTasks(
  * @param options - Clean options that determine which tasks to run
  */
 async function cleanProject(projectRoot: string, options: CleanOptions) {
-  const tasks = createCleanupTasks(projectRoot, options);
+  const tasks = await createCleanupTasks(projectRoot, options);
 
   let selectedTasks: CleanupTask[];
   const availableTasks = tasks.filter((task) => task.enabled);

From 05984491837d6d66b6039a50cf90220dde01accd Mon Sep 17 00:00:00 2001
From: Mateusz Rajski <mateusz.rajski@swmansion.com>
Date: Fri, 7 Nov 2025 14:10:07 +0100
Subject: [PATCH 2/3] fix: use which instead of command to support all
 platforms

---
 packages/cli/src/lib/plugins/clean.ts | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/packages/cli/src/lib/plugins/clean.ts b/packages/cli/src/lib/plugins/clean.ts
index 30b229326..bbfcc62b6 100644
--- a/packages/cli/src/lib/plugins/clean.ts
+++ b/packages/cli/src/lib/plugins/clean.ts
@@ -102,9 +102,9 @@ function hasMetroProject(projectRoot: string): boolean {
  * Checks if ccache is installed on the system.
  * @returns Promise that resolves to true if ccache is available, false otherwise
  */
-async function hasCCacheInstalled(): Promise<boolean> {
+async function isCCacheInstalled(): Promise<boolean> {
   try {
-    await spawn('sh', ['-c', 'command -v ccache']);
+    await spawn('which', ['ccache']);
     return true;
   } catch (error) {
     logger.debug(`Failed to find ccache binary: ${error}`);
@@ -222,7 +222,7 @@ async function createCleanupTasks(
     },
   });
 
-  const hasCCache = await hasCCacheInstalled();
+  const hasCCache = await isCCacheInstalled();
   // CCache cleanup (only if ccache is installed)
   tasks.push({
     name: 'ccache',

From 235188be6e5ed26fae2cba5600678b3bd1d75815 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= <thymikee@gmail.com>
Date: Fri, 14 Nov 2025 10:58:19 +0000
Subject: [PATCH 3/3] add changeset

---
 .changeset/long-dolls-juggle.md | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 .changeset/long-dolls-juggle.md

diff --git a/.changeset/long-dolls-juggle.md b/.changeset/long-dolls-juggle.md
new file mode 100644
index 000000000..ada836653
--- /dev/null
+++ b/.changeset/long-dolls-juggle.md
@@ -0,0 +1,6 @@
+---
+'rock': patch
+'create-rock': patch
+---
+
+feat: add ccache support in clean command
