-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdeps.ts
52 lines (47 loc) · 1.67 KB
/
deps.ts
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
// Deno WebUI
// Resolves the path to the required native WebUI library,
// ensuring it is downloaded to a central cache if needed.
import { ensureWebUiLib } from "./src/utils.ts";
// Determine the base library filename based
// on the current operating system and architecture.
function getBaseLibName(): string {
let baseName: string;
switch (Deno.build.os) {
case "windows":
baseName = "webui-2.dll";
// Validate architecture for Windows
if (Deno.build.arch !== "x86_64" && Deno.build.arch !== "aarch64") {
throw new Error(
`Unsupported architecture ${Deno.build.arch} for Windows`,
);
}
break;
case "darwin": // macOS
baseName = "libwebui-2.dylib";
// Validate architecture for macOS
if (Deno.build.arch !== "x86_64" && Deno.build.arch !== "aarch64") {
throw new Error(
`Unsupported architecture ${Deno.build.arch} for macOS`,
);
}
break;
default: // Linux and other Unix-like OSes
baseName = "libwebui-2.so";
// Validate architecture for Linux/others
if (Deno.build.arch !== "x86_64" && Deno.build.arch !== "aarch64") {
throw new Error(
`Unsupported architecture ${Deno.build.arch} for ${Deno.build.os}`,
);
}
break;
}
return baseName;
}
// Determine the required base filename
const baseLibName = getBaseLibName();
// Ensure the library exists in the cache (downloads if needed)
// and export the resolved path.
// This promise resolves to the final path of the library file.
export const libPath = await ensureWebUiLib(baseLibName);
// Optional: Export the base name too if needed elsewhere
export { baseLibName };