| 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 | # WSL interop calls time out under load ("UtilAcceptVsock: accept4 failed 110"): retry each one. |
| 7 | interop() { |
| 8 | local output attempt |
| 9 | for attempt in 1 2 3; do |
| 10 | if output="$("$@" 2>&1 | tr -d '\0')"; then |
| 11 | printf '%s' "$output" |
| 12 | return 0 |
| 13 | fi |
| 14 | sleep "$attempt" |
| 15 | done |
| 16 | printf 'fxc-wsl: %s failed 3 times:\n%s\n' "$1" "$output" >&2 |
| 17 | return 1 |
| 18 | } |
| 19 | # UNC paths break D3DCompileFromFile includes: stage on the Windows drive. |
| 20 | windowsProfile="$(cd /mnt/c && interop /mnt/c/Windows/System32/cmd.exe /c "echo %USERPROFILE%" | tr -d '\r')" |
| 21 | stageDir="$(mktemp -d "$(wslpath "$windowsProfile")/AppData/Local/Temp/fxc-stage.XXXXXX")" |
| 22 | trap 'rm -rf "$stageDir"' EXIT |
| 23 | translatedArgs=(); headerOut="" |
| 24 | while (($#)); do |
| 25 | case "$1" in |
| 26 | /T|/E|/Vn) translatedArgs+=("$1" "$2"); shift 2 ;; |
| 27 | /Fh) headerOut="$2"; translatedArgs+=("$1" "$(wslpath -w "$stageDir/out.h")"); shift 2 ;; |
| 28 | /O3) translatedArgs+=("$1"); shift ;; |
| 29 | *) cp "$(dirname "$1")"/*.hlsl "$stageDir/"; translatedArgs+=("$(wslpath -w "$stageDir/$(basename "$1")")"); shift ;; |
| 30 | esac |
| 31 | done |
| 32 | interop "$powershellExe" -NoProfile -ExecutionPolicy Bypass -File "$(wslpath -w "$shimDir/fxc-shim.ps1")" "${translatedArgs[@]}" >/dev/null |
| 33 | cp "$stageDir/out.h" "$headerOut" |