Skip to content

Commit

Permalink
feat(cli): add Ccache support
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Oct 1, 2024
1 parent 52d0318 commit 6b942ec
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-mayflies-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rnx-kit/cli": patch
---

Add Ccache support
15 changes: 0 additions & 15 deletions .github/actions/setup-toolchain/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,6 @@ runs:
run: |
podfile_lock="packages/test-app/${{ inputs.platform }}/Podfile.lock"
if [[ -f $(git rev-parse --show-toplevel)/.ccache/ccache.conf ]] && [[ -f "$podfile_lock" ]]; then
if ! command -v ccache 1> /dev/null; then
brew install ccache
fi
CCACHE_HOME=$(dirname $(dirname $(which ccache)))/opt/ccache
echo "CCACHE_DIR=$(git rev-parse --show-toplevel)/.ccache" >> $GITHUB_ENV
echo "CC=${CCACHE_HOME}/libexec/clang" >> $GITHUB_ENV
echo "CXX=${CCACHE_HOME}/libexec/clang++" >> $GITHUB_ENV
echo "CMAKE_C_COMPILER_LAUNCHER=$(which ccache)" >> $GITHUB_ENV
echo "CMAKE_CXX_COMPILER_LAUNCHER=$(which ccache)" >> $GITHUB_ENV
ccache --zero-stats 1> /dev/null
clang --version > .clang-version
input=$(find . -maxdepth 1 -name .clang-version -o -name .yarnrc.yml | sort)
echo "cache-key=$(cat "$podfile_lock" $input | shasum -a 256 | awk '{ print $1 }')" >> $GITHUB_OUTPUT
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ jobs:
if [[ "$(yarn show-affected --base origin/${{ github.base_ref }})" = *"@rnx-kit/test-app"* ]]; then
echo 'ios=true' >> $GITHUB_OUTPUT
fi
- name: Install Ccache
if: ${{ steps.affected-projects.outputs.ios != '' }}
run: |
brew install ccache
- name: Build @rnx-kit/cli
if: ${{ steps.affected-projects.outputs.ios != '' }}
run: |
Expand All @@ -151,7 +155,10 @@ jobs:
- name: Build iOS app
if: ${{ steps.affected-projects.outputs.ios != '' }}
run: |
yarn build:ios | xcbeautify
export CCACHE_DIR="$(git rev-parse --show-toplevel)/.ccache"
ccache --zero-stats 1> /dev/null
yarn build:ios --ccache-dir "$CCACHE_DIR" --ccache-home /opt/homebrew/opt/ccache | xcbeautify
ccache --show-stats --verbose
working-directory: packages/test-app
build-website:
name: "Build the website"
Expand Down
11 changes: 11 additions & 0 deletions packages/cli/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Config } from "@react-native-community/cli-types";
import { InvalidArgumentError } from "commander";
import { buildAndroid } from "./build/android";
import { setCcacheDir, setCcacheHome } from "./build/ccache";
import { buildIOS } from "./build/ios";
import { buildMacOS } from "./build/macos";
import type {
Expand Down Expand Up @@ -100,5 +101,15 @@ export const rnxBuildCommand = {
default: "simulator",
parse: asDestination,
},
{
name: "--ccache-dir <string>",
description: "Path to Ccache config",
parse: setCcacheDir,
},
{
name: "--ccache-home <string>",
description: "Path to Ccache installation",
parse: setCcacheHome,
},
],
};
23 changes: 23 additions & 0 deletions packages/cli/src/build/ccache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as fs from "node:fs";
import * as path from "node:path";

export function setCcacheDir(dir: string): string | undefined {
if (!fs.existsSync(dir)) {
return undefined;
}

process.env["CCACHE_DIR"] = dir;
return dir;
}

export function setCcacheHome(dir: string): string | undefined {
if (!fs.existsSync(dir)) {
return undefined;
}

process.env["CC"] = path.join(dir, "libexec", "clang");
process.env["CXX"] = path.join(dir, "libexec", "clang++");
process.env["CMAKE_C_COMPILER_LAUNCHER"] = path.join(dir, "bin", "ccache");
process.env["CMAKE_CXX_COMPILER_LAUNCHER"] = path.join(dir, "bin", "ccache");
return dir;
}

0 comments on commit 6b942ec

Please sign in to comment.