Skip to content

Commit 0a40fe2

Browse files
[codex] Use baseline Bun target for Windows builds (#688)
Co-authored-by: James Grugett <jahooma@gmail.com>
1 parent 6656987 commit 0a40fe2

5 files changed

Lines changed: 69 additions & 3 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: 'Setup Bun Compile Runtime'
2+
description: 'Download and cache a Bun runtime used by bun build --compile-executable-path'
3+
4+
inputs:
5+
target:
6+
description: 'Bun compile target, for example bun-windows-x64-baseline'
7+
required: true
8+
9+
runs:
10+
using: 'composite'
11+
steps:
12+
- name: Get Bun version
13+
id: bun-version
14+
shell: bash
15+
run: echo "version=$(bun --version)" >> "$GITHUB_OUTPUT"
16+
17+
- name: Cache Bun compile runtime
18+
uses: actions/cache@v5
19+
with:
20+
path: ${{ runner.temp }}/bun-compile-runtimes/${{ inputs.target }}-v${{ steps.bun-version.outputs.version }}
21+
key: ${{ runner.os }}-bun-compile-runtime-${{ inputs.target }}-v${{ steps.bun-version.outputs.version }}
22+
23+
- name: Prepare Bun compile runtime
24+
shell: pwsh
25+
env:
26+
BUN_COMPILE_TARGET: ${{ inputs.target }}
27+
BUN_VERSION: ${{ steps.bun-version.outputs.version }}
28+
RUNTIME_DIR: ${{ runner.temp }}/bun-compile-runtimes/${{ inputs.target }}-v${{ steps.bun-version.outputs.version }}
29+
run: |
30+
$ErrorActionPreference = 'Stop'
31+
32+
$runtimePath = Join-Path $env:RUNTIME_DIR 'bun.exe'
33+
if (!(Test-Path -LiteralPath $runtimePath)) {
34+
New-Item -ItemType Directory -Force -Path $env:RUNTIME_DIR | Out-Null
35+
36+
$zipPath = Join-Path $env:RUNTIME_DIR "$($env:BUN_COMPILE_TARGET).zip"
37+
$downloadUrl = "https://github.com/oven-sh/bun/releases/download/bun-v$($env:BUN_VERSION)/$($env:BUN_COMPILE_TARGET).zip"
38+
39+
Write-Host "Downloading $($env:BUN_COMPILE_TARGET): $downloadUrl"
40+
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath
41+
Expand-Archive -LiteralPath $zipPath -DestinationPath $env:RUNTIME_DIR -Force
42+
43+
$extractedRuntimePath = Join-Path $env:RUNTIME_DIR "$($env:BUN_COMPILE_TARGET)/bun.exe"
44+
if (!(Test-Path -LiteralPath $extractedRuntimePath)) {
45+
throw "Downloaded $($env:BUN_COMPILE_TARGET), but bun.exe was not found at $extractedRuntimePath"
46+
}
47+
48+
Copy-Item -LiteralPath $extractedRuntimePath -Destination $runtimePath -Force
49+
}
50+
51+
"BUN_COMPILE_EXECUTABLE_PATH=$runtimePath" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8

.github/workflows/cli-release-build.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,18 @@ jobs:
315315
echo "$ENV_OVERRIDES" | jq -r 'to_entries | .[] | .key + "=" + .value' >> $GITHUB_ENV
316316
fi
317317
318+
- name: Prepare Windows baseline Bun compile runtime
319+
uses: ./.github/actions/setup-bun-compile-runtime
320+
with:
321+
target: bun-windows-x64-baseline
322+
318323
- name: Build binary
319324
run: bun run scripts/build-binary.ts ${{ inputs.binary-name }} ${{ inputs.new-version }}
320325
working-directory: cli
321326
shell: bash
322327
env:
323328
VERBOSE: true
324-
OVERRIDE_TARGET: bun-windows-x64
329+
OVERRIDE_TARGET: bun-windows-x64-baseline
325330
OVERRIDE_PLATFORM: win32
326331
OVERRIDE_ARCH: x64
327332

.github/workflows/freebuff-e2e.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ jobs:
162162
echo "NEXT_PUBLIC_CB_ENVIRONMENT=prod" >> $GITHUB_ENV
163163
echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV
164164
165+
- name: Prepare Windows baseline Bun compile runtime
166+
uses: ./.github/actions/setup-bun-compile-runtime
167+
with:
168+
target: bun-windows-x64-baseline
169+
165170
- name: Build Freebuff binary
166171
run: bun freebuff/cli/build.ts 0.0.0-e2e
167172
shell: bash

.github/workflows/npm-app-release-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
arch: arm64
5454
- os: windows-latest
5555
target: win32-x64
56-
bun_target: bun-windows-x64
56+
bun_target: bun-windows-x64-baseline
5757
platform: win32
5858
arch: x64
5959
runs-on: ${{ matrix.os }}

cli/scripts/build-binary.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const OVERRIDE_PLATFORM = process.env.OVERRIDE_PLATFORM as
2828
| NodeJS.Platform
2929
| undefined
3030
const OVERRIDE_ARCH = process.env.OVERRIDE_ARCH ?? undefined
31+
const OVERRIDE_COMPILE_EXECUTABLE_PATH =
32+
process.env.BUN_COMPILE_EXECUTABLE_PATH
3133

3234
const __filename = fileURLToPath(import.meta.url)
3335
const __dirname = dirname(__filename)
@@ -95,7 +97,7 @@ function getTargetInfo(): TargetInfo {
9597
arch: 'arm64',
9698
},
9799
'win32-x64': {
98-
bunTarget: 'bun-windows-x64',
100+
bunTarget: 'bun-windows-x64-baseline',
99101
platform: 'win32',
100102
arch: 'x64',
101103
},
@@ -172,6 +174,9 @@ async function main() {
172174
'--compile',
173175
'--production', // Required so compiled binaries use the production JSX runtime (avoids jsxDEV crashes).
174176
`--target=${targetInfo.bunTarget}`,
177+
...(OVERRIDE_COMPILE_EXECUTABLE_PATH
178+
? [`--compile-executable-path=${OVERRIDE_COMPILE_EXECUTABLE_PATH}`]
179+
: []),
175180
`--outfile=${outputFile}`,
176181
'--sourcemap=none',
177182
...defineFlags.flatMap(([key, value]) => ['--define', `${key}=${value}`]),

0 commit comments

Comments
 (0)