BlueGit

ict rusty-teams

Files

rusty-teams / packaging / kvt / fxc-wine.sh

fxc-wine.sh

fxc-wine.sh 1.5 KiB Download Raw
1#!/usr/bin/env bash
2# KVT fork: fxc.exe stand-in for a Linux CI container (no Windows, no WSL).
3# Runs Microsoft's own fxc.exe and d3dcompiler_47.dll from the Windows SDK NuGet
4# package under wine, so the shaders are byte-for-byte what a Windows build makes.
5# GPUI's build script calls it with: /T <target> /E <entry> /Fh <out.h> /Vn <name> /O3 <file.hlsl>
6# Needs FXC_DIR (fxc.exe + d3dcompiler_47.dll, see build-windows.sh) and wine64.
7set -euo pipefail
8: "${FXC_DIR:?FXC_DIR must point at the folder with fxc.exe}"
9wine="$(command -v wine64 || command -v wine || echo /usr/lib/wine/wine64)"
10export WINEPREFIX="${WINEPREFIX:-$HOME/.wine-fxc}" WINEDEBUG=-all WINEDLLOVERRIDES="d3dcompiler_47=n"
11winpath() { printf 'Z:%s' "$(realpath -m "$1" | tr / '\\')"; }
12args=()
13header=""
14while (($#)); do
15 case "$1" in
16 /T|/E|/Vn) args+=("$1" "$2"); shift 2 ;;
17 /Fh) header="$2"; args+=("$1" "$(winpath "$2")"); shift 2 ;;
18 /O[0-3d]|/Zi|/WX|/Gec|/Ges) args+=("$1"); shift ;;
19 *) args+=("$(winpath "$1")"); shift ;;
20 esac
21done
22[[ -n "$header" ]] && rm -f "$header"
23# fxc prints warnings and errors on stdout. wine's fxc can crash while exiting after
24# a good compile, so the exit code alone does not count: the header must be written.
25log="$(mktemp)"
26trap 'rm -f "$log"' EXIT
27status=0
28"$wine" "$FXC_DIR/fxc.exe" /nologo "${args[@]}" >"$log" 2>&1 || status=$?
29if [[ -n "$header" ]] && grep -q 'const BYTE' "$header" 2>/dev/null && grep -q 'compilation header save succeeded' "$log"; then
30 exit 0
31fi
32cat "$log" >&2
33echo "fxc-wine: fxc failed (exit $status)" >&2
34exit 1