From dd584091413d55044855a1182ffaa72112169865 Mon Sep 17 00:00:00 2001 From: Cheng Date: Sun, 19 Jan 2025 04:49:09 +0000 Subject: [PATCH] ci: Use ccache --- .github/workflows/main.yml | 9 +++++++-- scripts/bootstrap.js | 6 +++++- scripts/common.js | 10 +++++++++- scripts/test.js | 5 +++-- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fc7062a..b3119b9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,11 +29,16 @@ jobs: run: sudo apt install -y binutils-aarch64-linux-gnu - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + + - name: Use ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: ccache-${{ matrix.os }}-${{ matrix.arch }} - name: Build run: | - node scripts/bootstrap.js --target-cpu=${{ matrix.arch }} + node scripts/bootstrap.js --target-cpu=${{ matrix.arch }} --cc-wrapper=ccache node scripts/build.js out/Release - name: Create distribution diff --git a/scripts/bootstrap.js b/scripts/bootstrap.js index e2ba638..1fd2255 100755 --- a/scripts/bootstrap.js +++ b/scripts/bootstrap.js @@ -4,7 +4,7 @@ // Use of this source code is governed by the license that can be found in the // LICENSE file. -const {targetCpu, targetOs, execSync, spawnSync} = require('./common') +const {ccWrapper, targetCpu, targetOs, execSync, spawnSync} = require('./common') // Get the arch of sysroot. let sysrootArch = { @@ -38,6 +38,10 @@ const releaseConfig = [ 'is_official_build=true', ] +if (ccWrapper) { + commonConfig.push(`cc_wrapper="${ccWrapper}"`, + 'clang_use_chrome_plugins=false') +} if (targetOs == 'linux') { // Use prebuilt clang binaries. commonConfig.push('is_clang=true', diff --git a/scripts/common.js b/scripts/common.js index b754276..0581ed2 100644 --- a/scripts/common.js +++ b/scripts/common.js @@ -32,11 +32,15 @@ const version = String(execSync('git describe --always --tags')).trim() // Get target_cpu from args.gn. let targetCpu = process.arch +let ccWrapper = null if (fs.existsSync('out/Release/args.gn')) { const content = String(fs.readFileSync('out/Release/args.gn')) - const match = content.match(/target_cpu = "(.*)"/) + let match = content.match(/target_cpu = "(.*)"/) if (match && match.length > 1) targetCpu = match[1] + match = content.match(/cc_wrapper = "(.*)"/) + if (match && match.length > 1) + ccWrapper = match[1] } // Get target OS. @@ -52,6 +56,9 @@ const argv = process.argv.slice(2).filter((arg) => { if (arg == '-v' || arg == '--verbose') { verbose = true return false + } else if (arg.startsWith('--cc-wrapper=')) { + ccWrapper = arg.substr(arg.indexOf('=') + 1) + return false } else if (arg.startsWith('--target-cpu=')) { targetCpu = arg.substr(arg.indexOf('=') + 1) return false @@ -109,6 +116,7 @@ module.exports = { verbose, version, argv, + ccWrapper, targetCpu, targetOs, streamPromise, diff --git a/scripts/test.js b/scripts/test.js index 8d939df..e146434 100755 --- a/scripts/test.js +++ b/scripts/test.js @@ -4,7 +4,7 @@ // Use of this source code is governed by the license that can be found in the // LICENSE file. -const {argv, version, targetCpu, targetOs, execSync} = require('./common') +const {argv, ccWrapper, version, targetCpu, targetOs, execSync} = require('./common') const path = require('path') const extract = require('./libs/extract-zip') @@ -49,8 +49,9 @@ function runEachTest(project, projectPath) { execSync(`python3 ${path.join(tmppath, 'gn/tools/clang/scripts/update.py')}`) } + const args = ccWrapper ? `--args=cc_wrapper="${ccWrapper}"` : '' const gn = path.join(tmppath, 'gn', 'gn') - execSync(`${gn} gen ${outdir}`, {cwd: projectPath}) + execSync(`${gn} gen ${outdir} ${args}`, {cwd: projectPath}) console.log(`Building project "${project}"...`) execSync(`ninja -C ${outdir}`)