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>
@@ -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 @@3
set -euo pipefail3
set -euo pipefail4
shimDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"4
shimDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"5
powershellExe=/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe5
powershellExe=/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe6
# WSL interop calls time out under load ("UtilAcceptVsock: accept4 failed 110"): retry each one.7
interop() {8
local output attempt9
for attempt in 1 2 3; do10
if output="$("$@" 2>&1 | tr -d '\0')"; then11
printf '%s' "$output"12
return 013
fi14
sleep "$attempt"15
done16
printf 'fxc-wsl: %s failed 3 times:\n%s\n' "$1" "$output" >&217
return 118
}6
# UNC paths break D3DCompileFromFile includes: stage on the Windows drive.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
stageDir="$(mktemp -d "$(wslpath "$windowsProfile")/AppData/Local/Temp/fxc-stage.XXXXXX")"21
stageDir="$(mktemp -d "$(wslpath "$windowsProfile")/AppData/Local/Temp/fxc-stage.XXXXXX")"9
trap 'rm -rf "$stageDir"' EXIT22
trap 'rm -rf "$stageDir"' EXIT10
translatedArgs=(); headerOut=""23
translatedArgs=(); headerOut=""@@ -16,13 +29,5 @@ while (($#)); do16
*) 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
esac30
esac18
done31
done19
# PowerShell via WSL interop fails intermittently (empty stderr) during busy builds: retry.32
interop "$powershellExe" -NoProfile -ExecutionPolicy Bypass -File "$(wslpath -w "$shimDir/fxc-shim.ps1")" "${translatedArgs[@]}" >/dev/null20
for attempt in 1 2 3; do33
cp "$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" ]]; then22
cp "$stageDir/out.h" "$headerOut"23
exit 024
fi25
sleep "$attempt"26
done27
printf 'fxc failed after 3 attempts:\n%s\n' "$shimOutput" >&228
exit 1