#!/usr/bin/env bash # KVT fork: fxc.exe stand-in for a Linux CI container (no Windows, no WSL). # Runs Microsoft's own fxc.exe and d3dcompiler_47.dll from the Windows SDK NuGet # package under wine, so the shaders are byte-for-byte what a Windows build makes. # GPUI's build script calls it with: /T /E /Fh /Vn /O3 # Needs FXC_DIR (fxc.exe + d3dcompiler_47.dll, see build-windows.sh) and wine64. set -euo pipefail : "${FXC_DIR:?FXC_DIR must point at the folder with fxc.exe}" wine="$(command -v wine64 || command -v wine || echo /usr/lib/wine/wine64)" export WINEPREFIX="${WINEPREFIX:-$HOME/.wine-fxc}" WINEDEBUG=-all WINEDLLOVERRIDES="d3dcompiler_47=n" winpath() { printf 'Z:%s' "$(realpath -m "$1" | tr / '\\')"; } args=() header="" while (($#)); do case "$1" in /T|/E|/Vn) args+=("$1" "$2"); shift 2 ;; /Fh) header="$2"; args+=("$1" "$(winpath "$2")"); shift 2 ;; /O[0-3d]|/Zi|/WX|/Gec|/Ges) args+=("$1"); shift ;; *) args+=("$(winpath "$1")"); shift ;; esac done [[ -n "$header" ]] && rm -f "$header" # fxc prints warnings and errors on stdout. wine's fxc can crash while exiting after # a good compile, so the exit code alone does not count: the header must be written. log="$(mktemp)" trap 'rm -f "$log"' EXIT status=0 "$wine" "$FXC_DIR/fxc.exe" /nologo "${args[@]}" >"$log" 2>&1 || status=$? if [[ -n "$header" ]] && grep -q 'const BYTE' "$header" 2>/dev/null && grep -q 'compilation header save succeeded' "$log"; then exit 0 fi cat "$log" >&2 echo "fxc-wine: fxc failed (exit $status)" >&2 exit 1