enhance: backward compatibility with simulated x64 version
This commit is contained in:
parent
a0c4dfc30a
commit
24feafd6b4
96
dist/setup/index.js
generated
vendored
96
dist/setup/index.js
generated
vendored
File diff suppressed because one or more lines are too long
@ -5,7 +5,14 @@ import {
|
|||||||
validateStrict,
|
validateStrict,
|
||||||
} from "compare-versions";
|
} from "compare-versions";
|
||||||
import { Input } from "./action";
|
import { Input } from "./action";
|
||||||
import { getArchitecture, getAvx2, getPlatform, request } from "./utils";
|
import {
|
||||||
|
getArchitecture,
|
||||||
|
getAvx2,
|
||||||
|
getPlatform,
|
||||||
|
isWindowsArm64Supported,
|
||||||
|
request,
|
||||||
|
warnWindowsArm64,
|
||||||
|
} from "./utils";
|
||||||
|
|
||||||
export async function getDownloadUrl(options: Input): Promise<string> {
|
export async function getDownloadUrl(options: Input): Promise<string> {
|
||||||
const { customUrl } = options;
|
const { customUrl } = options;
|
||||||
@ -63,13 +70,21 @@ 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(
|
|
||||||
getArchitecture(arch ?? process.arch),
|
let archValue = arch ?? process.arch;
|
||||||
);
|
let avx2Value = avx2;
|
||||||
|
|
||||||
|
if (eos === "windows" && getArchitecture(archValue) === "aarch64") {
|
||||||
|
if (!isWindowsArm64Supported(tag ?? version)) {
|
||||||
|
warnWindowsArm64();
|
||||||
|
archValue = "x64";
|
||||||
|
avx2Value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const earch = encodeURIComponent(getArchitecture(archValue));
|
||||||
const eavx2 = encodeURIComponent(
|
const eavx2 = encodeURIComponent(
|
||||||
getAvx2(arch ?? process.arch, avx2) === false
|
getAvx2(archValue, avx2Value) === false ? "-baseline" : "",
|
||||||
? "-baseline"
|
|
||||||
: "",
|
|
||||||
);
|
);
|
||||||
const eprofile = encodeURIComponent(profile === true ? "-profile" : "");
|
const eprofile = encodeURIComponent(profile === true ? "-profile" : "");
|
||||||
|
|
||||||
|
|||||||
20
src/utils.ts
20
src/utils.ts
@ -1,3 +1,4 @@
|
|||||||
|
import { compareVersions, validate } from "compare-versions";
|
||||||
import { debug, warning } from "@actions/core";
|
import { debug, warning } from "@actions/core";
|
||||||
import { info } from "node:console";
|
import { info } from "node:console";
|
||||||
import { createHash } from "node:crypto";
|
import { createHash } from "node:crypto";
|
||||||
@ -61,6 +62,25 @@ export function getAvx2(arch: string, avx2?: boolean): boolean {
|
|||||||
return avx2 ?? true;
|
return avx2 ?? true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isWindowsArm64Supported(tag: string): boolean {
|
||||||
|
if (tag === "canary" || tag === "latest") return true;
|
||||||
|
|
||||||
|
const version = tag.startsWith("bun-v") ? tag.slice(5) : tag;
|
||||||
|
|
||||||
|
return validate(version) && compareVersions(version, "1.3.10") >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function warnWindowsArm64(): void {
|
||||||
|
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"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test";
|
import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test";
|
||||||
import { getDownloadUrl } from "../src/download-url";
|
import { getDownloadUrl } from "../src/download-url";
|
||||||
import * as utils from "../src/utils";
|
import * as utils from "../src/utils";
|
||||||
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
const MOCK_TAGS = [
|
const MOCK_TAGS = [
|
||||||
{ ref: "refs/tags/bun-v0.5.0" },
|
{ ref: "refs/tags/bun-v0.5.0" },
|
||||||
@ -158,4 +159,49 @@ describe("getDownloadUrl", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Windows ARM64 Fallback", () => {
|
||||||
|
it("should fallback to x64-baseline for versions older than 1.3.10 and log a warning", async () => {
|
||||||
|
const warningSpy = spyOn(core, "warning");
|
||||||
|
const url = await getDownloadUrl({
|
||||||
|
version: "1.1.0",
|
||||||
|
os: "windows",
|
||||||
|
arch: "arm64",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(url).toBe(
|
||||||
|
"https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-windows-x64-baseline.zip",
|
||||||
|
);
|
||||||
|
expect(warningSpy).toHaveBeenCalled();
|
||||||
|
expect(warningSpy.mock.calls[0][0]).toContain(
|
||||||
|
"Bun does not provide native arm64 builds for Windows",
|
||||||
|
);
|
||||||
|
warningSpy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should use aarch64 for version 1.3.10", async () => {
|
||||||
|
const url = await getDownloadUrl({
|
||||||
|
version: "1.3.10",
|
||||||
|
os: "windows",
|
||||||
|
arch: "arm64",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(url).toBe(
|
||||||
|
"https://github.com/oven-sh/bun/releases/download/bun-v1.3.10/bun-windows-aarch64.zip",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should use aarch64 for canary", async () => {
|
||||||
|
const url = await getDownloadUrl({
|
||||||
|
version: "canary",
|
||||||
|
os: "windows",
|
||||||
|
arch: "arm64",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(url).toBe(
|
||||||
|
"https://github.com/oven-sh/bun/releases/download/canary/bun-windows-aarch64.zip",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user