| 1 | #!/usr/bin/env bash |
| 2 | # fxc.exe stand-in for WSL: translates paths, runs fxc-shim.ps1 on Windows. Point GPUI_FXC_PATH here. |
| 3 | set -euo pipefail |
| 4 | shimDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | powershellExe=/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe |
| 6 | # UNC paths break D3DCompileFromFile includes: stage on the Windows drive. |
| 7 | windowsProfile="$(cd /mnt/c && /mnt/c/Windows/System32/cmd.exe /c "echo %USERPROFILE%" 2>/dev/null | tr -d '\r')" |
| 8 | stageDir="$(mktemp -d "$(wslpath "$windowsProfile")/AppData/Local/Temp/fxc-stage.XXXXXX")" |
| 9 | trap 'rm -rf "$stageDir"' EXIT |
| 10 | translatedArgs=(); headerOut="" |
| 11 | while (($#)); do |
| 12 | case "$1" in |
| 13 | /T|/E|/Vn) translatedArgs+=("$1" "$2"); shift 2 ;; |
| 14 | /Fh) headerOut="$2"; translatedArgs+=("$1" "$(wslpath -w "$stageDir/out.h")"); shift 2 ;; |
| 15 | /O3) translatedArgs+=("$1"); shift ;; |
| 16 | *) cp "$(dirname "$1")"/*.hlsl "$stageDir/"; translatedArgs+=("$(wslpath -w "$stageDir/$(basename "$1")")"); shift ;; |
| 17 | esac |
| 18 | done |
| 19 | # PowerShell via WSL interop fails intermittently (empty stderr) during busy builds: retry. |
| 20 | for attempt in 1 2 3; do |
| 21 | if shimOutput="$("$powershellExe" -NoProfile -ExecutionPolicy Bypass -File "$(wslpath -w "$shimDir/fxc-shim.ps1")" "${translatedArgs[@]}" 2>&1)" && [[ -s "$stageDir/out.h" ]]; then |
| 22 | cp "$stageDir/out.h" "$headerOut" |
| 23 | exit 0 |
| 24 | fi |
| 25 | sleep "$attempt" |
| 26 | done |
| 27 | printf 'fxc failed after 3 attempts:\n%s\n' "$shimOutput" >&2 |
| 28 | exit 1 |