Skip to content

Commit

Permalink
feat: allow riscv64 support via custom electron dist (#8143)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaietta authored Aug 17, 2024
1 parent e77de9f commit b306895
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changeset/stupid-avocados-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"app-builder-lib": minor
"builder-util": minor
"electron-builder": minor
---

feat: support riscv64 architecture for electron-builder (requires custom prebuilt artifact via `electronDist`)
1 change: 1 addition & 0 deletions docs/api/electron-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Developer API only. See [Configuration](../configuration/configuration.md) for u
<li><strong><code id="Arch-armv7l">armv7l</code></strong></li>
<li><strong><code id="Arch-arm64">arm64</code></strong></li>
<li><strong><code id="Arch-universal">universal</code></strong></li>
<li><strong><code id="Arch-riscv64">riscv64</code></strong></li>
</ul>
<p><a name="module_electron-builder.build"></a></p>
<h2 id="electron-builder.build(rawoptions)-%E2%87%92-promise%3Carray%3Cstring%3E%3E"><code>electron-builder.build(rawOptions)</code> ⇒ <code>Promise&lt;Array&lt;String&gt;&gt;</code></h2>
Expand Down
2 changes: 2 additions & 0 deletions packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@
"arm64",
"armv7l",
"ia32",
"riscv64",
"universal",
"x64"
],
Expand Down Expand Up @@ -5941,6 +5942,7 @@
"arm64",
"armv7l",
"ia32",
"riscv64",
"universal",
"x64"
],
Expand Down
2 changes: 2 additions & 0 deletions packages/app-builder-lib/src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export function toAppImageOrSnapArch(arch: Arch): string {
return "arm"
case Arch.arm64:
return "arm_aarch64"
case Arch.riscv64:
return "riscv64"

default:
throw new Error(`Unsupported arch ${arch}`)
Expand Down
2 changes: 2 additions & 0 deletions packages/app-builder-lib/src/targets/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ function archNameToTriplet(arch: Arch): string {
return "arm-linux-gnueabihf"
case Arch.arm64:
return "aarch64-linux-gnu"
case Arch.riscv64:
return "riscv64-linux-gnu"

default:
throw new Error(`Unsupported arch ${arch}`)
Expand Down
10 changes: 7 additions & 3 deletions packages/builder-util/src/arch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ export enum Arch {
armv7l,
arm64,
universal,
riscv64,
}

export type ArchType = "x64" | "ia32" | "armv7l" | "arm64" | "universal"
export type ArchType = "x64" | "ia32" | "armv7l" | "arm64" | "universal" | "riscv64"

export function toLinuxArchString(arch: Arch, targetName: string): string {
switch (arch) {
Expand All @@ -18,14 +19,15 @@ export function toLinuxArchString(arch: Arch, targetName: string): string {
return targetName === "snap" || targetName === "deb" ? "armhf" : targetName === "flatpak" ? "arm" : "armv7l"
case Arch.arm64:
return targetName === "pacman" || targetName === "rpm" || targetName === "flatpak" ? "aarch64" : "arm64"

case Arch.riscv64:
return "riscv64"
default:
throw new Error(`Unsupported arch ${arch}`)
}
}

export function getArchCliNames(): Array<string> {
return [Arch[Arch.ia32], Arch[Arch.x64], Arch[Arch.armv7l], Arch[Arch.arm64]]
return [Arch[Arch.ia32], Arch[Arch.x64], Arch[Arch.armv7l], Arch[Arch.arm64], Arch[Arch.riscv64]]
}

export function getArchSuffix(arch: Arch, defaultArch?: string): string {
Expand All @@ -45,6 +47,8 @@ export function archFromString(name: string): Arch {
return Arch.armv7l
case "universal":
return Arch.universal
case "riscv64":
return Arch.riscv64
default:
throw new Error(`Unsupported arch ${name}`)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/electron-builder/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface CliOptions extends PackagerOptions, PublishOptions {
armv7l?: boolean
arm64?: boolean
universal?: boolean
riscv64?: boolean

dir?: boolean
}
Expand Down Expand Up @@ -48,6 +49,9 @@ export function normalizeOptions(args: CliOptions): BuildOptions {
if (args.universal) {
result.push(Arch.universal)
}
if (args.riscv64) {
result.push(Arch.riscv64)
}

return result.length === 0 && currentIfNotSpecified ? [archFromString(process.arch)] : result
}
Expand Down
6 changes: 5 additions & 1 deletion test/src/helpers/downloadElectron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ export function downloadAllRequiredElectronVersions(): Promise<any> {

const versions: Array<any> = []
for (const platform of platforms) {
const archs: string[] =
const archs =
platform === "mas" || platform === "darwin"
? ["x64"]
: platform === "win32"
? ["ia32", "x64"]
: require(`${path.join(__dirname, "../../..")}/packages/builder-util/out/util`).getArchCliNames()
for (const arch of archs) {
if (arch === "riscv64") {
// No prebuilt electron for riscv64
continue
}
if (gte(ELECTRON_VERSION, "19.0.0") && platform === "linux" && arch === "ia32") {
// Chromium dropped support for ia32 linux binaries in 102.0.4999.0
// https://www.electronjs.org/docs/latest/breaking-changes#removed-ia32-linux-binaries
Expand Down

0 comments on commit b306895

Please sign in to comment.