feat: fallback arm64 to x64 architecture for win32 platform (#131)
* feat: fallback arm64 to x64 architecture for win32 platform closes https://github.com/oven-sh/setup-bun/issues/130 * [autofix.ci] apply automated fixes * ci: test on windows-11-arm runner * refactor: move logic to getEffectiveArch func * [autofix.ci] apply automated fixes * feat: add warning message for windows arm64 fallback to x64 * [autofix.ci] apply automated fixes * feat: don't mention arch in warning msg aboout fallback * [autofix.ci] apply automated fixes * debug time * [autofix.ci] apply automated fixes * feat: force baseline for win32 arm fallback to x64 * [autofix.ci] apply automated fixes * ci: dont use windows-11-arm on setup bun from download url * fix * [autofix.ci] apply automated fixes * fix * [autofix.ci] apply automated fixes * fix * [autofix.ci] apply automated fixes * fix * [autofix.ci] apply automated fixes * fix * [autofix.ci] apply automated fixes * apply changes Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * [autofix.ci] apply automated fixes * docs: clarify * [autofix.ci] apply automated fixes * test: add unit tests for getAvx2 Windows ARM64 fallback logic (#154) * Initial plan * Add unit tests for getAvx2 function Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> * Consolidate duplicate test assertions in getAvx2 tests Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> * Fix whitespace formatting in test file Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> * test: add unit tests for getArchitecture and getAvx2 Windows ARM64 fallback logic (#153) * Initial plan * Add unit tests for getArchitecture function Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> * Remove unused import in utils.spec.ts Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Merge pr-131 and resolve test file conflicts Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> Co-authored-by: Jozef Steinhübl <generalkubo@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -50,6 +50,7 @@ jobs:
|
|||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- macos-latest
|
- macos-latest
|
||||||
- windows-latest
|
- windows-latest
|
||||||
|
- windows-11-arm
|
||||||
bun-version:
|
bun-version:
|
||||||
- latest
|
- latest
|
||||||
- canary
|
- canary
|
||||||
@@ -98,6 +99,7 @@ jobs:
|
|||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- macos-latest
|
- macos-latest
|
||||||
- windows-latest
|
- windows-latest
|
||||||
|
- windows-11-arm
|
||||||
|
|
||||||
file:
|
file:
|
||||||
- name: package.json (packageManager bun@1.1.0)
|
- name: package.json (packageManager bun@1.1.0)
|
||||||
|
|||||||
215
dist/setup/index.js
generated
vendored
215
dist/setup/index.js
generated
vendored
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
|||||||
import { compareVersions, satisfies, validate } from "compare-versions";
|
import { compareVersions, satisfies, validate } from "compare-versions";
|
||||||
import { Input } from "./action";
|
import { Input } from "./action";
|
||||||
import { getArchitecture, getPlatform, request } from "./utils";
|
import { getArchitecture, getAvx2, getPlatform, request } from "./utils";
|
||||||
|
|
||||||
export async function getDownloadUrl(options: Input): Promise<string> {
|
export async function getDownloadUrl(options: Input): Promise<string> {
|
||||||
const { customUrl } = options;
|
const { customUrl } = options;
|
||||||
@@ -50,8 +50,14 @@ async function getSemverDownloadUrl(options: Input): Promise<string> {
|
|||||||
|
|
||||||
const eversion = encodeURIComponent(tag ?? version);
|
const eversion = encodeURIComponent(tag ?? version);
|
||||||
const eos = encodeURIComponent(os ?? getPlatform());
|
const eos = encodeURIComponent(os ?? getPlatform());
|
||||||
const earch = encodeURIComponent(arch ?? getArchitecture());
|
const earch = encodeURIComponent(
|
||||||
const eavx2 = encodeURIComponent(avx2 === false ? "-baseline" : "");
|
getArchitecture(os ?? getPlatform(), arch ?? process.arch),
|
||||||
|
);
|
||||||
|
const eavx2 = encodeURIComponent(
|
||||||
|
getAvx2(os ?? getPlatform(), arch ?? process.arch, avx2) === false
|
||||||
|
? "-baseline"
|
||||||
|
: "",
|
||||||
|
);
|
||||||
const eprofile = encodeURIComponent(profile === true ? "-profile" : "");
|
const eprofile = encodeURIComponent(profile === true ? "-profile" : "");
|
||||||
|
|
||||||
const { href } = new URL(
|
const { href } = new URL(
|
||||||
|
|||||||
26
src/utils.ts
26
src/utils.ts
@@ -42,13 +42,33 @@ export function getPlatform(): string {
|
|||||||
return platform;
|
return platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getArchitecture(): string {
|
export function getArchitecture(os: string, arch: string): string {
|
||||||
const arch = process.arch;
|
if (os === "windows" && (arch === "aarch64" || arch === "arm64")) {
|
||||||
if (arch === "arm64") return "aarch64";
|
warning(
|
||||||
|
[
|
||||||
|
"⚠️ Bun does not provide native arm64 builds for Windows.",
|
||||||
|
"Using x64 baseline build which will run through Microsoft's x64 emulation layer.",
|
||||||
|
"This may result in reduced performance and potential compatibility issues.",
|
||||||
|
"💡 For best performance, consider using x64 Windows runners or other platforms with native support.",
|
||||||
|
].join("\n"),
|
||||||
|
);
|
||||||
|
|
||||||
|
return "x64";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arch === "arm64") return "aarch64";
|
||||||
return arch;
|
return arch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getAvx2(os: string, arch: string, avx2?: boolean): boolean {
|
||||||
|
// Temporary workaround for absence of arm64 builds on Windows (#130)
|
||||||
|
if (os === "windows" && (arch === "aarch64" || arch === "arm64")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return avx2 ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
const FILE_VERSION_READERS = {
|
const FILE_VERSION_READERS = {
|
||||||
"package.json": (content: string) => {
|
"package.json": (content: string) => {
|
||||||
const pkg = JSON.parse(content);
|
const pkg = JSON.parse(content);
|
||||||
|
|||||||
124
tests/utils.spec.ts
Normal file
124
tests/utils.spec.ts
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
import { afterEach, describe, expect, it, spyOn } from "bun:test";
|
||||||
|
import { getArchitecture, getAvx2 } from "../src/utils";
|
||||||
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
|
describe("getArchitecture", () => {
|
||||||
|
let warningSpy: ReturnType<typeof spyOn>;
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
warningSpy?.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return x64 for Windows with arm64 architecture", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("windows", "arm64");
|
||||||
|
|
||||||
|
expect(result).toBe("x64");
|
||||||
|
expect(warningSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(warningSpy).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining(
|
||||||
|
"⚠️ Bun does not provide native arm64 builds for Windows."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return x64 for Windows with aarch64 architecture", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("windows", "aarch64");
|
||||||
|
|
||||||
|
expect(result).toBe("x64");
|
||||||
|
expect(warningSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(warningSpy).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining(
|
||||||
|
"⚠️ Bun does not provide native arm64 builds for Windows."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return aarch64 for non-Windows platforms with arm64", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("linux", "arm64");
|
||||||
|
|
||||||
|
expect(result).toBe("aarch64");
|
||||||
|
expect(warningSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return aarch64 for macOS with arm64", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("darwin", "arm64");
|
||||||
|
|
||||||
|
expect(result).toBe("aarch64");
|
||||||
|
expect(warningSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return original arch value for x64", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("windows", "x64");
|
||||||
|
|
||||||
|
expect(result).toBe("x64");
|
||||||
|
expect(warningSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return original arch value for x86", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("linux", "x86");
|
||||||
|
|
||||||
|
expect(result).toBe("x86");
|
||||||
|
expect(warningSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return original arch value for aarch64 on Linux", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("linux", "aarch64");
|
||||||
|
|
||||||
|
expect(result).toBe("aarch64");
|
||||||
|
expect(warningSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getAvx2", () => {
|
||||||
|
it("should return false when called with os: 'windows' and arch: 'arm64'", () => {
|
||||||
|
const result = getAvx2("windows", "arm64");
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false when called with os: 'windows' and arch: 'aarch64'", () => {
|
||||||
|
const result = getAvx2("windows", "aarch64");
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false when called with os: 'windows', arch: 'arm64', and avx2: true", () => {
|
||||||
|
const result = getAvx2("windows", "arm64", true);
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false when called with os: 'windows', arch: 'aarch64', and avx2: false", () => {
|
||||||
|
const result = getAvx2("windows", "aarch64", false);
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return the provided avx2 value (true) when specified and not on Windows ARM64", () => {
|
||||||
|
expect(getAvx2("linux", "x64", true)).toBe(true);
|
||||||
|
expect(getAvx2("darwin", "x64", true)).toBe(true);
|
||||||
|
expect(getAvx2("windows", "x64", true)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return the provided avx2 value (false) when specified and not on Windows ARM64", () => {
|
||||||
|
expect(getAvx2("linux", "x64", false)).toBe(false);
|
||||||
|
expect(getAvx2("darwin", "x64", false)).toBe(false);
|
||||||
|
expect(getAvx2("windows", "x64", false)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return true by default when avx2 is not specified and not on Windows ARM64", () => {
|
||||||
|
// x64 architecture on various platforms
|
||||||
|
expect(getAvx2("linux", "x64")).toBe(true);
|
||||||
|
expect(getAvx2("darwin", "x64")).toBe(true);
|
||||||
|
expect(getAvx2("windows", "x64")).toBe(true);
|
||||||
|
|
||||||
|
// ARM architecture on non-Windows platforms
|
||||||
|
expect(getAvx2("linux", "arm64")).toBe(true);
|
||||||
|
expect(getAvx2("linux", "aarch64")).toBe(true);
|
||||||
|
expect(getAvx2("darwin", "arm64")).toBe(true);
|
||||||
|
expect(getAvx2("darwin", "aarch64")).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user