Skip to content

Commit 5f5c0cf

Browse files
committed
chore: native arm bundles
1 parent 32359e6 commit 5f5c0cf

6 files changed

Lines changed: 40 additions & 89 deletions

File tree

.github/workflows/check.yaml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,10 @@ jobs:
212212
label: unix
213213
- os: windows-latest
214214
label: windows-x64
215+
bun-target-arch: x64
215216
- os: windows-11-arm
216217
label: windows-arm64
218+
bun-target-arch: arm64
217219

218220
runs-on: ${{ matrix.os }}
219221

@@ -230,33 +232,19 @@ jobs:
230232

231233
- name: Install bun
232234
uses: oven-sh/setup-bun@v2
233-
if: ${{ matrix.os != 'windows-11-arm' }}
234235
with:
235236
bun-version-file: .bun-version
236237
no-cache: true
237238

238-
- name: Install bun (Windows ARM)
239-
if: ${{ matrix.os == 'windows-11-arm' }}
240-
run: |
241-
$bunVersion = (Get-Content .bun-version).Trim()
242-
irm bun.sh/install.ps1 -OutFile install.ps1
243-
244-
# Bun doesn't have Windows ARM64 builds, so the setup-bun action fails. The install script however,
245-
# does "support" it.
246-
247-
.\install.ps1 -Version $bunVersion
248-
249-
Join-Path (Resolve-Path ~).Path ".bun\bin" >> $env:GITHUB_PATH
250-
251239
# https://github.com/oven-sh/bun/issues/11198
252240
- name: Fix cross-platform building on Actions
253241
if: ${{ matrix.os != 'ubuntu-latest' }}
254242
run: |
255243
mkdir C:\test
256244
cd C:\test
257245
bun init -y
258-
bun build --compile --target=bun-windows-x64 --outfile test index.ts
259-
bun build --compile --target=bun-windows-x64-baseline --outfile test index.ts
246+
bun build --compile --target=bun-windows-${{ matrix.bun-target-arch }} --outfile test index.ts
247+
bun build --compile --target=bun-windows-${{ matrix.bun-target-arch }}-baseline --outfile test index.ts
260248
261249
- name: Build Bundles
262250
run: pnpm run insert-cli-metadata && pnpm run build-bundles

.github/workflows/pre_release.yaml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ jobs:
103103
label: unix
104104
- os: windows-latest
105105
label: windows-x64
106+
bun-target-arch: x64
106107
- os: windows-11-arm
107108
label: windows-arm64
109+
bun-target-arch: arm64
108110

109111
runs-on: ${{ matrix.os }}
110112

@@ -126,32 +128,18 @@ jobs:
126128

127129
- name: Install bun
128130
uses: oven-sh/setup-bun@v2
129-
if: ${{ matrix.os != 'windows-11-arm' }}
130131
with:
131132
bun-version-file: .bun-version
132133

133-
- name: Install bun (Windows ARM)
134-
if: ${{ matrix.os == 'windows-11-arm' }}
135-
run: |
136-
$bunVersion = (Get-Content .bun-version).Trim()
137-
irm bun.sh/install.ps1 -OutFile install.ps1
138-
139-
# Bun doesn't have Windows ARM64 builds, so the setup-bun action fails. The install script however,
140-
# does "support" it.
141-
142-
.\install.ps1 -Version $bunVersion
143-
144-
Join-Path (Resolve-Path ~).Path ".bun\bin" >> $env:GITHUB_PATH
145-
146134
# https://github.com/oven-sh/bun/issues/11198
147135
- name: Fix cross-platform building on Actions
148136
if: ${{ matrix.os != 'ubuntu-latest' }}
149137
run: |
150138
mkdir C:\test
151139
cd C:\test
152140
bun init -y
153-
bun build --compile --target=bun-windows-x64 --outfile test index.ts
154-
bun build --compile --target=bun-windows-x64-baseline --outfile test index.ts
141+
bun build --compile --target=bun-windows-${{ matrix.bun-target-arch }} --outfile test index.ts
142+
bun build --compile --target=bun-windows-${{ matrix.bun-target-arch }}-baseline --outfile test index.ts
155143
156144
- name: Set pre-release version
157145
run: pnpm version ${{ needs.update_changelog.outputs.pre_release_version }} --no-git-tag-version

.github/workflows/release.yaml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ jobs:
131131
label: unix
132132
- os: windows-latest
133133
label: windows-x64
134+
bun-target-arch: x64
134135
- os: windows-11-arm
135136
label: windows-arm64
137+
bun-target-arch: arm64
136138

137139
runs-on: ${{ matrix.os }}
138140

@@ -154,32 +156,18 @@ jobs:
154156

155157
- name: Install bun
156158
uses: oven-sh/setup-bun@v2
157-
if: ${{ matrix.os != 'windows-11-arm' }}
158159
with:
159160
bun-version-file: .bun-version
160161

161-
- name: Install bun (Windows ARM)
162-
if: ${{ matrix.os == 'windows-11-arm' }}
163-
run: |
164-
$bunVersion = (Get-Content .bun-version).Trim()
165-
irm bun.sh/install.ps1 -OutFile install.ps1
166-
167-
# Bun doesn't have Windows ARM64 builds, so the setup-bun action fails. The install script however,
168-
# does "support" it.
169-
170-
.\install.ps1 -Version $bunVersion
171-
172-
Join-Path (Resolve-Path ~).Path ".bun\bin" >> $env:GITHUB_PATH
173-
174162
# https://github.com/oven-sh/bun/issues/11198
175163
- name: Fix cross-platform building on Actions
176164
if: ${{ matrix.os != 'ubuntu-latest' }}
177165
run: |
178166
mkdir C:\test
179167
cd C:\test
180168
bun init -y
181-
bun build --compile --target=bun-windows-x64 --outfile test index.ts
182-
bun build --compile --target=bun-windows-x64-baseline --outfile test index.ts
169+
bun build --compile --target=bun-windows-${{ matrix.bun-target-arch }} --outfile test index.ts
170+
bun build --compile --target=bun-windows-${{ matrix.bun-target-arch }}-baseline --outfile test index.ts
183171
184172
- name: Set version
185173
run: pnpm version ${{ needs.release_metadata.outputs.version_number }} --no-git-tag-version

scripts/build-cli-bundles.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { readFileSync } from 'node:fs';
1111
import { readFile, rm, writeFile } from 'node:fs/promises';
1212
import { basename } from 'node:path';
1313

14-
import { $, type Build, build, fileURLToPath } from 'bun';
14+
import { type Build, build, fileURLToPath } from 'bun';
1515

1616
import { version } from '../package.json' with { type: 'json' };
1717

@@ -21,6 +21,7 @@ const targets = (() => {
2121
//
2222
'bun-windows-x64',
2323
'bun-windows-x64-baseline',
24+
'bun-windows-arm64',
2425
'bun-linux-x64',
2526
'bun-linux-x64-baseline',
2627
'bun-linux-arm64',
@@ -31,13 +32,16 @@ const targets = (() => {
3132
'bun-darwin-arm64-baseline',
3233
'bun-linux-x64-musl',
3334
'bun-linux-arm64-musl',
34-
// TODO: when adding native windows arm64 builds, remove these too
3535
'bun-linux-x64-musl-baseline' as never,
3636
'bun-linux-arm64-musl-baseline' as never,
3737
] satisfies Build.CompileTarget[];
3838
}
3939

4040
if (process.platform === 'win32') {
41+
if (process.arch === 'arm64') {
42+
return ['bun-windows-arm64'] satisfies Build.CompileTarget[];
43+
}
44+
4145
return ['bun-windows-x64', 'bun-windows-x64-baseline'] satisfies Build.CompileTarget[];
4246
}
4347

@@ -117,24 +121,6 @@ for (const entryPoint of entryPoints) {
117121
baseline = 'baseline';
118122
}
119123

120-
// If we are building on Windows ARM64, even though the target is x64, we mark it as "arm64" (there are some weird errors when compiling on x64
121-
// and running on arm64). Hopefully bun will get arm64 native builds
122-
// TODO: Vlad remove this in a subsequent PR as Bun now has native arm64 windows builds
123-
if (os === 'windows' && process.platform === 'win32') {
124-
const systemType = await $`pwsh -c "(Get-CimInstance Win32_ComputerSystem).SystemType"`.text();
125-
126-
if (systemType.toLowerCase().includes('arm')) {
127-
arch = 'arm64';
128-
129-
// On arm, process.arch will still return x64, which will break the upgrade command.
130-
// So we override the arch to arm64
131-
132-
const newNewContent = newContent.replace('process.env.APIFY_BUNDLE_ARCH', '"arm64"');
133-
134-
await writeFile(metadataFile, newNewContent);
135-
}
136-
}
137-
138124
const fileName = `${cliName}-${version}-${os}-${arch}${musl ? '-musl' : ''}${baseline ? '-baseline' : ''}`;
139125

140126
const outFile = fileURLToPath(new URL(`../bundles/${fileName}`, import.meta.url));
@@ -155,9 +141,6 @@ for (const entryPoint of entryPoints) {
155141
},
156142
bytecode: true,
157143
});
158-
159-
// Remove the arch override
160-
await writeFile(metadataFile, newContent);
161144
}
162145
}
163146

scripts/install/install.ps1

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,14 @@ param(
88
# The following script is adapted from the bun.sh install script
99
# Licensed under the MIT License (https://github.com/oven-sh/bun/blob/main/LICENSE.md)
1010

11-
$allowedSystemTypes = @("x64-based", "ARM64-based")
12-
$currentSystemType = (Get-CimInstance Win32_ComputerSystem).SystemType
13-
11+
$Arch = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment').PROCESSOR_ARCHITECTURE
1412
# filter out 32 bit
15-
if (-not ($allowedSystemTypes | Where-Object { $currentSystemType -match $_ })) {
13+
if (-not ($Arch -eq "AMD64" -or $Arch -eq "ARM64")) {
1614
Write-Output "Install Failed:"
1715
Write-Output "Apify CLI for Windows is currently only available for 64-bit Windows and ARM64 Windows.`n"
1816
return 1
1917
}
2018

21-
if ($currentSystemType -match "ARM64") {
22-
Write-Warning "Warning:"
23-
Write-Warning "ARM64-based systems are not natively supported yet.`nThe install will still continue but Apify CLI might not work as intended.`n"
24-
}
25-
2619
# This corresponds to .win10_rs5 in build.zig
2720
$MinBuild = 17763;
2821
$MinBuildName = "Windows 10 1809 / Windows Server 2019"
@@ -114,13 +107,18 @@ function Install-Apify {
114107
return 1
115108
}
116109

117-
$Arch = if ($currentSystemType -match "ARM64") { "arm64" } else { "x64" }
118-
$IsBaseline = $ForceBaseline
119-
120-
if (-not $IsBaseline) {
121-
$IsBaseline = !(
122-
Add-Type -MemberDefinition '[DllImport("kernel32.dll")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);' -Name 'Kernel32' -Namespace 'Win32' -PassThru
123-
)::IsProcessorFeaturePresent(40)
110+
$IsARM64 = $Arch -eq "ARM64"
111+
$Arch = if ($IsARM64) { "arm64" } else { "x64" }
112+
$IsBaseline = $false
113+
114+
if (-not $IsARM64) {
115+
$IsBaseline = $ForceBaseline
116+
if (-not $IsBaseline) {
117+
$IsBaseline = !( `
118+
Add-Type -MemberDefinition '[DllImport("kernel32.dll")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);' `
119+
-Name 'Kernel32' -Namespace 'Win32' -PassThru `
120+
)::IsProcessorFeaturePresent(40);
121+
}
124122
}
125123

126124
$ApifyRoot = if ($env:APIFY_CLI_INSTALL) { $env:APIFY_CLI_INSTALL } else { "${Home}\.apify" }

scripts/install/install.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,20 @@ case $platform in
5353
target=darwin-x64
5454
;;
5555
'Darwin arm64')
56-
target=darwin-arm64
56+
target=darwin-aarch64
5757
;;
5858
'Linux aarch64' | 'Linux arm64')
59-
target=linux-arm64
59+
target=linux-aarch64
60+
;;
61+
'MINGW64'*'ARM64'* | 'MINGW64'*'aarch64'*)
62+
target=windows-aarch64
6063
;;
6164
'MINGW64'*)
6265
target=windows-x64
6366
;;
67+
'Linux riscv64')
68+
error 'Not supported on riscv64'
69+
;;
6470
'Linux x86_64' | *)
6571
target=linux-x64
6672
;;

0 commit comments

Comments
 (0)