refactor: simplify baseline version check, add native windows arm64 build
This commit is contained in:
parent
ab8cb4e8f8
commit
a0c4dfc30a
@ -64,10 +64,10 @@ 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(
|
const earch = encodeURIComponent(
|
||||||
getArchitecture(os ?? getPlatform(), arch ?? process.arch),
|
getArchitecture(arch ?? process.arch),
|
||||||
);
|
);
|
||||||
const eavx2 = encodeURIComponent(
|
const eavx2 = encodeURIComponent(
|
||||||
getAvx2(os ?? getPlatform(), arch ?? process.arch, avx2) === false
|
getAvx2(arch ?? process.arch, avx2) === false
|
||||||
? "-baseline"
|
? "-baseline"
|
||||||
: "",
|
: "",
|
||||||
);
|
);
|
||||||
|
|||||||
23
src/utils.ts
23
src/utils.ts
@ -47,28 +47,15 @@ export function getPlatform(): string {
|
|||||||
return platform;
|
return platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getArchitecture(os: string, arch: string): string {
|
export function getArchitecture(arch: string): string {
|
||||||
if (os === "windows" && (arch === "aarch64" || arch === "arm64")) {
|
|
||||||
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";
|
if (arch === "arm64") return "aarch64";
|
||||||
return arch;
|
return arch;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAvx2(os: string, arch: string, avx2?: boolean): boolean {
|
export function getAvx2(arch: string, avx2?: boolean): boolean {
|
||||||
// Temporary workaround for absence of arm64 builds on Windows (#130)
|
// ARM64 architectures do not have a baseline version.
|
||||||
if (os === "windows" && (arch === "aarch64" || arch === "arm64")) {
|
if (arch === "aarch64" || arch === "arm64") {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return avx2 ?? true;
|
return avx2 ?? true;
|
||||||
|
|||||||
@ -9,116 +9,37 @@ describe("getArchitecture", () => {
|
|||||||
warningSpy?.mockRestore();
|
warningSpy?.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return x64 for Windows with arm64 architecture", () => {
|
it("should return aarch64 for arm64 architecture on all platforms", () => {
|
||||||
warningSpy = spyOn(core, "warning");
|
expect(getArchitecture("arm64")).toBe("aarch64");
|
||||||
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", () => {
|
it("should return aarch64 for aarch64 architecture", () => {
|
||||||
warningSpy = spyOn(core, "warning");
|
expect(getArchitecture("aarch64")).toBe("aarch64");
|
||||||
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", () => {
|
it("should return original arch value for x64", () => {
|
||||||
warningSpy = spyOn(core, "warning");
|
expect(getArchitecture("x64")).toBe("x64");
|
||||||
const result = getArchitecture("windows", "x64");
|
|
||||||
|
|
||||||
expect(result).toBe("x64");
|
|
||||||
expect(warningSpy).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return original arch value for x86", () => {
|
it("should return original arch value for x86", () => {
|
||||||
warningSpy = spyOn(core, "warning");
|
expect(getArchitecture("x86")).toBe("x86");
|
||||||
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", () => {
|
describe("getAvx2", () => {
|
||||||
it("should return false when called with os: 'windows' and arch: 'arm64'", () => {
|
it("should return true for ARM64 architectures", () => {
|
||||||
const result = getAvx2("windows", "arm64");
|
expect(getAvx2("arm64")).toBe(true);
|
||||||
expect(result).toBe(false);
|
expect(getAvx2("aarch64")).toBe(true);
|
||||||
|
expect(getAvx2("arm64", false)).toBe(true);
|
||||||
|
expect(getAvx2("aarch64", false)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return false when called with os: 'windows' and arch: 'aarch64'", () => {
|
it("should return the provided avx2 value when specified for x64", () => {
|
||||||
const result = getAvx2("windows", "aarch64");
|
expect(getAvx2("x64", true)).toBe(true);
|
||||||
expect(result).toBe(false);
|
expect(getAvx2("x64", false)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return false when called with os: 'windows', arch: 'arm64', and avx2: true", () => {
|
it("should return true by default when avx2 is not specified for x64", () => {
|
||||||
const result = getAvx2("windows", "arm64", true);
|
expect(getAvx2("x64")).toBe(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);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user