Skip to content

Commit

Permalink
Add support for goma
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Dec 6, 2023
1 parent 799417b commit ab765a4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 74 deletions.
81 changes: 9 additions & 72 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ env:

jobs:
build:
needs: [vs-toolchain]
runs-on: ${{ fromJson('{"linux":"ubuntu-22.04","mac":"macos-12","win":"ubuntu-22.04"}')[matrix.targetOs] }}
runs-on: ${{ fromJson('{"linux":"ubuntu-22.04","mac":"macos-12","win":"windows-2022"}')[matrix.targetOs] }}
continue-on-error: false

strategy:
Expand All @@ -30,11 +29,6 @@ jobs:
if: runner.os == 'Linux'
run: sudo apt update

- name: Install Linux Dependencies
if: runner.os == 'Linux' && matrix.targetOs == 'win'
# Needed for running ciopfs, used when setup vs toolchain.
run: sudo apt install -y fuse

- name: Install Linux Cross Compilation Toolchains
if: runner.os == 'linux' && matrix.arch != 'x64'
run: sudo apt install -y gcc-multilib g++-multilib
Expand All @@ -49,23 +43,18 @@ jobs:

- name: Checkout
uses: actions/checkout@v3

- name: Maximize Build Space
if: matrix.targetOs == 'win'
uses: hirnidrin/free-disk-space@main

- name: Get Windows SDK
if: matrix.targetOs == 'win'
uses: actions/cache/restore@v3
with:
path: '*.zip'
key: vs-toolchain-${{ env.WIN_SDK_VERSION }}
fail-on-cache-miss: true
enableCrossOsArchive: true
submodules: recursive

- name: Setup GOMA
env:
SECRET_FILE_CONTENT: ${{ secrets.GOMA_OAUTH2_CONFIG }}
run: |
printf "$SECRET_FILE_CONTENT" > ~/.goma_oauth2_config
- name: Build
run: |
node scripts/bootstrap.js --target-os=${{ matrix.targetOs }} --target-cpu=${{ matrix.arch }} --node-repo=https://github.com/zcbenz/node --node-commit=pending-patches
node scripts/bootstrap.js --goma --target-os=${{ matrix.targetOs }} --target-cpu=${{ matrix.arch }} --node-repo=https://github.com/zcbenz/node --node-commit=pending-patches
node scripts/build.js
- name: Run Tests
Expand All @@ -91,58 +80,6 @@ jobs:
# don't have enough experience with OpenSSL to fix it.
./tools/test.py --shell ../out/Release/node --flaky-tests=dontcare --skip-tests=parallel/test-crypto-no-algorithm
vs-toolchain:
runs-on: windows-2022
continue-on-error: false

steps:
- name: Check cache
id: check-cache
# It is not job failure when this step fails.
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
# Check if vs-toolchain has been generated before.
gh extension install actions/gh-actions-cache
gh actions-cache list --repo $GITHUB_REPOSITORY | grep -q vs-toolchain-$WIN_SDK_VERSION
- name: Validate branch
if: steps.check-cache.outcome == 'failure'
run: |
# GitHub limits where cache is accessible, we don't want to create
# vs toolchain for every branch so force creating one on main branch.
if (${env:GITHUB_BASE_REF}) {
$env:GIT_BRANCH = ${env:GITHUB_BASE_REF}
} else {
$env:GIT_BRANCH = ${env:GITHUB_REF} -replace '^refs/heads/', ''
}
if (${env:GIT_BRANCH} -ne 'main') {
Write-Output 'Can not create vs-toolchain in a sub-branch, please re-run the main branch job.'
Write-Output "The value of GIT_BRANCH is: ${env:GIT_BRANCH}."
Exit 1
}
- name: Checkout
if: steps.check-cache.outcome == 'failure'
uses: actions/checkout@v3
with:
repository: yue/build-gn

- name: Generate Windows SDK package
if: steps.check-cache.outcome == 'failure'
# See: https://chromium.googlesource.com/chromium/src/+/master/docs/win_cross.md
run: python third_party/depot_tools/win_toolchain/package_from_installed.py 2022 -w 10.0.${env:WIN_SDK_VERSION}.0

- name: Save to cache
uses: actions/cache/save@v3
if: steps.check-cache.outcome == 'failure'
with:
path: '*.zip'
key: vs-toolchain-${{ env.WIN_SDK_VERSION }}
enableCrossOsArchive: true

notify-build-failure:
needs: [build]
if: failure() && github.event.schedule != null
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

/node/
/third_party/abseil-cpp/
/third_party/build-tools/
/third_party/gn/
/third_party/icu/
/third_party/jinja2/
Expand Down
10 changes: 8 additions & 2 deletions scripts/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const {argv, clang, hostCpu, hostOs, targetCpu, targetOs, execSync, spawnSync} = require('./common')

const fs = require('fs')
const path = require('path')

// Download GN.
execSync('node scripts/download_gn.js')
Expand Down Expand Up @@ -74,10 +75,14 @@ if (hostOs == 'linux') {
commonConfig.push('use_sysroot=true')
}
for (const arg of argv) {
if (arg == '--ccache' && hostOs != 'win')
if (arg == '--ccache' && hostOs != 'win') {
commonConfig.push('cc_wrapper="ccache"')
else if (arg.startsWith('--extra-args='))
} if (arg == '--goma') {
execSync('node scripts/goma.js')
commonConfig.push(`import("${path.resolve(__dirname, '../third_party/build-tools/')}/third_party/goma.gn")`)
} else if (arg.startsWith('--extra-args=')) {
commonConfig.push(...arg.substr(arg.indexOf('=') + 1).split(' '))
}
}

gen('out/Component', componentConfig)
Expand Down Expand Up @@ -105,6 +110,7 @@ function checkoutNode() {
function checkoutDeps() {
const deps = {
"abseil-cpp": "https://chromium.googlesource.com/chromium/src/third_party/abseil-cpp",
"build-tools": "https://github.com/electron/build-tools",
"icu": "https://chromium.googlesource.com/chromium/deps/icu",
"jinja2": "https://chromium.googlesource.com/chromium/src/third_party/jinja2",
"markupsafe": "https://chromium.googlesource.com/chromium/src/third_party/markupsafe",
Expand Down
21 changes: 21 additions & 0 deletions scripts/goma.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node

const cp = require('node:child_process')
const fs = require('node:fs')
const path = require('node:path')

const buildToolsDir = path.resolve(__dirname, '../third_party/build-tools')
const thirdPartyDir = path.join(buildToolsDir, 'third_party')
if (!fs.existsSync(thirdPartyDir))
fs.mkdirSync(thirdPartyDir)

const nodeModulesDir = path.join(buildToolsDir, 'node_modules')
if (!fs.existsSync(nodeModulesDir)) {
fs.mkdirSync(nodeModulesDir)
cp.execSync('yarn', {cwd: nodeModulesDir})
}

const goma = require(path.join(buildToolsDir, 'src/utils/goma'))
goma.downloadAndPrepare({gomaOneForAll: true})
goma.auth({goma: 'cluster'})
goma.ensure({goma: 'cluster'})

0 comments on commit ab765a4

Please sign in to comment.