From 953d02a44d8d437401e91c2a3cfa37e09697c33e Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Sun, 11 Aug 2024 21:23:08 -0300 Subject: [PATCH] feat(tooling): update build scripts to support ARM architectures (#898) Co-authored-by: theofficialgman <28281419+theofficialgman@users.noreply.github.com> --- script/build.ts | 23 ++++++++++------------- script/dist-info.ts | 15 +++++---------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/script/build.ts b/script/build.ts index dcc3bb7cdf7..e119c1f5780 100755 --- a/script/build.ts +++ b/script/build.ts @@ -3,8 +3,7 @@ import * as path from 'path' import * as cp from 'child_process' -import * as os from 'os' -import packager, { OfficialArch, OsxNotarizeOptions } from 'electron-packager' +import packager, { OsxNotarizeOptions } from 'electron-packager' import frontMatter from 'front-matter' import { externals } from '../app/webpack.common' @@ -131,21 +130,19 @@ function packageApp() { ) } - const toPackageArch = (targetArch: string | undefined): OfficialArch => { - if (targetArch === undefined) { - targetArch = os.arch() + const getPackageArch = (): 'arm64' | 'x64' | 'armv7l' => { + const arch = process.env.npm_config_arch || process.arch + + if (arch === 'arm64' || arch === 'x64') { + return arch } - if ( - targetArch === 'arm64' || - targetArch === 'x64' || - targetArch === 'armv7l' - ) { - return targetArch + if (arch === 'arm') { + return 'armv7l' } throw new Error( - `Building Desktop for architecture '${targetArch}' is not supported` + `Building Desktop for architecture '${arch}' is not supported. Currently these architectures are supported: arm, arm64, x64` ) } @@ -174,7 +171,7 @@ function packageApp() { return packager({ name: getExecutableName(), platform: toPackagePlatform(process.platform), - arch: toPackageArch(process.env.TARGET_ARCH), + arch: getPackageArch(), asar: false, // TODO: Probably wanna enable this down the road. out: getDistRoot(), icon, diff --git a/script/dist-info.ts b/script/dist-info.ts index 420444f7448..459f01db905 100644 --- a/script/dist-info.ts +++ b/script/dist-info.ts @@ -114,18 +114,13 @@ export const getChannel = () => export function getDistArchitecture(): 'arm64' | 'x64' | 'armv7l' { // If a specific npm_config_arch is set, we use that one instead of the OS arch (to support cross compilation) - if ( - process.env.npm_config_arch === 'arm64' || - process.env.npm_config_arch === 'x64' || - process.env.npm_config_arch === 'armv7l' - ) { - return process.env.npm_config_arch - } + const arch = process.env.npm_config_arch || process.arch - if (process.arch === 'arm64') { - return 'arm64' + if (arch === 'arm64' || arch === 'x64' || arch === 'armv7l') { + return arch } - if (process.arch === 'arm') { + + if (arch === 'arm') { return 'armv7l' }