forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-native-host.mjs
More file actions
73 lines (64 loc) · 2.18 KB
/
Copy pathvalidate-native-host.mjs
File metadata and controls
73 lines (64 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import { pathToFileURL } from "node:url";
export function validateNativeHost(classifier, host) {
if (classifier === "linux-x64") {
if (host.platform !== "linux" || host.arch !== "x64") {
throw new Error(
`Native ${classifier} packaging requires Linux x64; detected ${host.platform}-${host.arch}`,
);
}
if (!host.glibcVersionRuntime) {
throw new Error(
`Native ${classifier} packaging requires glibc; musl and unknown libc hosts are unsupported`,
);
}
return `Validated native build host: ${classifier} (glibc ${host.glibcVersionRuntime})`;
}
if (classifier === "win32-x64") {
if (host.platform !== "win32" || host.arch !== "x64") {
throw new Error(
`Native ${classifier} packaging requires Windows x64; detected ${host.platform}-${host.arch}`,
);
}
return `Validated native build host: ${classifier}`;
}
if (classifier === "darwin-arm64") {
if (host.platform !== "darwin" || host.arch !== "arm64") {
throw new Error(
`Native ${classifier} packaging requires macOS ARM64; detected ${host.platform}-${host.arch}`,
);
}
return `Validated native build host: ${classifier}`;
}
throw new Error(`Unsupported native build classifier: ${classifier}`);
}
export function detectNativeHost() {
const report = process.report?.getReport();
return {
platform: process.platform,
arch: process.arch,
glibcVersionRuntime: report?.header?.glibcVersionRuntime,
};
}
function main() {
const [classifier] = process.argv.slice(2);
if (!classifier) {
console.error("Usage: node validate-native-host.mjs <classifier>");
process.exitCode = 1;
return;
}
try {
console.log(validateNativeHost(classifier, detectNativeHost()));
} catch (error) {
console.error(error.message);
process.exitCode = 1;
}
}
if (
process.argv[1] &&
import.meta.url === pathToFileURL(process.argv[1]).href
) {
main();
}