Files
setup-uv/src/utils/platforms.ts
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
1.9 KiB
TypeScript
Raw Normal View History

2025-02-17 10:32:34 +01:00
import * as core from "@actions/core";
2025-08-12 22:12:10 +02:00
import * as exec from "@actions/exec";
2024-08-23 23:58:26 +02:00
export type Platform =
2024-09-05 08:06:45 -04:00
| "unknown-linux-gnu"
| "unknown-linux-musl"
| "unknown-linux-musleabihf"
| "apple-darwin"
| "pc-windows-msvc";
2025-02-16 05:30:44 +08:00
export type Architecture =
| "i686"
| "x86_64"
| "aarch64"
| "s390x"
| "powerpc64le";
2024-08-23 23:58:26 +02:00
export function getArch(): Architecture | undefined {
2024-09-05 08:06:45 -04:00
const arch = process.arch;
const archMapping: { [key: string]: Architecture } = {
arm64: "aarch64",
2025-08-12 22:12:10 +02:00
ia32: "i686",
2025-02-16 05:30:44 +08:00
ppc64: "powerpc64le",
2025-08-12 22:12:10 +02:00
s390x: "s390x",
x64: "x86_64",
2024-09-05 08:06:45 -04:00
};
2024-08-23 23:58:26 +02:00
if (arch in archMapping) {
2024-09-05 08:06:45 -04:00
return archMapping[arch];
2024-08-23 23:58:26 +02:00
}
}
2025-02-17 10:32:34 +01:00
export async function getPlatform(): Promise<Platform | undefined> {
const processPlatform = process.platform;
2024-09-05 08:06:45 -04:00
const platformMapping: { [key: string]: Platform } = {
darwin: "apple-darwin",
2025-08-12 22:12:10 +02:00
linux: "unknown-linux-gnu",
2024-09-05 08:06:45 -04:00
win32: "pc-windows-msvc",
};
2024-08-23 23:58:26 +02:00
2025-02-17 10:32:34 +01:00
if (processPlatform in platformMapping) {
const platform = platformMapping[processPlatform];
if (platform === "unknown-linux-gnu") {
const isMusl = await isMuslOs();
return isMusl ? "unknown-linux-musl" : platform;
}
return platform;
}
}
async function isMuslOs(): Promise<boolean> {
let stdOutput = "";
let errOutput = "";
const options: exec.ExecOptions = {
2025-08-12 22:12:10 +02:00
ignoreReturnCode: true,
2025-02-17 10:32:34 +01:00
listeners: {
stderr: (data: Buffer) => {
errOutput += data.toString();
},
2025-08-12 22:12:10 +02:00
stdout: (data: Buffer) => {
stdOutput += data.toString();
},
2025-02-17 10:32:34 +01:00
},
2025-08-12 22:12:10 +02:00
silent: !core.isDebug(),
2025-02-17 10:32:34 +01:00
};
try {
const execArgs = ["--version"];
await exec.exec("ldd", execArgs, options);
return stdOutput.includes("musl") || errOutput.includes("musl");
} catch (error) {
const err = error as Error;
core.warning(
`Failed to determine glibc or musl. Falling back to glibc. Error: ${err.message}`,
);
return false;
2024-08-23 23:58:26 +02:00
}
}