Skip to content

Commit

Permalink
Allow using ccache for MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Jan 19, 2025
1 parent 5406a37 commit f450281
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,31 @@ jobs:
run: sudo apt install -y binutils-aarch64-linux-gnu

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive

- name: Use ccache
uses: hendrikmuhs/[email protected]
with:
key: ccache-${{ matrix.os }}-${{ matrix.arch }}

- name: Build
- name: Build (Posix)
if: matrix.os != 'win'
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: Build (Windows)
if: matrix.os == 'win'
shell: cmd
run: |
pushd "C:\Program Files (x86)\Microsoft Visual Studio\Installer\"
for /f "delims=" %%x in ('.\vswhere.exe -latest -property InstallationPath') do set VSPATH=%%x
popd
call "%VSPATH%\VC\Auxiliary\Build\vcvarsall.bat" ${{ matrix.arch }}
node scripts/bootstrap.js --target-cpu=${{ matrix.arch }} --cc-wrapper=ccache
node scripts/build.js out/Release
- name: Create distribution
Expand Down
3 changes: 2 additions & 1 deletion build/toolchain/win/toolchain.gni
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ template("msvc_toolchain") {
} else {
cl_prefix = ""
}
} else if (toolchain_cc_wrapper != "" && toolchain_is_clang) {
# PATCH(build-gn): ccache works with msvc.
} else if (toolchain_cc_wrapper != "") {
cl_prefix = toolchain_cc_wrapper + " "
} else {
cl_prefix = ""
Expand Down
8 changes: 6 additions & 2 deletions scripts/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -19,7 +19,7 @@ if (process.platform == 'linux') {
execSync(`python3 build/linux/sysroot_scripts/install-sysroot.py --arch ${sysrootArch}`)
}

execSync('git submodule sync --recursive')
execSync('git submodule sync --recursive', {stdio: 'ignore'})
execSync('git submodule update --init --recursive')

const commonConfig = [
Expand All @@ -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',
Expand Down
10 changes: 9 additions & 1 deletion scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -109,6 +116,7 @@ module.exports = {
verbose,
version,
argv,
ccWrapper,
targetCpu,
targetOs,
streamPromise,
Expand Down
5 changes: 3 additions & 2 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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}`)
Expand Down

0 comments on commit f450281

Please sign in to comment.