diff --git a/__tests__/os.test.ts b/__tests__/os.test.ts index 32c73f16..0ecb952d 100644 --- a/__tests__/os.test.ts +++ b/__tests__/os.test.ts @@ -1,7 +1,15 @@ import * as os from "../src/os"; +import getArch from "../src/arch"; jest.mock("getos"); +jest.mock("../src/arch", () => { + return { + __esModule: true, + default: jest.fn(() => "x64"), + }; +}); + const setSystem = require("getos").__setSystem; describe("os resolver", () => { diff --git a/__tests__/swift-versions.test.ts b/__tests__/swift-versions.test.ts index 73fce4e9..e635aae6 100644 --- a/__tests__/swift-versions.test.ts +++ b/__tests__/swift-versions.test.ts @@ -1,9 +1,26 @@ import { OS, System } from "../src/os"; import * as versions from "../src/swift-versions"; -const macOS: System = { os: OS.MacOS, version: "latest", name: "macOS" }; -const ubuntu: System = { os: OS.Ubuntu, version: "latest", name: "Ubuntu" }; -const windows: System = { os: OS.Windows, version: "latest", name: "Windows" }; +const macOS: System = { + os: OS.MacOS, + version: "latest", + name: "macOS", + arch: "arm64", +}; + +const ubuntu: System = { + os: OS.Ubuntu, + version: "latest", + name: "Ubuntu", + arch: "x64", +}; + +const windows: System = { + os: OS.Windows, + version: "latest", + name: "Windows", + arch: "x64", +}; describe("swift version resolver", () => { it("identifies X.X.X versions", async () => { diff --git a/__tests__/visual-studio.test.ts b/__tests__/visual-studio.test.ts index 3dce72c4..259d5aec 100644 --- a/__tests__/visual-studio.test.ts +++ b/__tests__/visual-studio.test.ts @@ -12,7 +12,12 @@ jest.mock("fs", () => { }; }); -const windows: System = { os: OS.Windows, version: "latest", name: "Windows" }; +const windows: System = { + os: OS.Windows, + version: "latest", + name: "Windows", + arch: "x64", +}; describe("visual studio resolver", () => { const env = process.env; diff --git a/dist/index.js b/dist/index.js index 3d011b75..7f091d5d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,6 +1,20 @@ /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ +/***/ 209: +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +function getArch() { + return process.arch; +} +exports["default"] = getArch; + + +/***/ }), + /***/ 951: /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { @@ -372,6 +386,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.getSystem = exports.OS = void 0; const getos_1 = __importDefault(__nccwpck_require__(6068)); +const arch_1 = __importDefault(__nccwpck_require__(209)); var OS; (function (OS) { OS[OS["MacOS"] = 0] = "MacOS"; @@ -395,23 +410,41 @@ async function getSystem() { os ? resolve(os) : reject(error || "No OS detected"); }); }); + const arch = (0, arch_1.default)(); let system; switch (detectedSystem.os) { case "darwin": - system = { os: OS.MacOS, version: "latest", name: "macOS" }; + system = { + os: OS.MacOS, + version: "latest", + name: "macOS", + arch, + }; break; case "linux": if (detectedSystem.dist !== "Ubuntu") { - throw new Error(`"${detectedSystem.dist}" is not a supported linux distribution`); + throw new Error(`"${detectedSystem.dist}" is not a supported Linux distribution`); + } + if (arch !== "x64" && arch !== "arm64") { + throw new Error(`${arch} is not a supported architecture for Linux`); } system = { os: OS.Ubuntu, version: detectedSystem.release, name: "Ubuntu", + arch, }; break; case "win32": - system = { os: OS.Windows, version: "latest", name: "Windows" }; + if (arch !== "x64") { + throw new Error(`${arch} is not a supported architecture for Windows`); + } + system = { + os: OS.Windows, + version: "latest", + name: "Windows", + arch, + }; break; default: throw new Error(`"${detectedSystem.os}" is not a supported platform`); @@ -542,7 +575,11 @@ function swiftPackage(version, system) { break; case os_1.OS.Ubuntu: platform = `ubuntu${system.version.replace(/\D/g, "")}`; + if (system.arch === "arm64") + platform += "-aarch64"; archiveName = `swift-${version}-RELEASE-ubuntu${system.version}`; + if (system.arch === "arm64") + archiveName += "-aarch64"; archiveFile = `${archiveName}.tar.gz`; break; case os_1.OS.Windows: diff --git a/src/arch.ts b/src/arch.ts new file mode 100644 index 00000000..3a317d48 --- /dev/null +++ b/src/arch.ts @@ -0,0 +1,3 @@ +export default function getArch(): string { + return process.arch; +} diff --git a/src/os.ts b/src/os.ts index 3dec1b49..85c4d063 100644 --- a/src/os.ts +++ b/src/os.ts @@ -1,4 +1,5 @@ import getos from "getos"; +import getArch from "./arch"; export enum OS { MacOS, @@ -22,6 +23,7 @@ export interface System { os: OS; version: string; name: string; + arch: string; } export async function getSystem(): Promise { @@ -30,27 +32,45 @@ export async function getSystem(): Promise { os ? resolve(os) : reject(error || "No OS detected"); }); }); + const arch = getArch(); let system: System; switch (detectedSystem.os) { case "darwin": - system = { os: OS.MacOS, version: "latest", name: "macOS" }; + system = { + os: OS.MacOS, + version: "latest", + name: "macOS", + arch, + }; break; case "linux": if (detectedSystem.dist !== "Ubuntu") { throw new Error( - `"${detectedSystem.dist}" is not a supported linux distribution` + `"${detectedSystem.dist}" is not a supported Linux distribution` ); } + if (arch !== "x64" && arch !== "arm64") { + throw new Error(`${arch} is not a supported architecture for Linux`); + } system = { os: OS.Ubuntu, version: detectedSystem.release, name: "Ubuntu", + arch, }; break; case "win32": - system = { os: OS.Windows, version: "latest", name: "Windows" }; + if (arch !== "x64") { + throw new Error(`${arch} is not a supported architecture for Windows`); + } + system = { + os: OS.Windows, + version: "latest", + name: "Windows", + arch, + }; break; default: throw new Error(`"${detectedSystem.os}" is not a supported platform`); diff --git a/src/swift-versions.ts b/src/swift-versions.ts index ef50b0cc..d5c26b79 100644 --- a/src/swift-versions.ts +++ b/src/swift-versions.ts @@ -97,7 +97,9 @@ export function swiftPackage(version: string, system: System): Package { break; case OS.Ubuntu: platform = `ubuntu${system.version.replace(/\D/g, "")}`; + if (system.arch === "arm64") platform += "-aarch64"; archiveName = `swift-${version}-RELEASE-ubuntu${system.version}`; + if (system.arch === "arm64") archiveName += "-aarch64"; archiveFile = `${archiveName}.tar.gz`; break; case OS.Windows: