Commit 5a47e114 authored by Matt Mastracci's avatar Matt Mastracci

Add native binary cache to Windows cross-compilation

Try restoring the .node binary from turbo remote cache before building
the Docker image. On cache hit, skip Docker entirely. On miss, build
and save the result for next time.

Also add --profile flag to native-cache.js so release and
release-with-assertions binaries are cached separately.
parent 43c5ab8d
...@@ -79,6 +79,12 @@ jobs: ...@@ -79,6 +79,12 @@ jobs:
runs-on: ['self-hosted', 'linux', 'x64', 'metal'] runs-on: ['self-hosted', 'linux', 'x64', 'metal']
needs: ['changes'] needs: ['changes']
if: ${{ needs.changes.outputs.docs-only == 'false' }} if: ${{ needs.changes.outputs.docs-only == 'false' }}
env:
TURBO_VERSION: 2.9.4
TURBO_ARGS: '-v --env-mode loose --remote-cache-timeout 300 --log-order stream'
TURBO_TEAM: 'vtest314-next-e2e-tests'
TURBO_CACHE: 'remote:rw'
TURBO_TOKEN: ${{ secrets.TURBO_REMOTE_CACHE_TOKEN }}
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
...@@ -93,14 +99,24 @@ jobs: ...@@ -93,14 +99,24 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 25 fetch-depth: 25
- name: Rust fingerprint
run: pnpm dlx turbo@${TURBO_VERSION} run rust-fingerprint ${TURBO_ARGS}
- name: Restore native binary cache
id: native-cache
run: node scripts/native-cache.js --restore --target ${{ matrix.target }} --profile release-with-assertions && echo "HIT=yes" >> $GITHUB_OUTPUT || echo "HIT=no" >> $GITHUB_OUTPUT
- name: Build Docker image - name: Build Docker image
if: ${{ steps.native-cache.outputs.HIT != 'yes' }}
uses: ./.github/actions/docker-buildx uses: ./.github/actions/docker-buildx
with: with:
target: windows target: windows
image-tag: next-swc-builder-win:latest image-tag: next-swc-builder-win:latest
cache-ref: next-swc-builder-win cache-ref: next-swc-builder-win
- name: Cross-compile Windows native binary - name: Cross-compile Windows native binary
if: ${{ steps.native-cache.outputs.HIT != 'yes' }}
run: node scripts/docker-native-build.js --quick --skip-image ${{ matrix.target }} run: node scripts/docker-native-build.js --quick --skip-image ${{ matrix.target }}
- name: Save native binary cache
if: ${{ steps.native-cache.outputs.HIT != 'yes' }}
run: node scripts/native-cache.js --save --target ${{ matrix.target }} --profile release-with-assertions
- name: Upload Windows native artifact - name: Upload Windows native artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with: with:
......
...@@ -23,6 +23,7 @@ const { values: flags } = parseArgs({ ...@@ -23,6 +23,7 @@ const { values: flags } = parseArgs({
restore: { type: 'boolean', default: false }, restore: { type: 'boolean', default: false },
save: { type: 'boolean', default: false }, save: { type: 'boolean', default: false },
target: { type: 'string', default: '' }, target: { type: 'string', default: '' },
profile: { type: 'string', default: 'release' },
}, },
strict: false, strict: false,
}) })
...@@ -42,9 +43,10 @@ function computeCacheKey() { ...@@ -42,9 +43,10 @@ function computeCacheKey() {
// Combine turbo's input hash with the target triple for a unique key. // Combine turbo's input hash with the target triple for a unique key.
// Must be hex-only (turbo cache API requirement). // Must be hex-only (turbo cache API requirement).
const hash = createHash('sha256') const hash = createHash('sha256')
hash.update(`native-cache-v1\0`) hash.update(`native-cache-v2\0`)
hash.update(`turbo=${turboHash}\0`) hash.update(`turbo=${turboHash}\0`)
hash.update(`target=${flags.target}\0`) hash.update(`target=${flags.target}\0`)
hash.update(`profile=${flags.profile}\0`)
return hash.digest('hex') return hash.digest('hex')
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment