// SPDX-FileCopyrightText: 2026 Paula Wisnievski // SPDX-License-Identifier: AGPL-3.0-or-later // deno run --allow-read --allow-write desktop/linux_launcher.ts dist/bworld // deno desktop has no setting for chromium's command line, but its linux launcher passes its arguments on to chromium. // 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 const SWITCHES = [ "--enable-features=UseOzonePlatform,Vulkan,VulkanFromANGLE", // "--enable-unsafe-webgpu", "--use-angle=vulkan", "--ozone-platform=wayland", "--enable-wayland-ime", "--wayland-text-input-version=3", ]; 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 , like dist/cubi"); Deno.exit(1); } wrap_linux_launcher(dir); } // 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. # CUBI_CHROMIUM_FLAGS replaces them, set it to "" to start without any here="$(dirname "$(readlink -f "$0")")" # the binary finds its runtime by its own name, which is ${name}.so and not ${name}-bin.so export LAUFEY_RUNTIME_PATH="$here/${name}.so" exec "$here/${name}-bin" \${CUBI_CHROMIUM_FLAGS-${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; }