BlueGit

ict rusty-teams

fix(build): retry every WSL interop call in the fxc wrapper, never fail silently

- Root cause of the random "Shader compilation failed" with empty stderr: WSL interop
  times out under load ("UtilAcceptVsock: accept4 failed 110"). The cmd.exe USERPROFILE
  call hid its error in /dev/null and set -e ended the script without a word.
- cmd.exe and powershell.exe calls go through one interop() helper: 3 attempts, then the
  last output on stderr.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-13 · 7 weeks ago

Hash
665c3d2a414eecf4c98d424632fce602a204658c
Parent
303afa55
1 file changed +16 −11
scripts/fxc-wsl.sh +16 −11
@@ -3,8 +3,21 @@
3 3 set -euo pipefail
4 4 shimDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5 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 }
6 19 # 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')"
20 windowsProfile="$(cd /mnt/c && interop /mnt/c/Windows/System32/cmd.exe /c "echo %USERPROFILE%" | tr -d '\r')"
8 21 stageDir="$(mktemp -d "$(wslpath "$windowsProfile")/AppData/Local/Temp/fxc-stage.XXXXXX")"
9 22 trap 'rm -rf "$stageDir"' EXIT
10 23 translatedArgs=(); headerOut=""
@@ -16,13 +29,5 @@ while (($#)); do
16 29 *) cp "$(dirname "$1")"/*.hlsl "$stageDir/"; translatedArgs+=("$(wslpath -w "$stageDir/$(basename "$1")")"); shift ;;
17 30 esac
18 31 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
32 interop "$powershellExe" -NoProfile -ExecutionPolicy Bypass -File "$(wslpath -w "$shimDir/fxc-shim.ps1")" "${translatedArgs[@]}" >/dev/null
33 cp "$stageDir/out.h" "$headerOut"
@@ -3,8 +3,21 @@
3set -euo pipefail
3set -euo pipefail
4shimDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4shimDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5powershellExe=/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
5powershellExe=/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
6# WSL interop calls time out under load ("UtilAcceptVsock: accept4 failed 110"): retry each one.
7interop() {
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}
6# UNC paths break D3DCompileFromFile includes: stage on the Windows drive.
19# UNC paths break D3DCompileFromFile includes: stage on the Windows drive.
7windowsProfile="$(cd /mnt/c && /mnt/c/Windows/System32/cmd.exe /c "echo %USERPROFILE%" 2>/dev/null | tr -d '\r')"
20windowsProfile="$(cd /mnt/c && interop /mnt/c/Windows/System32/cmd.exe /c "echo %USERPROFILE%" | tr -d '\r')"
8stageDir="$(mktemp -d "$(wslpath "$windowsProfile")/AppData/Local/Temp/fxc-stage.XXXXXX")"
21stageDir="$(mktemp -d "$(wslpath "$windowsProfile")/AppData/Local/Temp/fxc-stage.XXXXXX")"
9trap 'rm -rf "$stageDir"' EXIT
22trap 'rm -rf "$stageDir"' EXIT
10translatedArgs=(); headerOut=""
23translatedArgs=(); headerOut=""
@@ -16,13 +29,5 @@ while (($#)); do
16 *) cp "$(dirname "$1")"/*.hlsl "$stageDir/"; translatedArgs+=("$(wslpath -w "$stageDir/$(basename "$1")")"); shift ;;
29 *) cp "$(dirname "$1")"/*.hlsl "$stageDir/"; translatedArgs+=("$(wslpath -w "$stageDir/$(basename "$1")")"); shift ;;
17 esac
30 esac
18done
31done
19# PowerShell via WSL interop fails intermittently (empty stderr) during busy builds: retry.
32interop "$powershellExe" -NoProfile -ExecutionPolicy Bypass -File "$(wslpath -w "$shimDir/fxc-shim.ps1")" "${translatedArgs[@]}" >/dev/null
20for attempt in 1 2 3; do
33cp "$stageDir/out.h" "$headerOut"
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"
26done
27printf 'fxc failed after 3 attempts:\n%s\n' "$shimOutput" >&2
28exit 1