Windows build
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// deno task compile [linux] [windows]
|
||||
// builds the mods and the client once, then the desktop app as one executable for each os given, this one's by default:
|
||||
// dist/cubi for linux and dist/cubi.exe for windows. each has everything the app reads inside it, and the libraries in
|
||||
// desktop/<os>/ when there are any (see desktop/libraries.ts)
|
||||
import { existsSync } from "@std/fs";
|
||||
|
||||
const TARGETS: Record<string, { target: string; output: string; flags: string[] }> = {
|
||||
linux: { target: "x86_64-unknown-linux-gnu", output: "dist/cubi", flags: [] },
|
||||
// a game, not a console program. what goes wrong is shown in a message box, see desktop/main.ts
|
||||
windows: { target: "x86_64-pc-windows-msvc", output: "dist/cubi.exe", flags: ["--no-terminal"] },
|
||||
};
|
||||
|
||||
// the same as deno task desktop
|
||||
const PERMISSIONS = [
|
||||
"--unstable-webgpu",
|
||||
"--allow-read",
|
||||
"--allow-write",
|
||||
"--allow-net",
|
||||
"--allow-ffi",
|
||||
"--allow-env=CUBI_SERVER,CUBI_CLIENT_UPDATES,HOME,USERPROFILE,APPDATA,XDG_DATA_HOME",
|
||||
];
|
||||
|
||||
// what the app reads that deno doesn't find by following its imports: what the build made, the server's workers and
|
||||
// the app's config
|
||||
const INCLUDES = [
|
||||
"build",
|
||||
"server_mods",
|
||||
"server/game/worker.ts",
|
||||
"server/game/worldgen_worker.ts",
|
||||
"server/content_worker.ts",
|
||||
"desktop/config.json",
|
||||
];
|
||||
|
||||
async function deno(args: string[]) {
|
||||
const { success } = await new Deno.Command(Deno.execPath(), { args, stdout: "inherit", stderr: "inherit" })
|
||||
.output();
|
||||
if (!success) Deno.exit(1);
|
||||
}
|
||||
|
||||
const oses = Deno.args.length > 0 ? Deno.args : [Deno.build.os];
|
||||
for (const os of oses) {
|
||||
if (!TARGETS[os]) throw new Error(`Can't compile for ${os}, only for ${Object.keys(TARGETS).join(" and ")}`);
|
||||
}
|
||||
|
||||
await deno(["run", "-A", "build.ts", "--once"]);
|
||||
for (const os of oses) {
|
||||
const { target, output, flags } = TARGETS[os];
|
||||
const libraries = existsSync(`desktop/${os}`) ? [`desktop/${os}`] : [];
|
||||
await deno([
|
||||
"compile",
|
||||
"--target",
|
||||
target,
|
||||
...flags,
|
||||
...PERMISSIONS,
|
||||
...[...INCLUDES, ...libraries].flatMap((path) => ["--include", path]),
|
||||
"--output",
|
||||
output,
|
||||
"desktop/main.ts",
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user