Skip to content

Commit 561549f

Browse files
committed
Add support for aarch64 Linux
Before this change, runners on non-macOS would always succeed by downloading the x86_64 binary for their respective platform, which is obviously problematic. To solve this, this change introduces both support for aarch64 Linux, and processor architecture validation.
1 parent 3aed395 commit 561549f

File tree

7 files changed

+102
-10
lines changed

7 files changed

+102
-10
lines changed

__tests__/os.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import * as os from "../src/os";
2+
import getArch from "../src/arch";
23

34
jest.mock("getos");
45

6+
jest.mock("../src/arch", () => {
7+
return {
8+
__esModule: true,
9+
default: jest.fn(() => "x64"),
10+
};
11+
});
12+
513
const setSystem = require("getos").__setSystem;
614

715
describe("os resolver", () => {

__tests__/swift-versions.test.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
import { OS, System } from "../src/os";
22
import * as versions from "../src/swift-versions";
33

4-
const macOS: System = { os: OS.MacOS, version: "latest", name: "macOS" };
5-
const ubuntu: System = { os: OS.Ubuntu, version: "latest", name: "Ubuntu" };
6-
const windows: System = { os: OS.Windows, version: "latest", name: "Windows" };
4+
const macOS: System = {
5+
os: OS.MacOS,
6+
version: "latest",
7+
name: "macOS",
8+
arch: "arm64",
9+
};
10+
11+
const ubuntu: System = {
12+
os: OS.Ubuntu,
13+
version: "latest",
14+
name: "Ubuntu",
15+
arch: "x64",
16+
};
17+
18+
const windows: System = {
19+
os: OS.Windows,
20+
version: "latest",
21+
name: "Windows",
22+
arch: "x64",
23+
};
724

825
describe("swift version resolver", () => {
926
it("identifies X.X.X versions", async () => {

__tests__/visual-studio.test.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ jest.mock("fs", () => {
1212
};
1313
});
1414

15-
const windows: System = { os: OS.Windows, version: "latest", name: "Windows" };
15+
const windows: System = {
16+
os: OS.Windows,
17+
version: "latest",
18+
name: "Windows",
19+
arch: "x64",
20+
};
1621

1722
describe("visual studio resolver", () => {
1823
const env = process.env;

dist/index.js

+40-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
/******/ (() => { // webpackBootstrap
22
/******/ var __webpack_modules__ = ({
33

4+
/***/ 209:
5+
/***/ ((__unused_webpack_module, exports) => {
6+
7+
"use strict";
8+
9+
Object.defineProperty(exports, "__esModule", ({ value: true }));
10+
function getArch() {
11+
return process.arch;
12+
}
13+
exports["default"] = getArch;
14+
15+
16+
/***/ }),
17+
418
/***/ 951:
519
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
620

@@ -372,6 +386,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
372386
Object.defineProperty(exports, "__esModule", ({ value: true }));
373387
exports.getSystem = exports.OS = void 0;
374388
const getos_1 = __importDefault(__nccwpck_require__(6068));
389+
const arch_1 = __importDefault(__nccwpck_require__(209));
375390
var OS;
376391
(function (OS) {
377392
OS[OS["MacOS"] = 0] = "MacOS";
@@ -395,23 +410,41 @@ async function getSystem() {
395410
os ? resolve(os) : reject(error || "No OS detected");
396411
});
397412
});
413+
const arch = (0, arch_1.default)();
398414
let system;
399415
switch (detectedSystem.os) {
400416
case "darwin":
401-
system = { os: OS.MacOS, version: "latest", name: "macOS" };
417+
system = {
418+
os: OS.MacOS,
419+
version: "latest",
420+
name: "macOS",
421+
arch,
422+
};
402423
break;
403424
case "linux":
404425
if (detectedSystem.dist !== "Ubuntu") {
405-
throw new Error(`"${detectedSystem.dist}" is not a supported linux distribution`);
426+
throw new Error(`"${detectedSystem.dist}" is not a supported Linux distribution`);
427+
}
428+
if (arch !== "x64" && arch !== "arm64") {
429+
throw new Error(`${arch} is not a supported architecture for Linux`);
406430
}
407431
system = {
408432
os: OS.Ubuntu,
409433
version: detectedSystem.release,
410434
name: "Ubuntu",
435+
arch,
411436
};
412437
break;
413438
case "win32":
414-
system = { os: OS.Windows, version: "latest", name: "Windows" };
439+
if (arch !== "x64") {
440+
throw new Error(`${arch} is not a supported architecture for Windows`);
441+
}
442+
system = {
443+
os: OS.Windows,
444+
version: "latest",
445+
name: "Windows",
446+
arch,
447+
};
415448
break;
416449
default:
417450
throw new Error(`"${detectedSystem.os}" is not a supported platform`);
@@ -542,7 +575,11 @@ function swiftPackage(version, system) {
542575
break;
543576
case os_1.OS.Ubuntu:
544577
platform = `ubuntu${system.version.replace(/\D/g, "")}`;
578+
if (system.arch === "arm64")
579+
platform += "-aarch64";
545580
archiveName = `swift-${version}-RELEASE-ubuntu${system.version}`;
581+
if (system.arch === "arm64")
582+
archiveName += "-aarch64";
546583
archiveFile = `${archiveName}.tar.gz`;
547584
break;
548585
case os_1.OS.Windows:

src/arch.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function getArch(): string {
2+
return process.arch;
3+
}

src/os.ts

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import getos from "getos";
2+
import getArch from "./arch";
23

34
export enum OS {
45
MacOS,
@@ -22,6 +23,7 @@ export interface System {
2223
os: OS;
2324
version: string;
2425
name: string;
26+
arch: string;
2527
}
2628

2729
export async function getSystem(): Promise<System> {
@@ -30,27 +32,45 @@ export async function getSystem(): Promise<System> {
3032
os ? resolve(os) : reject(error || "No OS detected");
3133
});
3234
});
35+
const arch = getArch();
3336

3437
let system: System;
3538

3639
switch (detectedSystem.os) {
3740
case "darwin":
38-
system = { os: OS.MacOS, version: "latest", name: "macOS" };
41+
system = {
42+
os: OS.MacOS,
43+
version: "latest",
44+
name: "macOS",
45+
arch,
46+
};
3947
break;
4048
case "linux":
4149
if (detectedSystem.dist !== "Ubuntu") {
4250
throw new Error(
43-
`"${detectedSystem.dist}" is not a supported linux distribution`
51+
`"${detectedSystem.dist}" is not a supported Linux distribution`
4452
);
4553
}
54+
if (arch !== "x64" && arch !== "arm64") {
55+
throw new Error(`${arch} is not a supported architecture for Linux`);
56+
}
4657
system = {
4758
os: OS.Ubuntu,
4859
version: detectedSystem.release,
4960
name: "Ubuntu",
61+
arch,
5062
};
5163
break;
5264
case "win32":
53-
system = { os: OS.Windows, version: "latest", name: "Windows" };
65+
if (arch !== "x64") {
66+
throw new Error(`${arch} is not a supported architecture for Windows`);
67+
}
68+
system = {
69+
os: OS.Windows,
70+
version: "latest",
71+
name: "Windows",
72+
arch,
73+
};
5474
break;
5575
default:
5676
throw new Error(`"${detectedSystem.os}" is not a supported platform`);

src/swift-versions.ts

+2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ export function swiftPackage(version: string, system: System): Package {
9797
break;
9898
case OS.Ubuntu:
9999
platform = `ubuntu${system.version.replace(/\D/g, "")}`;
100+
if (system.arch === "arm64") platform += "-aarch64";
100101
archiveName = `swift-${version}-RELEASE-ubuntu${system.version}`;
102+
if (system.arch === "arm64") archiveName += "-aarch64";
101103
archiveFile = `${archiveName}.tar.gz`;
102104
break;
103105
case OS.Windows:

0 commit comments

Comments
 (0)