diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 8a158db16..a365a7bf2 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -293,8 +293,10 @@ jobs: label: unix - os: windows-latest label: windows-x64 + bun-target-arch: x64 - os: windows-11-arm label: windows-arm64 + bun-target-arch: arm64 runs-on: ${{ matrix.os }} @@ -322,24 +324,10 @@ jobs: - name: Install bun uses: oven-sh/setup-bun@v2 - if: ${{ matrix.os != 'windows-11-arm' }} with: bun-version-file: .bun-version no-cache: true - - name: Install bun (Windows ARM) - if: ${{ matrix.os == 'windows-11-arm' }} - run: | - $bunVersion = (Get-Content .bun-version).Trim() - irm bun.sh/install.ps1 -OutFile install.ps1 - - # Bun doesn't have Windows ARM64 builds, so the setup-bun action fails. The install script however, - # does "support" it. - - .\install.ps1 -Version $bunVersion - - Join-Path (Resolve-Path ~).Path ".bun\bin" >> $env:GITHUB_PATH - # https://github.com/oven-sh/bun/issues/11198 - name: Fix cross-platform building on Actions if: ${{ matrix.os != 'ubuntu-latest' }} @@ -347,8 +335,8 @@ jobs: mkdir C:\test cd C:\test bun init -y - bun build --compile --target=bun-windows-x64 --outfile test index.ts - bun build --compile --target=bun-windows-x64-baseline --outfile test index.ts + bun build --compile --target=bun-windows-${{ matrix.bun-target-arch }} --outfile test index.ts + bun build --compile --target=bun-windows-${{ matrix.bun-target-arch }}-baseline --outfile test index.ts - name: Build Bundles run: yarn insert-cli-metadata && yarn build-bundles diff --git a/.github/workflows/pre_release.yaml b/.github/workflows/pre_release.yaml index 98a4265c3..2536c5691 100644 --- a/.github/workflows/pre_release.yaml +++ b/.github/workflows/pre_release.yaml @@ -111,8 +111,10 @@ jobs: label: unix - os: windows-latest label: windows-x64 + bun-target-arch: x64 - os: windows-11-arm label: windows-arm64 + bun-target-arch: arm64 runs-on: ${{ matrix.os }} @@ -145,23 +147,9 @@ jobs: - name: Install bun uses: oven-sh/setup-bun@v2 - if: ${{ matrix.os != 'windows-11-arm' }} with: bun-version-file: .bun-version - - name: Install bun (Windows ARM) - if: ${{ matrix.os == 'windows-11-arm' }} - run: | - $bunVersion = (Get-Content .bun-version).Trim() - irm bun.sh/install.ps1 -OutFile install.ps1 - - # Bun doesn't have Windows ARM64 builds, so the setup-bun action fails. The install script however, - # does "support" it. - - .\install.ps1 -Version $bunVersion - - Join-Path (Resolve-Path ~).Path ".bun\bin" >> $env:GITHUB_PATH - # https://github.com/oven-sh/bun/issues/11198 - name: Fix cross-platform building on Actions if: ${{ matrix.os != 'ubuntu-latest' }} @@ -169,8 +157,8 @@ jobs: mkdir C:\test cd C:\test bun init -y - bun build --compile --target=bun-windows-x64 --outfile test index.ts - bun build --compile --target=bun-windows-x64-baseline --outfile test index.ts + bun build --compile --target=bun-windows-${{ matrix.bun-target-arch }} --outfile test index.ts + bun build --compile --target=bun-windows-${{ matrix.bun-target-arch }}-baseline --outfile test index.ts - name: Set pre-release version run: yarn version ${{ needs.update_changelog.outputs.pre_release_version }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e276fc12d..fe7c4872d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -138,8 +138,10 @@ jobs: label: unix - os: windows-latest label: windows-x64 + bun-target-arch: x64 - os: windows-11-arm label: windows-arm64 + bun-target-arch: arm64 runs-on: ${{ matrix.os }} @@ -172,23 +174,9 @@ jobs: - name: Install bun uses: oven-sh/setup-bun@v2 - if: ${{ matrix.os != 'windows-11-arm' }} with: bun-version-file: .bun-version - - name: Install bun (Windows ARM) - if: ${{ matrix.os == 'windows-11-arm' }} - run: | - $bunVersion = (Get-Content .bun-version).Trim() - irm bun.sh/install.ps1 -OutFile install.ps1 - - # Bun doesn't have Windows ARM64 builds, so the setup-bun action fails. The install script however, - # does "support" it. - - .\install.ps1 -Version $bunVersion - - Join-Path (Resolve-Path ~).Path ".bun\bin" >> $env:GITHUB_PATH - # https://github.com/oven-sh/bun/issues/11198 - name: Fix cross-platform building on Actions if: ${{ matrix.os != 'ubuntu-latest' }} @@ -196,8 +184,8 @@ jobs: mkdir C:\test cd C:\test bun init -y - bun build --compile --target=bun-windows-x64 --outfile test index.ts - bun build --compile --target=bun-windows-x64-baseline --outfile test index.ts + bun build --compile --target=bun-windows-${{ matrix.bun-target-arch }} --outfile test index.ts + bun build --compile --target=bun-windows-${{ matrix.bun-target-arch }}-baseline --outfile test index.ts - name: Set version run: yarn version ${{ needs.release_metadata.outputs.version_number }} diff --git a/scripts/build-cli-bundles.ts b/scripts/build-cli-bundles.ts index 5ae25d03d..a85cc2f0f 100644 --- a/scripts/build-cli-bundles.ts +++ b/scripts/build-cli-bundles.ts @@ -11,7 +11,7 @@ import { readFileSync } from 'node:fs'; import { readFile, rm, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; -import { $, type Build, build, fileURLToPath } from 'bun'; +import { type Build, build, fileURLToPath } from 'bun'; import { version } from '../package.json' with { type: 'json' }; @@ -21,6 +21,7 @@ const targets = (() => { // 'bun-windows-x64', 'bun-windows-x64-baseline', + 'bun-windows-arm64', 'bun-linux-x64', 'bun-linux-x64-baseline', 'bun-linux-arm64', @@ -31,13 +32,16 @@ const targets = (() => { 'bun-darwin-arm64-baseline', 'bun-linux-x64-musl', 'bun-linux-arm64-musl', - // TODO: when adding native windows arm64 builds, remove these too 'bun-linux-x64-musl-baseline' as never, 'bun-linux-arm64-musl-baseline' as never, ] satisfies Build.CompileTarget[]; } if (process.platform === 'win32') { + if (process.arch === 'arm64') { + return ['bun-windows-arm64'] satisfies Build.CompileTarget[]; + } + return ['bun-windows-x64', 'bun-windows-x64-baseline'] satisfies Build.CompileTarget[]; } @@ -117,24 +121,6 @@ for (const entryPoint of entryPoints) { baseline = 'baseline'; } - // 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 - // and running on arm64). Hopefully bun will get arm64 native builds - // TODO: Vlad remove this in a subsequent PR as Bun now has native arm64 windows builds - if (os === 'windows' && process.platform === 'win32') { - const systemType = await $`pwsh -c "(Get-CimInstance Win32_ComputerSystem).SystemType"`.text(); - - if (systemType.toLowerCase().includes('arm')) { - arch = 'arm64'; - - // On arm, process.arch will still return x64, which will break the upgrade command. - // So we override the arch to arm64 - - const newNewContent = newContent.replace('process.env.APIFY_BUNDLE_ARCH', '"arm64"'); - - await writeFile(metadataFile, newNewContent); - } - } - const fileName = `${cliName}-${version}-${os}-${arch}${musl ? '-musl' : ''}${baseline ? '-baseline' : ''}`; const outFile = fileURLToPath(new URL(`../bundles/${fileName}`, import.meta.url)); @@ -155,9 +141,6 @@ for (const entryPoint of entryPoints) { }, bytecode: true, }); - - // Remove the arch override - await writeFile(metadataFile, newContent); } } diff --git a/scripts/install/install.ps1 b/scripts/install/install.ps1 index fde157290..65aea3d66 100755 --- a/scripts/install/install.ps1 +++ b/scripts/install/install.ps1 @@ -8,21 +8,14 @@ param( # The following script is adapted from the bun.sh install script # Licensed under the MIT License (https://github.com/oven-sh/bun/blob/main/LICENSE.md) -$allowedSystemTypes = @("x64-based", "ARM64-based") -$currentSystemType = (Get-CimInstance Win32_ComputerSystem).SystemType - +$Arch = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment').PROCESSOR_ARCHITECTURE # filter out 32 bit -if (-not ($allowedSystemTypes | Where-Object { $currentSystemType -match $_ })) { +if (-not ($Arch -eq "AMD64" -or $Arch -eq "ARM64")) { Write-Output "Install Failed:" Write-Output "Apify CLI for Windows is currently only available for 64-bit Windows and ARM64 Windows.`n" return 1 } -if ($currentSystemType -match "ARM64") { - Write-Warning "Warning:" - Write-Warning "ARM64-based systems are not natively supported yet.`nThe install will still continue but Apify CLI might not work as intended.`n" -} - # This corresponds to .win10_rs5 in build.zig $MinBuild = 17763; $MinBuildName = "Windows 10 1809 / Windows Server 2019" @@ -114,13 +107,18 @@ function Install-Apify { return 1 } - $Arch = if ($currentSystemType -match "ARM64") { "arm64" } else { "x64" } - $IsBaseline = $ForceBaseline - - if (-not $IsBaseline) { - $IsBaseline = !( - Add-Type -MemberDefinition '[DllImport("kernel32.dll")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);' -Name 'Kernel32' -Namespace 'Win32' -PassThru - )::IsProcessorFeaturePresent(40) + $IsARM64 = $Arch -eq "ARM64" + $Arch = if ($IsARM64) { "arm64" } else { "x64" } + $IsBaseline = $false + + if (-not $IsARM64) { + $IsBaseline = $ForceBaseline + if (-not $IsBaseline) { + $IsBaseline = !( ` + Add-Type -MemberDefinition '[DllImport("kernel32.dll")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);' ` + -Name 'Kernel32' -Namespace 'Win32' -PassThru ` + )::IsProcessorFeaturePresent(40); + } } $ApifyRoot = if ($env:APIFY_CLI_INSTALL) { $env:APIFY_CLI_INSTALL } else { "${Home}\.apify" } diff --git a/scripts/install/install.sh b/scripts/install/install.sh index 9717f2487..1fc490f82 100755 --- a/scripts/install/install.sh +++ b/scripts/install/install.sh @@ -53,14 +53,20 @@ case $platform in target=darwin-x64 ;; 'Darwin arm64') - target=darwin-arm64 + target=darwin-aarch64 ;; 'Linux aarch64' | 'Linux arm64') - target=linux-arm64 + target=linux-aarch64 + ;; +'MINGW64'*'ARM64'* | 'MINGW64'*'aarch64'*) + target=windows-aarch64 ;; 'MINGW64'*) target=windows-x64 ;; +'Linux riscv64') + error 'Not supported on riscv64' + ;; 'Linux x86_64' | *) target=linux-x64 ;;