windows: the app's tray, and its Windows build from Linux

- Tray (gpui-tray): a shield coloured by how things are (working, one
  failed, all off, no service), its tooltip saying which; the menu opens
  the window and switches the local proxy, the DPI bypass and the Telegram
  proxy, with their states checked; Quit. Closing the window leaves the
  app in the tray (no tray: it quits); --hidden starts it there.
- The app builds for Windows from Linux: GPUI compiles its HLSL shaders
  with fxc.exe only when the building machine is Windows, so its Windows
  backend is vendored with that one check made on the target instead
  (vendor/gpui-pre-windows/PATCHED.md, tools/vendor-gpui-windows.py), and
  tools/fxc-wine.sh runs Microsoft's fxc.exe under Wine: the compiler from
  the Windows SDK 10.0.26100 installer, pinned by hash, kept on the build
  machine; only the compiled shaders go into the app.
- gui-shot.sh keeps the app off the desktop's session bus.

Under Wine the app starts but cannot draw text (Wine's DirectWrite does
not implement font-set matching), so its Windows rendering is untested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-27 02:03:18 +03:00
1 parent a7bf347859
commit 77becc235c
35 files changed
+15691 -29

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# fxc.exe, Microsoft's HLSL compiler, under Wine: GPUI's shaders, when the app is cross-compiled
# for Windows (GPUI_FXC_PATH names this; see tools/vendor-gpui-windows.py). The compiler comes
# from the Windows SDK 10.0.26100 that Visual Studio's installer offers, pinned by hash, and
# stays on this machine: only the shaders it compiles go into the app.
#
# GPUI_FXC_PATH=$PWD/tools/fxc-wine.sh cargo xwin build --release -p ps-gui --target x86_64-pc-windows-msvc
set -euo pipefail
CACHE=${XDG_CACHE_HOME:-$HOME/.cache}/proxy-suite-windows/fxc-10.0.26100
CAB_URL=https://download.visualstudio.microsoft.com/download/pr/6452c1f1-dc1e-413c-8b19-991b61870a8b/944d105a33e16da614cbf2a17da22954/69661e20556b3ca9456b946c2c881ddd.cab
CAB_SHA256=bef5b038fce288fa1db234bd61c3e450abecc02f5a386248625073a83010f61e
FXC_SHA256=31fa10504b1551337de4d06ec2194143885a76a8b5a81177999e2faa34729183
DLL_SHA256=2b23efdc8b45adc4b79c1c0b940a906336628cd35ed80defd489d70d22ff6d74
# Their names in the cab: the File table of "Windows SDK for Windows Store Apps Tools", bin/10.0.26100.0/x64.
FXC_IN_CAB=fil6dfaf6bbf56939fbab75b569ffa0fd41
DLL_IN_CAB=fil0d3f984977487cd87127d614f654195b
here=$(dirname "$(realpath "$0")")
pkg() { nix build --no-link --print-out-paths --inputs-from "$here/.." "nixpkgs#$1" | head -1; }
verified() {
[ -f "$CACHE/fxc.exe" ] && [ -f "$CACHE/d3dcompiler_47.dll" ] &&
echo "$FXC_SHA256 $CACHE/fxc.exe" | sha256sum -c --quiet 2>/dev/null &&
echo "$DLL_SHA256 $CACHE/d3dcompiler_47.dll" | sha256sum -c --quiet 2>/dev/null
}
if ! verified; then
mkdir -p "$CACHE"
tmp=$(mktemp -d)
curl -sSfL -o "$tmp/tools.cab" "$CAB_URL"
echo "$CAB_SHA256 $tmp/tools.cab" | sha256sum -c --quiet
(cd "$tmp" && "$(pkg gcab.bin)/bin/gcab" -x tools.cab "$FXC_IN_CAB" "$DLL_IN_CAB")
mv "$tmp/$FXC_IN_CAB" "$CACHE/fxc.exe"
mv "$tmp/$DLL_IN_CAB" "$CACHE/d3dcompiler_47.dll"
rm -rf "$tmp"
verified || { echo "fxc-wine.sh: the extracted compiler does not match its hashes" >&2; exit 1; }
fi
WINE=$(pkg wineWow64Packages.stable)/bin
export WINEPREFIX=$CACHE/wine WINEDEBUG=-all WINEDLLOVERRIDES="mscoree,mshtml="
[ -d "$WINEPREFIX" ] || "$WINE/wineboot" -i >/dev/null 2>&1 || true
# Unix paths (the shader sources, the headers it writes) as Wine's Z: paths; a lone /X is a switch.
args=()
for a in "$@"; do
if [[ $a == /*/* ]]; then args+=("$("$WINE/winepath" -w "$a")"); else args+=("$a"); fi
done
exec "$WINE/wine" "$CACHE/fxc.exe" "${args[@]}"
+2 -1
View File
@@ -26,7 +26,8 @@ XPID=$!
trap 'kill "${APID:-}" "$XPID" 2>/dev/null || true' EXIT
for _ in $(seq 50); do [ -e "/tmp/.X11-unix/X$n" ] && break; sleep 0.1; done
env -u WAYLAND_DISPLAY DISPLAY=":$n" VK_ICD_FILENAMES="$MESA/share/vulkan/icd.d/lvp_icd.x86_64.json" \
# Not the desktop's session bus: the app's tray icon would appear on the real desktop.
env -u WAYLAND_DISPLAY -u DBUS_SESSION_BUS_ADDRESS DISPLAY=":$n" VK_ICD_FILENAMES="$MESA/share/vulkan/icd.d/lvp_icd.x86_64.json" \
"$APP" "$@" >"${OUT%.png}.log" 2>&1 &
APID=$!
sleep "$WAIT"
+80
View File
@@ -0,0 +1,80 @@
#!/usr/bin/env python3
"""GPUI's Windows backend, vendored with its build script patched, into vendor/gpui-pre-windows.
Upstream compiles the HLSL shaders (with fxc.exe) only when the machine building is Windows:
its build script asks `cfg!(target_os = "windows")`, which in a build script is the host.
Cross-compiled from Linux, the release library then fails for want of the compiled shaders.
The patch asks the target instead (CARGO_CFG_TARGET_OS, CARGO_CFG_DEBUG_ASSERTIONS) and lets
GPUI_FXC_PATH name any program that acts as fxc.exe (tools/fxc-wine.sh runs it under Wine).
Nothing else changes.
python3 -I tools/vendor-gpui-windows.py ~/.cargo/registry/src/*/gpui-pre-windows-0.3.10
"""
import shutil
import sys
from pathlib import Path
src = Path(sys.argv[1])
dst = Path(__file__).resolve().parent.parent / "vendor" / "gpui-pre-windows"
shutil.rmtree(dst, ignore_errors=True)
shutil.copytree(src, dst, ignore=shutil.ignore_patterns(".cargo-ok", ".cargo_vcs_info.json", "Cargo.toml.orig", "Cargo.lock"))
build = (dst / "build.rs").read_text()
def replace(old: str, new: str) -> None:
global build
if build.count(old) != 1:
sys.exit(f"build.rs has changed upstream; update the patch: {old[:60]!r}")
build = build.replace(old, new)
main_start = build.index("fn main() {")
main_end = build.index("\n}\n", main_start) + 3
build = (
build[:main_start]
+ '''// Patched for Proxy Suite (tools/vendor-gpui-windows.py): the shaders are compiled when the
// target is Windows in a release build, whatever machine builds it.
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=GPUI_FXC_PATH");
let windows = std::env::var("CARGO_CFG_TARGET_OS").is_ok_and(|os| os == "windows");
let release = std::env::var_os("CARGO_CFG_DEBUG_ASSERTIONS").is_none();
if windows && release {
shader_compilation::compile_shaders();
}
}
'''
+ build[main_end:]
)
replace('#[cfg(all(target_os = "windows", not(debug_assertions)))]\nmod shader_compilation {', "mod shader_compilation {")
replace(" pub fn find_latest_windows_sdk_binary(", " #[cfg(windows)]\n pub fn find_latest_windows_sdk_binary(")
replace(
""" // Try to find in PATH
// NOTE: This has to be `where.exe` on Windows, not `where`, it must be ended with `.exe`
if let Ok(output)""",
""" // Try to find in PATH
// NOTE: This has to be `where.exe` on Windows, not `where`, it must be ended with `.exe`
#[cfg(windows)]
if let Ok(output)""",
)
replace(
""" if let Ok(Some(path)) = find_latest_windows_sdk_binary("fxc.exe") {""",
""" #[cfg(windows)]
if let Ok(Some(path)) = find_latest_windows_sdk_binary("fxc.exe") {""",
)
replace(' panic!("Failed to find fxc.exe");', ' panic!("Failed to find fxc.exe (cross-compiling, set GPUI_FXC_PATH: tools/fxc-wine.sh)");')
replace('#[cfg(all(target_os = "windows", not(debug_assertions)))]\nuse shader_compilation::compile_shaders;\n', "")
(dst / "build.rs").write_text(build)
(dst / "PATCHED.md").write_text(
f"""# gpui-pre-windows, patched
`{src.name}` from crates.io (Apache-2.0, LICENSE-APACHE), unchanged except `build.rs`: the HLSL
shaders are compiled when the target (not the building machine) is Windows in a release build,
and GPUI_FXC_PATH may name any program acting as fxc.exe. Made by
`tools/vendor-gpui-windows.py`; the workspace uses it through `[patch.crates-io]`.
"""
)
print(f"vendored {src.name} into {dst}")