Download for desktop app
This commit is contained in:
+42
-29
@@ -3,10 +3,6 @@
|
||||
// so this moves the launcher to bworld-bin and puts a script in its place that starts it with the switches webgpu
|
||||
// needs on some linux setups. run it on the app folder after deno desktop builds it; running it again does nothing
|
||||
|
||||
if (Deno.build.os !== "linux") {
|
||||
Deno.exit(0);
|
||||
}
|
||||
|
||||
const SWITCHES = [
|
||||
"--enable-unsafe-webgpu",
|
||||
"--ozone-platform=x11",
|
||||
@@ -14,30 +10,36 @@ const SWITCHES = [
|
||||
"--enable-features=Vulkan,VulkanFromANGLE",
|
||||
];
|
||||
|
||||
const dir = Deno.args[0];
|
||||
if (!dir) {
|
||||
console.error("usage: linux_launcher.ts <app folder>, like dist/bworld");
|
||||
Deno.exit(1);
|
||||
}
|
||||
const name = dir.replace(/\/+$/, "").split("/").pop()!;
|
||||
const launcher = `${dir}/${name}`;
|
||||
const binary = `${launcher}-bin`;
|
||||
|
||||
// already wrapped: the launcher is a script now
|
||||
const head = new Uint8Array(4);
|
||||
const file = Deno.openSync(launcher);
|
||||
file.readSync(head);
|
||||
file.close();
|
||||
const is_elf = head[0] === 0x7f && head[1] === 0x45 && head[2] === 0x4c && head[3] === 0x46;
|
||||
if (!is_elf) {
|
||||
console.log(`${launcher} is already wrapped`);
|
||||
Deno.exit(0);
|
||||
if (import.meta.main) {
|
||||
// on its own it's run after building for the os it's on, which only needs wrapping on linux
|
||||
if (Deno.build.os !== "linux") {
|
||||
Deno.exit(0);
|
||||
}
|
||||
const dir = Deno.args[0];
|
||||
if (!dir) {
|
||||
console.error("usage: linux_launcher.ts <app folder>, like dist/bworld");
|
||||
Deno.exit(1);
|
||||
}
|
||||
wrap_linux_launcher(dir);
|
||||
}
|
||||
|
||||
Deno.renameSync(launcher, binary);
|
||||
Deno.writeTextFileSync(
|
||||
launcher,
|
||||
`#!/bin/sh
|
||||
// wraps the launcher of a linux build in dir. it works from any os, see tools/desktop_all.ts, but the script is only
|
||||
// made executable on unix: zipping it from windows has to set that itself
|
||||
export function wrap_linux_launcher(dir: string) {
|
||||
const name = dir.replace(/[\/\\]+$/, "").split(/[\/\\]/).pop()!;
|
||||
const launcher = `${dir}/${name}`;
|
||||
const binary = `${launcher}-bin`;
|
||||
|
||||
// already wrapped: the launcher is a script now
|
||||
if (!is_elf(launcher)) {
|
||||
console.log(`${launcher} is already wrapped`);
|
||||
return;
|
||||
}
|
||||
|
||||
Deno.renameSync(launcher, binary);
|
||||
Deno.writeTextFileSync(
|
||||
launcher,
|
||||
`#!/bin/sh
|
||||
# starts ${name} with the chromium switches webgpu needs on some linux setups, see desktop/linux_launcher.ts.
|
||||
# BWORLD_CHROMIUM_FLAGS replaces them, set it to "" to start without any
|
||||
here="$(dirname "$(readlink -f "$0")")"
|
||||
@@ -45,6 +47,17 @@ here="$(dirname "$(readlink -f "$0")")"
|
||||
export LAUFEY_RUNTIME_PATH="$here/${name}.so"
|
||||
exec "$here/${name}-bin" \${BWORLD_CHROMIUM_FLAGS-${SWITCHES.join(" ")}} "$@"
|
||||
`,
|
||||
);
|
||||
Deno.chmodSync(launcher, 0o755);
|
||||
console.log(`Wrapped ${launcher}: ${SWITCHES.join(" ")}`);
|
||||
);
|
||||
if (Deno.build.os !== "windows") {
|
||||
Deno.chmodSync(launcher, 0o755);
|
||||
}
|
||||
console.log(`Wrapped ${launcher}: ${SWITCHES.join(" ")}`);
|
||||
}
|
||||
|
||||
export function is_elf(path: string) {
|
||||
const head = new Uint8Array(4);
|
||||
const file = Deno.openSync(path);
|
||||
file.readSync(head);
|
||||
file.close();
|
||||
return head[0] === 0x7f && head[1] === 0x45 && head[2] === 0x4c && head[3] === 0x46;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user