Skip to content

Commit

Permalink
feat(tooling): update build scripts to support ARM architectures (#898)
Browse files Browse the repository at this point in the history
Co-authored-by: theofficialgman <28281419+theofficialgman@users.noreply.github.com>
  • Loading branch information
shiftkey and theofficialgman committed Aug 17, 2024
1 parent b5a3cef commit 953d02a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
23 changes: 10 additions & 13 deletions script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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`
)
}

Expand Down Expand Up @@ -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,
Expand Down
15 changes: 5 additions & 10 deletions script/dist-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down

0 comments on commit 953d02a

Please sign in to comment.