| 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. |
| 7 | set -euo pipefail |
| 8 | : "${FXC_DIR:?FXC_DIR must point at the folder with fxc.exe}" |
| 9 | wine="$(command -v wine64 || command -v wine || echo /usr/lib/wine/wine64)" |
| 10 | export WINEPREFIX="${WINEPREFIX:-$HOME/.wine-fxc}" WINEDEBUG=-all WINEDLLOVERRIDES="d3dcompiler_47=n" |
| 11 | winpath() { printf 'Z:%s' "$(realpath -m "$1" | tr / '\\')"; } |
| 12 | args=() |
| 13 | header="" |
| 14 | while (($#)); 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 |
| 21 | done |
| 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. |
| 25 | log="$(mktemp)" |
| 26 | trap 'rm -f "$log"' EXIT |
| 27 | status=0 |
| 28 | "$wine" "$FXC_DIR/fxc.exe" /nologo "${args[@]}" >"$log" 2>&1 || status=$? |
| 29 | if [[ -n "$header" ]] && grep -q 'const BYTE' "$header" 2>/dev/null && grep -q 'compilation header save succeeded' "$log"; then |
| 30 | exit 0 |
| 31 | fi |
| 32 | cat "$log" >&2 |
| 33 | echo "fxc-wine: fxc failed (exit $status)" >&2 |
| 34 | exit 1 |